Sub SlaveSender_Collection() '//////////////////参数采集通讯语句发送 If Not Mainboard.MSComm1.PortOpen Then Exit Sub End If Mainboard.Tcong.Interval = 10 Mainboard.Tcong.Enabled = True‘RTU模式前期静音 Do If Not Mainboard.Tcong.Enabled Then Exit Do End If DoEvents Loop Bover = False Dim Clear0() As Byte Mainboard.MSComm1.InputLen = 0 Clear0 = Mainboard.MSComm1.Input‘///清楚接收区 Mainboard.MSComm1.Output = sendSj_Collection Bover = False Bkong = False Mainboard.Tcong.Interval = 30 Mainboard.Tcong.Enabled = True‘后期延时 Mainboard.MSComm1.RThreshold = 8 Ninput = 8 Do If Not Mainboard.Tcong.Enabled Then Exit Do End If If Bover Then Exit Do End If DoEvents Loop Mainboard.Tcong.Enabled = False If Bover Then‘Bover为顺利接收数据标志 TFeedBackDataTranslation Num‘ 进一步处理通讯结果 End If ReDim arr(0 To 1) As Byte End Sub 在通讯中常有丢失现象,既查询10次,返回8、9次,请帮忙看看
Ask(1) = &H4
Ask(2) = &H1
Ask(3) = &H0
Ask(4) = &H41
Ask(5) = &H89
mscomm1.output=ask
If Not Mainboard.MSComm1.PortOpen Then
Exit Sub
End If
Mainboard.Tcong.Interval = 10
Mainboard.Tcong.Enabled = True‘RTU模式前期静音
Do
If Not Mainboard.Tcong.Enabled Then
Exit Do
End If
DoEvents
Loop
Bover = False
Dim Clear0() As Byte
Mainboard.MSComm1.InputLen = 0
Clear0 = Mainboard.MSComm1.Input‘///清楚接收区
Mainboard.MSComm1.Output = sendSj_Collection
Bover = False
Bkong = False
Mainboard.Tcong.Interval = 30
Mainboard.Tcong.Enabled = True‘后期延时
Mainboard.MSComm1.RThreshold = 8
Ninput = 8
Do
If Not Mainboard.Tcong.Enabled Then
Exit Do
End If
If Bover Then
Exit Do
End If DoEvents
Loop
Mainboard.Tcong.Enabled = False
If Bover Then‘Bover为顺利接收数据标志
TFeedBackDataTranslation Num‘ 进一步处理通讯结果
End If
ReDim arr(0 To 1) As Byte
End Sub
在通讯中常有丢失现象,既查询10次,返回8、9次,请帮忙看看
http://download.csdn.net/source/1262066