📄 form1.frm
字号:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "mscomm32.ocx"
Begin VB.Form Form1
Caption = "串口调试程序"
ClientHeight = 4650
ClientLeft = 60
ClientTop = 450
ClientWidth = 5955
LinkTopic = "Form1"
ScaleHeight = 4650
ScaleWidth = 5955
StartUpPosition = 3 '窗口缺省
Begin VB.TextBox Text1
Height = 1455
Left = 240
TabIndex = 11
Top = 480
Width = 2895
End
Begin MSCommLib.MSComm MSComm1
Left = 1200
Top = 2160
_ExtentX = 1005
_ExtentY = 1005
_Version = 393216
DTREnable = -1 'True
End
Begin VB.VScrollBar VScroll2
Height = 1455
Left = 3120
TabIndex = 8
Top = 2880
Width = 255
End
Begin VB.VScrollBar VScroll1
Height = 1455
Left = 3120
TabIndex = 7
Top = 480
Width = 255
End
Begin VB.Frame Frame3
Caption = "显示方式"
Height = 975
Left = 3840
TabIndex = 6
Top = 3360
Width = 1815
Begin VB.OptionButton Option7
Caption = "十六进制"
Height = 255
Left = 240
TabIndex = 15
Top = 600
Width = 1455
End
Begin VB.OptionButton Option6
Caption = "字符模式"
Height = 255
Left = 240
TabIndex = 14
Top = 240
Width = 1575
End
End
Begin VB.Frame Frame2
Caption = "端口"
Height = 1095
Left = 3840
TabIndex = 5
Top = 840
Width = 1815
Begin VB.OptionButton Option3
Caption = "COM3"
Height = 255
Left = 240
TabIndex = 16
Top = 720
Width = 735
End
Begin VB.OptionButton Option2
Caption = "COM2"
Height = 255
Left = 240
TabIndex = 10
Top = 480
Width = 975
End
Begin VB.OptionButton Option1
Caption = "COM1"
Height = 255
Left = 240
TabIndex = 9
Top = 240
Width = 975
End
End
Begin VB.Frame Frame1
Caption = "波特率"
Height = 975
Left = 3840
TabIndex = 4
Top = 2160
Width = 1815
Begin VB.OptionButton Option5
Caption = "19200"
Height = 255
Left = 240
TabIndex = 13
Top = 600
Width = 975
End
Begin VB.OptionButton Option4
Caption = "9600"
Height = 255
Left = 240
TabIndex = 12
Top = 240
Width = 1215
End
End
Begin VB.CommandButton Command1
Caption = "发送"
Height = 495
Left = 3840
TabIndex = 3
Top = 240
Width = 1815
End
Begin VB.TextBox Text2
Height = 1455
Left = 240
TabIndex = 1
Top = 2880
Width = 2895
End
Begin VB.Label Label2
AutoSize = -1 'True
Caption = "接受数据:"
Height = 180
Left = 240
TabIndex = 2
Top = 2640
Width = 810
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "发送数据:"
Height = 180
Left = 240
TabIndex = 0
Top = 240
Width = 810
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Form_Load()
MSComm1.CommPort = 1
If Option4.Value = True Then
MSComm1.Settings = "9600 ,n ,8 ,1"
End If
If Option5.Value = True Then
MSComm1.Settings = "19200 ,n ,8 ,1"
End If
If Option6.Value = True Then
MSComm1.InputMode = comInputModeText
End If
If Option7.Value = True Then
MSComm1.InputMode = comInputModeBinary
End If
MSComm1.InputLen = 0
If MSComm1.PortOpen = False Then
MSComm1.PortOpen = True
End If
MSComm1.RThreshold = 1
End Sub
Private Sub Command1_Click()
Dim outstring As String
Dim n As Long
outstring = Text1.Text
n = Len(outstring)
Call send(outstring, n)
End Sub
Private Sub send(outstring As String, n As Long)
Dim instring As String '
MSComm1.InputLen = 0
If MSComm1.PortOpen = False Then
MSComm1.PortOpen = True
End If
MSComm1.RThreshold = n
MSComm1.Output = outstring + Chr(&HD)
End Sub
Private Sub MSComm1_OnComm()
Dim instring As String
Select Case MSComm1.CommEvent
Case comEvReceive
If MSComm1.InputMode = comInputModeText Then
instring = MSComm1.Input
Text2.Text = instring
End If
If MSComm1.InputMode = comInputModeBinary Then
Dim R() As Byte
Dim Buff As Variant
MSComm1.InputLen = MSComm1.InBufferCount
Buff = MSComm1.Input
R = Buff
For i = LBound(R) To UBound(R)
Text2.Text = Text2.Text + _
CStr(Hex(R(i))) + " "
Next
End If
End Select
End Sub
Private Sub Form_Unload(Cancel As Integer)
If MSComm1.PortOpen = True Then
MSComm1.PortOpen = False
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -