VB上位机接收多个不同的数据并在不同Text框中显示
发布网友
发布时间:2023-12-24 12:16
我来回答
共1个回答
热心网友
时间:2024-08-15 21:06
MSComm1.InputLen = 1
MSComm1.InBufferCount = 0 '清除发送缓冲区数据
MSComm1.OutBufferCount = 0 '清除接收缓冲区数据
MSComm1.InputMode = 1
MSComm1.SThreshold = 0
MSComm1.RThreshold = 10
SEL_COMDim btSend(10) As Byte
btSend(1) = &H1
btSend(2) = &H89
btSend(3) = &HFF
btSend(4) = &HA1
btSend(5) = &H5
btSend(6) = &H0
btSend(7) = &H0
btSend(8) = &H0
btSend(9) = &H30
btSend(10) = &H15
For I = 1 To 10
arr_rc(I) = btSend(I)
Next I
DoEvents
MSComm1.RTSEnable = True
yanshi
yanshi
yanshi
yanshi
yanshi
yanshi
yanshi
MSComm1.Output = arr_rc
du_shuju = True
yanshi
yanshi
yanshi
yanshi
yanshi
MSComm1.RTSEnable = False
Private Sub MSComm1_OnComm()
Dim I As Integer
MSComm1.InputLen = 0
If MSComm1.CommEvent = 2 Then
bytesTotal = MSComm1.InBufferCount
If bytesTotal = 29 Then
buf_rc = MSComm1.Input
For I = 0 To 28
arr_tx(I) = buf_rc(I)
Next I
Dim F1
F1 = arr_tx(8) & arr_tx(9)
If Val(F1) = "4821" Then Text25.Text = "通讯正常"
Command6_Click
Else
Text25.Text = "通讯超时"
End If