📄 form1.frm
字号:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 4695
ClientLeft = 60
ClientTop = 450
ClientWidth = 7245
LinkTopic = "Form1"
ScaleHeight = 4695
ScaleWidth = 7245
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command2
Caption = "关闭"
Height = 615
Left = 6000
TabIndex = 3
Top = 4080
Width = 1215
End
Begin VB.TextBox Text2
Enabled = 0 'False
Height = 495
Left = 2400
TabIndex = 2
Top = 2760
Width = 3135
End
Begin VB.TextBox Text1
Height = 495
Left = 2400
TabIndex = 1
Top = 1680
Width = 3015
End
Begin VB.CommandButton Command1
Caption = "发送"
Height = 495
Left = 5640
TabIndex = 0
Top = 1680
Width = 975
End
Begin MSCommLib.MSComm MSComm1
Left = 6600
Top = 120
_ExtentX = 1005
_ExtentY = 1005
_Version = 393216
DTREnable = -1 'True
End
Begin VB.Label Label5
Caption = "通讯串口1"
Height = 495
Left = 600
TabIndex = 8
Top = 840
Width = 4695
End
Begin VB.Label Label4
Caption = $"Form1.frx":0000
Height = 615
Left = 120
TabIndex = 7
Top = 4080
Width = 5655
End
Begin VB.Label Label3
Caption = "发送的数据为16进制,范围在0-FF之间 通讯波特率19200"
Height = 495
Left = 600
TabIndex = 6
Top = 480
Width = 5175
End
Begin VB.Label Label2
Caption = "接收单片机发来的数据:"
Height = 375
Left = 120
TabIndex = 5
Top = 2760
Width = 2175
End
Begin VB.Label Label1
Caption = "待发送的数据:(16进制)"
Height = 255
Left = 0
TabIndex = 4
Top = 1680
Width = 2535
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 b(0) As Byte
b(0) = "&H" & Text1.Text
MSComm1.OutBufferCount = 0
MSComm1.Output = b
Text2.Text = ""
End Sub
Private Sub Command2_Click()
MSComm1.PortOpen = False
Unload Me
End Sub
Private Sub Form_Load()
MSComm1.CommPort = 1
MSComm1.InBufferSize = 4000
MSComm1.InBufferCount = 0
MSComm1.InputMode = 1
MSComm1.Settings = "19200,n,8,1"
MSComm1.RThreshold = 1
MSComm1.InputLen = 6
If MSComm1.PortOpen = False Then
MSComm1.PortOpen = True '
End If
End Sub
Private Sub MSComm1_OnComm()
Dim str As String
Dim count As Integer
Dim i As Integer
Select Case MSComm1.CommEvent
Case comEvReceive
inbyte = MSComm1.Input
For i = LBound(inbyte) To UBound(inbyte)
str = str + Hex(inbyte(i)) + Chr(32) ';将接受到的数据转换成十六进制,以字符串的形式显示
Next i
Text2.Text = str
End Select
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -