我有一个在com端口上发送数据的临床设备,我想从设备接收数据 在ENQ上发送ACK后,它还收到第一帧(254)字符 它会收到 [ETB] [CR] [LF] 字符 然后我再次发送下一帧的ACK,但不接收数据 只收到EOT char
按设备进行设备通信:
< - [ENQ]
- > [ACK]
< - [STX] 1H |的 * ** * ** * ** * ** * ** * ** * ** * - [ETB] 21 [CR] [LF]
- > [ACK]
< - [STX] 1H |的 * ** * ** * ** * ** * ** * ** * ** * - [ETX] 8E [CR] [LF]
- > [ACK]
< - [EOT]
我的代码是:
'MSComm1.Settings = "9600,n,8,1"
'MSComm1.InputLen = 1
Private Sub MSComm1_OnComm()
Dim InBuff As String
InBuff = MSComm1.Input
if Chr$(5)=InBuff then 'ENQ received
MSComm1.Output=Chr$(6) & VbCr
elseif Chr$(10)=InBuff then 'LF received
MSComm1.Output=Chr$(6) & VbCr
else
text1.text=text1.text & InBuff
end if
End Sub
设备发送完整数据,因为1个软件附带了接收完整数据的设备 但是再次发送ACK后我没有收到下一帧, 如果有人知道输出必须发送给下一个ACK,请建议我
提前致谢
答案 0 :(得分:0)
做这样的事......
MSComm1.InputLen = 1 ' for sending single character from device
MSComm1.RThreshold = 1 ' for firing events on receiving a single character
Dim InBuff As String
if MSComm1.CommEvent = comEvReceive then
do
InBuff = MSComm1.Input
Loop Until MSComm1.InBufferCount < 1
首先接收所有数据,然后以自己的方式使用它。