vb编写的PC 与PC 通信程序

源代码在线查看: 串口数据传输.frm

软件大小: 3 K
上传用户: bing1728
关键词: 编写 通信程序
下载地址: 免注册下载 普通下载 VIP

相关代码

				VERSION 5.00
				Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
				Begin VB.Form Form1 
				   Caption         =   "串口数据传输"
				   ClientHeight    =   2670
				   ClientLeft      =   60
				   ClientTop       =   510
				   ClientWidth     =   6660
				   LinkTopic       =   "Form1"
				   ScaleHeight     =   2670
				   ScaleWidth      =   6660
				   StartUpPosition =   3  '窗口缺省
				   Begin MSCommLib.MSComm MSComm1 
				      Left            =   2760
				      Top             =   1800
				      _ExtentX        =   1005
				      _ExtentY        =   1005
				      _Version        =   393216
				      DTREnable       =   -1  'True
				   End
				   Begin VB.CommandButton Command2 
				      Caption         =   "关闭窗口"
				      Height          =   495
				      Left            =   4920
				      TabIndex        =   5
				      Top             =   1800
				      Width           =   1335
				   End
				   Begin VB.CommandButton Command1 
				      Caption         =   "发送"
				      Height          =   540
				      Left            =   4920
				      TabIndex        =   4
				      Top             =   240
				      Width           =   1335
				   End
				   Begin VB.TextBox Text2 
				      Height          =   495
				      Left            =   2280
				      TabIndex        =   3
				      Text            =   "Text2"
				      Top             =   1080
				      Width           =   3855
				   End
				   Begin VB.TextBox Text1 
				      Height          =   495
				      Left            =   2280
				      TabIndex        =   2
				      Text            =   "Text1"
				      Top             =   240
				      Width           =   2175
				   End
				   Begin VB.Label Label2 
				      Caption         =   "接收数据"
				      Height          =   255
				      Left            =   600
				      TabIndex        =   1
				      Top             =   1200
				      Width           =   975
				   End
				   Begin VB.Label Label1 
				      Caption         =   "发送数据"
				      Height          =   255
				      Left            =   600
				      TabIndex        =   0
				      Top             =   360
				      Width           =   1095
				   End
				End
				Attribute VB_Name = "Form1"
				Attribute VB_GlobalNameSpace = False
				Attribute VB_Creatable = False
				Attribute VB_PredeclaredId = True
				Attribute VB_Exposed = False
				Private Sub Command1_Click()
				Dim SendMeg As String     '定义发送数据变量
				SendMeg = Text1.Text     '变量赋值
				MSComm1.OutBufferCount = 0  '清空发送缓冲区
				MSComm1.Output = SendMeg     '发送数据
				
				End Sub
				
				Private Sub Command2_Click()
				MSComm1.PortOpen = 0    '关闭窗口
				Unload Form1       '卸载窗体
				End Sub
				
				Private Sub Form_Load()
				MSComm1.CommPort = 1          '使用1号串口
				MSComm1.Settings = "9600,N,8,1"    '设置初始化参数
				MSComm1.PortOpen = Ture     '打开串口
				
				End Sub
				
				Private Sub MSComm1_OnComm()
				Dim RecMsg As String                '定义接收数据变量
				Select Case MSComm1.CommEvent
				  Case comEvReceive              '有接收事件发生
				    RecMsg = MSComm1.Input      '接收数据
				    Text2.Text = RecMsg         '显示接收数据
				    MSComm1.InBufferCount = 0   '清空接收区
				End Select
				End Sub
				
							

相关资源