vb6里,串口通讯,我设置读取仪表地址为5的数据,总是读取到仪表地址为6的地方,怎么弄?
我程序读取时总是读取到多一个地址的数据,是哪里的问题?怎么改?求代码!我觉得我通讯协议没有写错,放在1个仪表连接里对,这轮询起来就不对了……怎么弄?……PrivateSu...
我程序读取时总是读取到多一个地址的数据,是哪里的问题?怎么改?求代码!我觉得我通讯协议没有写错,放在1个仪表连接里对,这轮询起来就不对了……怎么弄?……
Private Sub MSComm1_OnComm()
Dim cmdin() As Byte '接收数据字节变量
If MSComm1.CommEvent = comEvReceive And MSComm1.InBufferCount = 10 Then
cmdin = MSComm1.Input
If I = 0 Then
Label1(0).Caption = TwoBytes(cmdin(0), cmdin(1))
Label1(1).Caption = TwoBytes(cmdin(2), cmdin(3))
ElseIf I = 1 Then
Label1(2).Caption = TwoBytes(cmdin(0), cmdin(1))
ElseIf I = 2 Then
Label1(3).Caption = TwoBytes(cmdin(0), cmdin(1))
ElseIf I = 3 Then
Label1(4).Caption = TwoBytes(cmdin(0), cmdin(1))
Text1(0).Text = TwoBytes(cmdin(2), cmdin(3))
ElseIf I = 4 Then
Label1(5).Caption = TwoBytes(cmdin(0), cmdin(1))
Text1(1).Text = TwoBytes(cmdin(2), cmdin(3))
End If
End If
T = True
End Sub
Private Sub Timer1_Timer()
Dim a(4) As Integer '地址在这里设
a(0) = 1
a(1) = 3
a(2) = 4
a(3) = 5
a(4) = 6
Call Read_Meter_Data(a(I))
I = (I + 1) Mod 5
T = False
End Sub 展开
Private Sub MSComm1_OnComm()
Dim cmdin() As Byte '接收数据字节变量
If MSComm1.CommEvent = comEvReceive And MSComm1.InBufferCount = 10 Then
cmdin = MSComm1.Input
If I = 0 Then
Label1(0).Caption = TwoBytes(cmdin(0), cmdin(1))
Label1(1).Caption = TwoBytes(cmdin(2), cmdin(3))
ElseIf I = 1 Then
Label1(2).Caption = TwoBytes(cmdin(0), cmdin(1))
ElseIf I = 2 Then
Label1(3).Caption = TwoBytes(cmdin(0), cmdin(1))
ElseIf I = 3 Then
Label1(4).Caption = TwoBytes(cmdin(0), cmdin(1))
Text1(0).Text = TwoBytes(cmdin(2), cmdin(3))
ElseIf I = 4 Then
Label1(5).Caption = TwoBytes(cmdin(0), cmdin(1))
Text1(1).Text = TwoBytes(cmdin(2), cmdin(3))
End If
End If
T = True
End Sub
Private Sub Timer1_Timer()
Dim a(4) As Integer '地址在这里设
a(0) = 1
a(1) = 3
a(2) = 4
a(3) = 5
a(4) = 6
Call Read_Meter_Data(a(I))
I = (I + 1) Mod 5
T = False
End Sub 展开
1个回答
2013-10-11
展开全部
推荐经典书籍
Visual_Basic与_RS-232_串行通信控制
Visual_Basic与_RS-232_串行通信控制
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询