网口通信的问题
我写了个上位机软件,用网口通信。我上位机发一个命令,下位机就往上位机传输数据。
可是传着传着,上位机的数据就不更新了。可是用网络助手测试,下位机还在发。
说明下位机程序没问题。我用
send按钮和后面的文本框往下位机发命令,可以控制小灯亮灭。
我不明白,为什么变形数据不更新。
请高手指教,谢谢。
附上网口中断函数。
Private Sub SckServer_DataArrival(ByVal bytesTotal As Long)
Dim MyStr As String
Dim a As Long
Dim Encoder(1511) As Single
Dim FileName As String
Dim Charnum As Long
Dim i As Long
'Dim b As Integer
'得到数据
SckServer.GetData MyStr
Charnum = Len(MyStr)
'
For i = 0 To (Charnum - 1)
If (Mid(MyStr, i + 1, 1) > "9") Then
Encoder(i) = 9
Else
Encoder(i) = Val(Mid(MyStr, i + 1, 1))
End If
Next
'
If (Encoder(0) = 1) Then '编码器当前值
If (Encoder(1) = 1) Then '+
CurrentValue = 0
For i = 2 To (Charnum - 1)
CurrentValue = CurrentValue + Encoder(i) * 10 ^ (Charnum - 1 - i)
Next
'ElseIf ((Encoder(1) = "0") And (Encoder(2) = "1")) Then
ElseIf (Encoder(1) = 0) Then
CurrentValue = 0
For i = 2 To (Charnum - 1)
CurrentValue = CurrentValue + Encoder(i) * 10 ^ (Charnum - 1 - i)
Next
End If
' j = j + 1
End If
If (Encoder(0) = 2) Then '画位移
DrawShift = Encoder(1) * 10 + Encoder(2)
End If
If (Encoder(0) = 3) Then '力
StrengthRec = Encoder(1) * 10000 + Encoder(2) * 1000 + Encoder(3) * 100 + Encoder(4) * 10 + Encoder(5)
End If
If ((Encoder(0) = 6) And (Encoder(1) = 6)) Then '连接包 55
linkflag = True
End If
End Sub
[此贴子已经被作者于2019-4-25 17:24编辑过]