我的一个电子称,通过串口和计算机相连,我用MsComm控件进行编程,电子称不断向串口发出18个字符一组的信号,信号格式为:
1:stx ascII字符 hex(02);
2:状态字a;
3:状态字b;
4:状态字c;
5:重量值高位;
.
.
10:重量值低位;
11:皮重值高位;
.
.
16:皮重值低位;
17:回车;
18:检查和;
现我用vb编制代码如下:
Dim cou As Long
Dim I_cou As Integer
Dim data As Variant
Me.Text1 = ""
Me.MSComToledoA.InputLen = 0
cou = MSComToledoA.InBufferCount
data = Me.MSComToledoA.Input
For I_cou = 1 To cou - 1
If data(I_cou) = &H2 Then
MsgBox "", vbOKOnly, SysName
End If
Me.Text1 = Me.Text1 + "." + Str(data(I_cou))
Next
收到如下数据:
. 180. 48. 160. 160. 160. 160. 178. 178. 48. 160. 160. 160. 48. 48. 48. 141. 9. 130.
这是电子称上的读数为2.20kg
现在的问题是如何将重量值从数据中转换读取出来,请各位大侠救命,今天老板要催命了...
1:stx ascII字符 hex(02);
2:状态字a;
3:状态字b;
4:状态字c;
5:重量值高位;
.
.
10:重量值低位;
11:皮重值高位;
.
.
16:皮重值低位;
17:回车;
18:检查和;
现我用vb编制代码如下:
Dim cou As Long
Dim I_cou As Integer
Dim data As Variant
Me.Text1 = ""
Me.MSComToledoA.InputLen = 0
cou = MSComToledoA.InBufferCount
data = Me.MSComToledoA.Input
For I_cou = 1 To cou - 1
If data(I_cou) = &H2 Then
MsgBox "", vbOKOnly, SysName
End If
Me.Text1 = Me.Text1 + "." + Str(data(I_cou))
Next
收到如下数据:
. 180. 48. 160. 160. 160. 160. 178. 178. 48. 160. 160. 160. 48. 48. 48. 141. 9. 130.
这是电子称上的读数为2.20kg
现在的问题是如何将重量值从数据中转换读取出来,请各位大侠救命,今天老板要催命了...
告诉我你的mail,我发给你!
Me.Text1 = Me.Text1 + "." + data(I_cou)
然后把数据发出来
Me.Text1 = Me.Text1 + "." + chr(data(I_cou))
把数据在贴出来!
Me.Text1 = Me.Text1 + "." + chr(data(I_cou))后变为:
00000 00000 00000 00000