串口通讯,在接收信息时,为什么总是接收不了,并且提示:超时间 呢?
'====================================================================================
'信息接收
'====================================================================================
'设定要接收的数据长度
intGetDataLen = 5
'超时时间计算:字节数×每个字节的传输时间×10 9600为波特率 请根据实际设定
sngTimeSpace = intGetDataLen * (11000# / 9600#) * 10#
sngTime = GetCurrentTime() '
Do While True '数据接收
DoEvents
If MSComm1.InBufferCount >= intGetDataLen Then Exit Do
'超时处理
If Abs(GetCurrentTime() - sngTime) > sngTimeSpace Then '超时
SendData = 1
Form2.Caption = GetCurrentTime 'sngTime sngTimeSpace
Exit Function
End If
Loop
为什么If MSComm1.InBufferCount >= intGetDataLen Then Exit Do这句总是执行不了。
而, If Abs(GetCurrentTime() - sngTime) > sngTimeSpace Then '超时
这句总是为真, Abs(GetCurrentTime() - sngTime) 值,随便就是几千,而sngTimeSpace值却为57
。。。。。。