还是关于通讯的小问题
说明书上说.1帧数据由12 组数据组成,其中第1位表示 02(XON)开始,第12位表示03(X0FF) 结束.那个在传送的这个帧的数据中还包含这两位么? 如果包含的话,那数据是不是00 02 和00 03啊? 还是02和03啊?
[解决办法]
看了你给出的数据,实际是一串16进制数据,需通过VB的MID函数分割,具体每个数据取几字节须按说明书确定。再用Val( "&H " & "XXXX ")方法取10进值,然后进行分析。
其中小数位数不一定在内要根据数据确定。
数据需将其空格去除.
给出代码供参考:
Option Explicit
Dim sj As String
Dim sj1 As String
Dim sj2 As String
Dim l As Integer
Dim l1 As Integer
Dim i As Integer
Private Sub Command1_Click()
l = Len(sj)
Text4 = l
For i = 1 To l Step 3
sj1 = sj1 & Mid(sj, i, 2)
Next
Text2 = sj1
l1 = Len(sj1)
Text3 = l1
For i = 1 To l1 Step 4
sj2 = sj2 & Val( "&H " & Mid(sj1, i, 4)) & " "
Next
Text1 = sj2
End Sub
Private Sub Form_Load()
sj = "F8 80 78 1E 80 78 FE 00 78 FE F8 00 78 FE 80 78 FE 00 78 FE F8 78 1E 78 00 00 78 FE 00 80 00 80 00 80 00 80 80 F8 80 00 80 F8 78 FE F8 80 78 FE 00 80 78 00 F0 "
End Sub
对如下16进制数据串:F880781E8078FE0078FEF80078FE8078FE0078FEF8781E78000078FE008000800080008080F8800080F878FEF88078FE00807800F0
按4字节取其值有:
-1920 30750 -32648 -512 30974 -2048 30974 -32648 -512 30974 -1928 7800 0 30974 128 128 128 128 -32520 -32768 -32520 30974 -1920 30974 128 30720 240
按8字节取其值有
-125798370 -2139554304 2029975552 2029944952 -33523458 -126345608 30974 8388736 8388736 -2131197952 -2131199746 -125798146 8419328 240