📄 form1.frm
字号:
Left = 1440
Shape = 3 'Circle
Top = 225
Width = 360
End
Begin VB.Shape Shape2
BackColor = &H00C0C0C0&
BackStyle = 1 'Opaque
Height = 240
Index = 8
Left = 1440
Shape = 3 'Circle
Top = 3480
Width = 360
End
End
Begin VB.Frame Frame2
Caption = "波特率"
Height = 1442
Left = 10458
TabIndex = 8
Top = 882
Width = 1204
Begin VB.OptionButton Option2
Caption = "9600B/s"
Height = 255
Index = 0
Left = 126
TabIndex = 12
Top = 252
Width = 1215
End
Begin VB.OptionButton Option2
Caption = "2400 B/s"
Height = 255
Index = 1
Left = 126
TabIndex = 11
Top = 504
Width = 1215
End
Begin VB.OptionButton Option2
Caption = "1200 B/s"
Height = 255
Index = 2
Left = 120
TabIndex = 10
Top = 756
Width = 1215
End
Begin VB.OptionButton Option2
Caption = " 600 B/s"
Height = 255
Index = 3
Left = 120
TabIndex = 9
Top = 1008
Width = 1215
End
End
Begin VB.Frame Frame1
Caption = "串口"
Height = 1316
Left = 11844
TabIndex = 5
Top = 1008
Width = 1078
Begin VB.OptionButton Option1
Caption = "Com 1"
Height = 238
Index = 0
Left = 126
TabIndex = 7
Top = 252
Width = 854
End
Begin VB.OptionButton Option1
Caption = "Com 4"
Height = 255
Index = 1
Left = 126
TabIndex = 6
Top = 630
Width = 855
End
End
Begin VB.TextBox Text2
Height = 375
Left = 2618
TabIndex = 4
Text = "1"
Top = 196
Width = 2055
End
Begin VB.TextBox Text1
Height = 375
Left = 336
TabIndex = 3
Text = "Text1"
Top = 196
Width = 2055
End
Begin MSCommLib.MSComm MSComm1
Left = 11634
Top = 238
_ExtentX = 1006
_ExtentY = 1006
_Version = 393216
DTREnable = -1 'True
End
Begin VB.CommandButton Command3
Caption = "stop"
Height = 495
Left = 10458
TabIndex = 2
Top = 3402
Width = 1215
End
Begin VB.CommandButton Command2
Caption = "receive"
Height = 495
Left = 11844
TabIndex = 1
Top = 2520
Width = 1215
End
Begin VB.CommandButton Command1
Caption = "send"
Height = 495
Left = 10458
TabIndex = 0
Top = 2520
Width = 1215
End
Begin VB.Label Label2
Caption = "Label2"
BeginProperty DataFormat
Type = 1
Format = "H:mm:ss"
HaveTrueFalseNull= 0
FirstDayOfWeek = 0
FirstWeekOfYear = 0
LCID = 2052
SubFormatType = 4
EndProperty
BeginProperty Font
Name = "宋体"
Size = 14.97
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 378
Left = 10710
TabIndex = 21
Top = 252
Width = 1932
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim X, Y, Z As Integer
Dim Send() As Byte
Dim sendCOUNT As Integer
Private Sub Check1_click(Index As Integer)
Dim J As String
Dim i As Integer, temp As Byte
On Error GoTo Errhandle
Text1.Text = ""
J = ""
If Check1(Index).Value = 1 Then
Shape2(Index).BackColor = &HFF00&
J = J + "1"
Else
Shape2(Index).BackColor = H808080
J = J + "0"
End If
For i = 1 To 8
Text1.Text = Text1.Text + Trim(Str(Check1(i).Value))
Next i
''//////////////////////////////////////////////
Y = 0
For X = 1 To 8
Z = Mid(Text1.Text, X, 1)
If Z = 1 Then
Select Case X
Case 1
Y = Y + 1
Case 2
Y = Y + 2
Case 3
Y = Y + 4
Case 4
Y = Y + 8
Case 5
Y = Y + 16
Case 6
Y = Y + 32
Case 7
Y = Y + 64
Case 8
Y = Y + 128
End Select
End If
Next X
Text3.Text = Y ''十进制
If Len(Hex(Y)) < 2 Then
Text3.Text = "0" + Hex(Y)
Else
Text3.Text = Hex(Y)
End If
''''''''''''''''''''''''''''''''''''''''''''
For i = 9 To 16
Text1.Text = Text1.Text + Trim(Str(Check1(i).Value))
Next i
''//////////////////////////////////////////////
Y = 0
For X = 9 To 16
Z = Mid(Text1.Text, X, 1)
If Z = 1 Then
Select Case X
Case 9
Y = Y + 1
Case 10
Y = Y + 2
Case 11
Y = Y + 4
Case 12
Y = Y + 8
Case 13
Y = Y + 16
Case 14
Y = Y + 32
Case 15
Y = Y + 64
Case 16
Y = Y + 128
End Select
End If
Next X
Text4.Text = Y ''十进制
If Len(Hex(Y)) < 2 Then
Text4.Text = "0" + Hex(Y)
Else
Text4.Text = Hex(Y)
End If
buff = "0A" + Text3.Text + Text4.Text + "0D"
'///////////////////////////////// /
Text2.Text = buff
Dim X1 As Integer
X1 = 1
Dim Y1 As Integer
Y1 = Len(buff)
Dim Z1 As Integer
Z1 = 0
ReDim Send(Y1 / 2 - 1)
Do While X1 < Y1
Send(Z1) = Val("&H" + (Mid(buff, X1, 2)))
MSComm1.Settings = "9600,n,8,1"
MSComm1.PortOpen = True
MSComm1.Output = Send
MSComm1.PortOpen = False
Z1 = Z1 + 1
X1 = X1 + 2
Loop
Errhandle:
Exit Sub
End Sub
Private Sub Command1_Click() ' 发送文件按键
TimerSEND.Enabled = True
Dim X1 As Integer
Dim Y1 As Integer
Dim Z1 As Integer
sendCOUNT = 1
For sendCOUNT = 1 To Text5.Count
If Text5(sendCOUNT).Text <> "" Then
buff = "0A" + Text5(sendCOUNT).Text + Text4.Text + "0D"
End If
X1 = 1
Y1 = Len(buff)
Z1 = 0
ReDim Send(Y1 / 2 - 1)
Do While X1 < Y1
Send(Z1) = Val("&H" + (Mid(buff, X1, 2)))
MSComm1.Settings = "9600,n,8,1"
MSComm1.PortOpen = True
MSComm1.Output = Send
MSComm1.PortOpen = False
Z1 = Z1 + 1
X1 = X1 + 2
Loop
Next sendCOUNT
End Sub
Private Sub Command2_Click() ' 接收文件按键
MSComm1.PortOpen = True
Text2.Text = MSComm1.Input
MSComm1.PortOpen = False
End Sub
Private Sub Command3_Click() ' 结束按键
End
End Sub
Private Sub Command4_Click()
MSComm1.PortOpen = True
MSComm1.Output = Text1.Text
MSComm1.PortOpen = False
End Sub
Private Sub Form_Load() ' 读入窗口时的初始化
Dim adrCOUANT As Integer, a As Integer
For a = 1 To Text5.Count
Text5(a).Text = ""
Label1(a).Caption = a
Next a
Option1(0).Value = True
Option2(0).Value = True
TimerSEND.Enabled = False
End Sub
Private Sub Option1_Click(Index As Integer) ' 选择COM口
Select Case Index
Case 0
MSComm1.CommPort = 1
If MSComm1.PortOpen Then
MsgBox "对不起,COM1已被占用,请另外选择。"
End If
Case 1
MSComm1.CommPort = 4
If MSComm1.PortOpen Then
MsgBox "对不起,COM4已被占用,请另外选择。"
End If
End Select
End Sub
Private Sub Option2_Click(Index As Integer) ' 选择波比率
Select Case Index
Case 0
MSComm1.Settings = "9600,n,8,1"
Case 1
MSComm1.Settings = "2400,n,8,1"
Case 2
MSComm1.Settings = "1200,n,8,1"
Case 3
MSComm1.Settings = "600,n,8,1"
End Select
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -