恭喜,你发布的帖子
发布于 2018-11-02 15:51:05
2楼
我做的数据结构,请参照:
'成员变量物理位置控制,类似于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字段值即可。
请填写推广理由:
分享
只看
楼主