恭喜,你发布的帖子
发布于 2018-10-20 16:22:26
6楼
实际上数据在向上位机传送时都是以二进制传送的,不区分格式,但我们利用这些数据时就要根据实际的情况进行相应的解析,就比如你这个VD2吧,PC接收的实际是4个字节,你需要把4个字节重新解析为浮点数,LABVIEW没做过,我用VB.NET是专门做的结构体来解析的,你可以参考下:
'=================================================================================================================
'成员变量物理位置控制,类似于C的联合体,
<System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Explicit)>
Public Structure _TypeCvt
<System.Runtime.InteropServices.FieldOffset(0)>
Public i16 As Int16
<System.Runtime.InteropServices.FieldOffset(0)>
Public u16 As UInt16
<System.Runtime.InteropServices.FieldOffset(0)>
Public i32 As Int32
<System.Runtime.InteropServices.FieldOffset(0)>
Public u32 As UInt32
<System.Runtime.InteropServices.FieldOffset(0)>
Public ft As Single
<System.Runtime.InteropServices.FieldOffset(0)>
Public byt0 As Byte
<System.Runtime.InteropServices.FieldOffset(1)>
Public byt1 As Byte
<System.Runtime.InteropServices.FieldOffset(2)>
Public byt2 As Byte
<System.Runtime.InteropServices.FieldOffset(3)>
Public byt3 As Byte
End Structure
'=================================================================================================================
现在定义一个:Dim tc As _TypeCvt
tc.byt3=接收字节0
tc.byt2=接收字节1
tc.byt1=接收字节2
tc.byt0=接收字节3
这时如果我们想要按浮点解析接收来的数据直接引用 tc.ft字段值即可。
请填写推广理由:
分享
只看
楼主