📄 form2.frm
字号:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Begin VB.Form Form2
Caption = "Form2"
ClientHeight = 4095
ClientLeft = 60
ClientTop = 450
ClientWidth = 8430
LinkTopic = "Form2"
ScaleHeight = 4095
ScaleWidth = 8430
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton guanbichuankou
Caption = "关闭串口"
Height = 375
Left = 5160
TabIndex = 18
Top = 2040
Width = 975
End
Begin VB.CommandButton dakaichuankou
Caption = "打开串口"
Height = 375
Left = 5160
TabIndex = 17
Top = 1320
Width = 975
End
Begin VB.ComboBox Combo5
Height = 300
Left = 7200
TabIndex = 16
Text = "位数"
Top = 3360
Width = 975
End
Begin VB.ComboBox Combo4
Height = 300
Left = 7200
TabIndex = 14
Text = "位数"
Top = 2760
Width = 975
End
Begin VB.ComboBox Combo3
Height = 300
Left = 7200
TabIndex = 13
Text = "校验"
Top = 2160
Width = 975
End
Begin VB.ComboBox Combo2
Height = 300
Left = 7200
TabIndex = 12
Text = "波特率"
Top = 1560
Width = 975
End
Begin VB.ComboBox Combo1
Height = 300
Left = 7200
TabIndex = 11
Text = "串口"
Top = 960
Width = 975
End
Begin VB.Timer Timer1
Left = 5040
Top = 3360
End
Begin MSCommLib.MSComm MSComm1
Left = 4320
Top = 3360
_ExtentX = 1005
_ExtentY = 1005
_Version = 393216
DTREnable = -1 'True
End
Begin VB.CommandButton Command2
Caption = "清空"
Height = 375
Left = 2640
TabIndex = 5
Top = 3120
Width = 1200
End
Begin VB.CommandButton Command1
Caption = "发送"
Height = 375
Left = 1080
TabIndex = 4
Top = 3120
Width = 1200
End
Begin VB.TextBox Text2
Height = 975
Left = 960
TabIndex = 1
Text = "Text2"
Top = 1800
Width = 3615
End
Begin VB.TextBox Text1
Height = 975
Left = 840
TabIndex = 0
Text = "Text1"
Top = 120
Width = 3735
End
Begin VB.Label Label8
Caption = "数据位"
Height = 180
Left = 6300
TabIndex = 15
Top = 2805
Width = 615
End
Begin VB.Label Label7
Caption = "停止位"
Height = 270
Left = 6300
TabIndex = 10
Top = 3405
Width = 615
End
Begin VB.Label Label6
Caption = "校验方式"
Height = 180
Left = 6300
TabIndex = 9
Top = 2205
Width = 735
End
Begin VB.Label Label5
Caption = "波特率"
Height = 180
Left = 6300
TabIndex = 8
Top = 1605
Width = 615
End
Begin VB.Label Label4
Caption = "串口"
Height = 180
Left = 6300
TabIndex = 7
Top = 1005
Width = 375
End
Begin VB.Label Label3
Caption = "配置你所需要设置的串口通讯方式"
Height = 375
Left = 6360
TabIndex = 6
Top = 360
Width = 1455
End
Begin VB.Label Label2
Caption = "发送数据"
Height = 375
Left = 240
TabIndex = 3
Top = 2160
Width = 375
End
Begin VB.Label Label1
BackColor = &H80000009&
Caption = "接收数据"
Height = 375
Left = 240
TabIndex = 2
Top = 360
Width = 375
End
End
Attribute VB_Name = "Form2"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Frame1_DragDrop(Source As Control, X As Single, Y As Single)
End Sub
Private Sub VScroll1_Change()
End Sub
Private Sub Command1_Click()
Dim f As String
Dim sendstr As String
f = Text2.Text
If f = "" Then
MsgBox "请输入要发送的数据"
Else
sendstr = "FF" & Len(f) & f & "FF"
MSComm1.Output = sendstr
End If
End Sub
Private Sub Command2_Click()
Text1.Text = ""
Text2.Text = ""
End Sub
Private Sub Command4_Click()
End Sub
Private Sub dakaichuankou_Click()
Dim a As String
Dim b As String
Dim c As String
Dim d As String
Dim aa As String
Dim e As Integer
Select Case Combo1.ListIndex = "1,2,3,4"
Case Combo1.ListIndex = "1"
e = 1
Case Combo1.ListIndex = "2"
e = 2
Case Combo1.ListIndex = "3"
e = 3
Case Combo1.ListIndex = "4"
e = 4
End Select
Select Case Combo2.ListIndex = "1,2,3,4"
Case Combo2.ListIndex = "1"
a = 4800
Case Combo2.ListIndex = "2"
a = 9600
Case Combo2.ListIndex = "3"
a = 19200
Case Combo2.ListIndex = "4"
a = 38400
End Select
Select Case Combo3.ListIndex = "1,2,3"
Case Combo3.ListIndex = "1"
b = "N"
Case Combo3.ListIndex = "2"
b = "o"
Case Combo3.ListIndex = "3"
b = "e"
End Select
Select Case Combo4.ListIndex = "1,2"
Case Combo4.ListIndex = "1"
c = 8
Case Combo4.ListIndex = "2"
c = 7
End Select
Select Case Combo5.ListIndex = "1,2"
Case Combo5.ListIndex = "1"
d = 1
Case Combo5.ListIndex = "2"
d = 2
End Select
If a = Null Then
MsgBox "请选择波特率"
If b = Null Then
MsgBox "请选择校验方式"
If c = Null Then
MsgBox "请选择数据传输的位数"
If d = Null Then
MsgBox "请选择停止位"
End If
End If
End If
End If
With MSComm1
.CommPort = e
.Settings = a & b & c & d
.InputMode = comInputModeText
End With
If Not MSComm1.PortOpen Then
MSComm1.PortOpen = True
End If
aa = False
dakaichuankou.Enabled = aa
guanbichuankou.Enabled = True
End Sub
Private Sub Form_Load()
Combo1.AddItem "com1"
Combo1.AddItem "com2"
Combo1.AddItem "com3"
Combo1.AddItem "com4"
Combo2.AddItem "4800"
Combo2.AddItem "9600"
Combo2.AddItem "19200"
Combo2.AddItem "38400"
Combo3.AddItem "无校验"
Combo3.AddItem "偶校验"
Combo3.AddItem "寄校验"
Combo4.AddItem "8"
Combo4.AddItem "7"
Combo5.AddItem "1"
Combo5.AddItem "2"
guanbichuankou.Enabled = False
End Sub
Private Sub guanbichuankou_Click()
MSComm1.PortOpen = False
If dakaichuankou.Enabled = False Then
dakaichuankou.Enabled = True
End If
guanbichuankou.Enabled = False
End Sub
Private Sub MSComm1_OnComm()
Dim rcv_array() As Byte
Dim dis_array As String
Dim rcv_len As Long
Dim yy As String
Dim haha As String
rcv_array = MSComm1.Input
rcv_len = UBound(rcv_array)
ReDim temP(0 To UBound(rcv_array))
For i = 0 To rcv_len
dis_array = dis_array & Hex(rcv_array(i)) & ""
Next i
If Len(dis_array) = 38 Then
yy = Mid(dis_array, 34, 1)
End If
If Len(dis_array) = 39 Then
yy = Mid(dis_array, 34, 2)
End If
If Len(dis_array) = 42 Then
yy = Mid(dis_array, 35, 4)
End If
If Len(dis_array) = 45 Then
yy = Mid(dis_array, 35, 5)
End If
Text1.Text = dis_array
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -