📄 form6.frm
字号:
VERSION 5.00
Begin VB.Form Form6
BorderStyle = 3 'Fixed Dialog
Caption = "四通道的数显表"
ClientHeight = 6465
ClientLeft = 45
ClientTop = 330
ClientWidth = 6180
LinkTopic = "Form6"
MaxButton = 0 'False
MDIChild = -1 'True
MinButton = 0 'False
ScaleHeight = 6465
ScaleWidth = 6180
ShowInTaskbar = 0 'False
Begin VB.TextBox Text9
Alignment = 1 'Right Justify
Height = 270
Left = 2880
MaxLength = 8
TabIndex = 13
Top = 3720
Width = 855
End
Begin VB.TextBox Text8
Alignment = 1 'Right Justify
Height = 270
Left = 1800
MaxLength = 8
TabIndex = 12
Top = 3720
Width = 855
End
Begin VB.TextBox Text7
Alignment = 1 'Right Justify
Height = 270
Left = 2880
MaxLength = 8
TabIndex = 11
Top = 3360
Width = 855
End
Begin VB.CommandButton Command3
Caption = "发送"
Height = 375
Left = 4200
TabIndex = 20
Top = 3480
Width = 855
End
Begin VB.TextBox Text5
Alignment = 1 'Right Justify
Height = 270
Left = 1800
MaxLength = 8
TabIndex = 10
Top = 3360
Width = 855
End
Begin VB.CommandButton Command1
Caption = "返回"
Height = 375
Left = 3960
TabIndex = 9
Top = 5520
Width = 1215
End
Begin VB.CommandButton Command12
Caption = "修改地址"
Height = 375
Left = 4080
TabIndex = 8
Top = 2520
Width = 975
End
Begin VB.TextBox Text6
Height = 270
Left = 3120
MaxLength = 4
TabIndex = 7
Top = 2640
Width = 615
End
Begin VB.TextBox Text2
Height = 270
Left = 1320
MaxLength = 4
TabIndex = 6
Top = 2640
Width = 615
End
Begin VB.CommandButton Command11
Caption = "广播命令"
Height = 375
Left = 4200
TabIndex = 5
Top = 360
Width = 975
End
Begin VB.CommandButton Command2
Caption = "初始化"
Height = 375
Left = 3120
TabIndex = 4
Top = 360
Width = 855
End
Begin VB.TextBox Text4
Height = 270
Left = 1680
MaxLength = 4
TabIndex = 1
Top = 480
Width = 615
End
Begin VB.CommandButton Command5
Caption = "发送"
Default = -1 'True
Height = 375
Left = 4320
TabIndex = 3
Top = 1440
Width = 855
End
Begin VB.TextBox Text1
Height = 270
Index = 0
Left = 1680
MaxLength = 40
TabIndex = 2
Top = 1560
Width = 2535
End
Begin VB.TextBox Text3
Height = 1095
Left = 840
MaxLength = 75
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 0
Top = 4920
Width = 2415
End
Begin VB.Label Label9
Caption = "4"
ForeColor = &H00000000&
Height = 375
Left = 2760
TabIndex = 23
Top = 3720
Width = 255
End
Begin VB.Label Label7
Caption = "3"
ForeColor = &H00000000&
Height = 375
Left = 1560
TabIndex = 22
Top = 3720
Width = 255
End
Begin VB.Label Label5
Caption = "2"
ForeColor = &H00000000&
Height = 375
Left = 2760
TabIndex = 21
Top = 3360
Width = 255
End
Begin VB.Label Label4
BackColor = &H80000013&
Caption = "1"
ForeColor = &H00000000&
Height = 375
Left = 1560
TabIndex = 19
Top = 3360
Width = 255
End
Begin VB.Label Label3
Caption = "遥测数据:"
Height = 375
Left = 480
TabIndex = 18
Top = 3480
Width = 1095
End
Begin VB.Label Label6
Caption = "新地址:"
Height = 255
Left = 2280
TabIndex = 17
Top = 2640
Width = 975
End
Begin VB.Label Label2
Caption = "原地址:"
Height = 255
Left = 480
TabIndex = 16
Top = 2640
Width = 855
End
Begin VB.Label Label8
Caption = "地址:"
Height = 255
Left = 600
TabIndex = 15
Top = 480
Width = 615
End
Begin VB.Label Label1
Caption = "发送数据:"
Height = 255
Index = 1
Left = 480
TabIndex = 14
Top = 1560
Width = 1095
End
End
Attribute VB_Name = "Form6"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Public inttime As Integer '发送时间间隔
Public strset As String
Dim myarray(12) As String
Public intport As Integer '串行口号
Private Sub Command1_Click()
Form6.Visible = False
End Sub
Private Sub Command11_Click()
If Not Form1.MSComm1.PortOpen Then
MsgBox ("请先选择串口后,再执行此操作")
Else
Form1.MSComm1.Output = "UUf13333c" ' 向串口发送广播命令
End If
End Sub
Private Sub Command12_Click()
If Len(Trim(Text2.Text)) < 4 Then
m1 = 4 - Len(Trim(Text2.Text))
Dim d As Integer, sss As String
For d = 1 To m1
sss = sss + "0"
Next
Text2.Text = sss + Trim(Text2.Text)
End If
If Len(Trim(Text6.Text)) < 4 Then
m1 = 4 - Len(Trim(Text6.Text))
sss = ""
For d = 1 To m1
sss = sss + "0"
Next
Text6.Text = sss + Trim(Text6.Text)
End If
Dim n1 As Integer, n2 As Integer
Dim i As Integer, s As String
Dim myarray() As String
'将旧地址和新地址都读取到myarray()数组中,并且将每位数据的ASC码值累加到n2中
ReDim myarray(8)
For i = 1 To 4
myarray(i) = Mid(Trim(Text2.Text), i, 1)
n2 = n2 + Asc(myarray(i))
Next
For i = 5 To 8
myarray(i) = Mid(Trim(Text6.Text), i - 4, 1)
n2 = n2 + Asc(myarray(i))
Next
'累加两个%的ASC码值并取其低位字节
n2 = n2 + Asc("%")
n2 = n2 + Asc("%")
s = Right(Hex(n2), 2)
'发送
If Not Form1.MSComm1.PortOpen Then
MsgBox ("请先选择串口后,再执行此操作")
Else
Form1.MSComm1.Output = "UU%" + Text2.Text + Text6.Text + "%" + s
End If
Text4.Text = Text6.Text
End Sub
Private Sub Command2_Click()
Dim m As Integer, m1 As Integer
If Not Form1.MSComm1.PortOpen Then
MsgBox ("请先选择串口后,再执行此操作") '判断串口的打开状态
Else
If Len(Trim(Text4.Text)) < 4 Then
m1 = 4 - Len(Trim(Text4.Text))
Dim d As Integer, sss As String
For d = 1 To m1
sss = sss + "0"
Next
Text4.Text = sss + Trim(Text4.Text)
End If
s = "UU%" + Text4.Text + "0000$"
Dim i As Integer, n As Integer
For i = 3 To 12
myarray(i) = Mid(s, i, 1)
n = n + Asc(myarray(i))
Next
s1 = Right(Hex(n), 2)
Form1.MSComm1.Output = s + s1
End If
Text3.Text = s + s1 + Chr$(13) + Chr$(10) + Text3.Text
End Sub
Private Sub Command3_Click()
If Text4.Text = "" Then
MsgBox ("请输入芯片的地址")
Else
If Len(Trim(Text4.Text)) < 4 Then
m1 = 4 - Len(Trim(Text4.Text))
Dim d As Integer, sss As String
For d = 1 To m1
sss = sss + "0"
Next
Text4.Text = sss + Trim(Text4.Text)
End If
Dim i As Integer, j As Integer, n As Integer, c As Integer, m As Integer, l As Integer
Dim s As String, s1 As String
n = n + Asc("#")
For c = 1 To 4
n = n + Asc(Mid(Trim(Text4.Text), c, 1))
Next
'变量S分别接受每个通道的数值以后,变量S1再将这四个通道的数据连在一起
m = 5
For i = 1 To Len(Trim(Text5.Text))
If Mid(Text5.Text, i, 1) = "." Then
j = Len(Trim(Text5.Text)) - i
m = 6
Else
s = s + Mid(Text5.Text, i, 1)
End If
Next
l = m - Len(Trim(Text5.Text))
For i = 1 To l
s = " " + s
Next
s = s & j
s1 = s1 + s
s = ""
m = 5
For i = 1 To Len(Trim(Text7.Text))
If Mid(Text7.Text, i, 1) = "." Then
j = Len(Trim(Text7.Text)) - i
m = 6
Else
s = s + Mid(Text7.Text, i, 1)
End If
Next
l = m - Len(Trim(Text7.Text))
For i = 1 To l
s = " " + s
Next
s = s & j
s1 = s1 + s
s = ""
m = 5
For i = 1 To Len(Trim(Text8.Text))
If Mid(Text8.Text, i, 1) = "." Then
j = Len(Trim(Text8.Text)) - i
m = 6
Else
s = s + Mid(Text8.Text, i, 1)
End If
Next
l = m - Len(Trim(Text8.Text))
For i = 1 To l
s = " " + s
Next
s = s & j
s1 = s1 + s
s = ""
m = 5
For i = 1 To Len(Trim(Text9.Text))
If Mid(Text9.Text, i, 1) = "." Then
j = Len(Trim(Text9.Text)) - i
m = 6
Else
s = s + Mid(Text9.Text, i, 1)
End If
Next
l = m - Len(Trim(Text9.Text))
For i = 1 To l
s = " " + s
Next
s = s & j
s1 = s1 + s
s = ""
For i = 1 To 24
n = n + Asc(Mid(s1, i, 1))
Next
Form1.MSComm1.Output = "UU#" + Text4.Text + s1 + Right(Hex(n), 2)
End If
Text3.Text = "UU#" + Text4.Text + s1 + Right(Hex(n), 2) + Chr$(13) + Chr$(10) + Text3.Text
End Sub
Private Sub Command5_Click()
Dim n1 As Integer, n2 As Integer
Dim i As Integer, s As String
Dim myarray() As String
n1 = Len(Trim(Text1(0).Text)) '所发送的命令
ReDim myarray(n1)
For i = 3 To n1
myarray(i) = Mid(Trim(Text1(0).Text), i, 1) '从第三位开始取数据
n2 = n2 + Asc(myarray(i)) '累加ASC值
Next
s = Right(Hex(n2), 2) '取低字节
If Not Form1.MSComm1.PortOpen Then
MsgBox ("请先选择串口后,再执行此操作")
Else
Form1.MSComm1.Output = Text1(0).Text + s '向串口发送数据
End If
Text3.Text = Text1(0).Text + s + Chr$(13) + Chr$(10) + Text3.Text
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -