sp; ''判断是否为数据的开始标志
.RThreshold = 0 ''关闭OnComm事件接收
End If
Do
DoEvents
Loop Until .InBufferCount >= 3 ''循环等待接收缓冲区>=3个字节
'' nRece = nRece + 1
For i = 2 To 12
SwichVar i
Text1.Text = Text1.Text & Chr(Out(i))
Next
Text1.Text = LTrim(Text1.Text)
Text2.Text = Text2.Text & CStr(nRece)
.RThreshold = 1 ''打开MSComm事件接收
Case Else
'' .PortOpen = False
End Select
End With
End Sub
****************************************************************************
Private Sub DelayTime()
Dim bDT As Boolean
Dim sPrevious As Single, sLast As Single
bDT = True
sPrevious = Timer (Timer可以计算从子夜到现在所经过的秒数,在Microsoft Windows中,Timer函数可以返回一秒的小数部分)
Do While bDT
If Timer - sPrevious >= 0.3 Then bDT = False
Loop
bDT = True
End Sub
(通信传输速率为9600bps,则最快速度1.04ms发送一个字节,仪表每秒发送50帧数据,每帧数据有4个字节,即每秒发送200个字节,平均5.0ms 发送一个字节,连续读取串口数据时要在程序中添加循环等待
程序)
Private Sub SwichVar(ByVal nNum As Integer)
DelayTime
var = Null
var = MSC.Input
Out(