📄 form1.frm
字号:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 4980
ClientLeft = 60
ClientTop = 345
ClientWidth = 6975
LinkTopic = "Form1"
ScaleHeight = 4980
ScaleWidth = 6975
StartUpPosition = 3 '窗口缺省
Begin VB.TextBox Text2
Height = 615
Left = 960
TabIndex = 3
Text = "Text2"
Top = 3240
Width = 1815
End
Begin VB.TextBox Text1
Height = 615
Left = 1080
TabIndex = 2
Text = "Text1"
Top = 2280
Width = 1815
End
Begin VB.CommandButton Command2
Caption = "Command2"
Height = 375
Left = 4680
TabIndex = 1
Top = 3480
Width = 1455
End
Begin VB.CommandButton Command1
Caption = "Command1"
Height = 495
Left = 4560
TabIndex = 0
Top = 2520
Width = 1575
End
Begin MSCommLib.MSComm MSComm1
Left = 1440
Top = 720
_ExtentX = 1005
_ExtentY = 1005
_Version = 393216
DTREnable = -1 'True
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Mscomm1_Oncomm()
'...通讯事件发生
Dim indata As Variant
Dim bte(0) As Byte
Select Case MSComm1.CommEvent
Case comEvReceive '...有接受事件发生
indata = MSComm1.Input
'...注意!要通过MSComm控件发送或接收二进制数据必须用Variant类型的变量对二进
'...制Byte类型的变量进行转换!
bte(0) = AscB(indata)
Text2.Text = bte(0)
MSComm1.InBufferCount = 0 '...清空输入寄存器
End Select
End Sub
Private Sub Command1_Click()
'...发送数据
Dim Num As Integer
Dim outbte(0) As Byte
Num = Val(Text1.Text)
outbte(0) = VBA.CByte(Num)
MSComm1.OutBufferCount = 0 '...清空输出寄存器
MSComm1.Output = outbte(0) '...发送数据
End Sub
Private Sub Command2_Click()
'...退出
Unload Me
End Sub
Private Sub Form_Load()
'...初始化
MSComm1.CommPort = 1 '...使用Com1口
MSComm1.Settings = "9600,n,8,1" '...设置通讯参数
MSComm1.PortOpen = True '...打开串口
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -