J
jiachenghuang
Unregistered / Unconfirmed
GUEST, unregistred user!
Private Sub Cmd_send_Click()
Dim temp(8) As Byte
Dim temp0$, temp1$, temp2$
Dim price, Digital As Integer
'发前四个字节
temp(0) = &HAA '指令头
temp(1) = &HF1 '设备地址
temp(2) = Val(Left(Txt_model.Text, 1)) '数据
temp(3) = Val(Mid(Txt_model.Text, 2, 1))
temp(4) = Val(Mid(Txt_model.Text, 3, 1))
temp(5) = Val(Mid(Txt_model.Text, 4, 1))
temp(6) = temp(2) + temp(3) + temp(4) + temp(5) '校验和
temp(7) = &HAB '指令尾
MSComm1.Output = temp
'发后四个字节
temp(0) = &HAA
temp(1) = &HF1
temp(2) = Val(Mid(Txt_model.Text, 5, 1))
temp(3) = Val(Mid(Txt_model.Text, 6, 1))
temp(4) = Val(Mid(Txt_model.Text, 7, 1))
temp(5) = Val(Mid(Txt_model.Text, 8, 1))
temp(6) = temp(2) + temp(3) + temp(4) + temp(5)
temp(7) = &HAB
MSComm1.Output = temp
End Sub
Dim temp(8) As Byte
Dim temp0$, temp1$, temp2$
Dim price, Digital As Integer
'发前四个字节
temp(0) = &HAA '指令头
temp(1) = &HF1 '设备地址
temp(2) = Val(Left(Txt_model.Text, 1)) '数据
temp(3) = Val(Mid(Txt_model.Text, 2, 1))
temp(4) = Val(Mid(Txt_model.Text, 3, 1))
temp(5) = Val(Mid(Txt_model.Text, 4, 1))
temp(6) = temp(2) + temp(3) + temp(4) + temp(5) '校验和
temp(7) = &HAB '指令尾
MSComm1.Output = temp
'发后四个字节
temp(0) = &HAA
temp(1) = &HF1
temp(2) = Val(Mid(Txt_model.Text, 5, 1))
temp(3) = Val(Mid(Txt_model.Text, 6, 1))
temp(4) = Val(Mid(Txt_model.Text, 7, 1))
temp(5) = Val(Mid(Txt_model.Text, 8, 1))
temp(6) = temp(2) + temp(3) + temp(4) + temp(5)
temp(7) = &HAB
MSComm1.Output = temp
End Sub