python 3.x如何使用ctype struct发送和recv数据

时间:2017-09-15 10:19:27

标签: python struct ctype

import ctypes
import struct
class _sPOS(ctypes.Structure):
_fileds_ = (
    ("POSX", ctypes.c_double),
    ("POSY", ctypes.c_double)
)
sPOS = _sPOS()
class _sPOSE(ctypes.Structure):
_fileds_ = (
    ("sPOSX", sPOS),
    ("sPOSY", sPOS),
    ("sDirection", ctypes.c_double)
)
with open('/Users/machcross/Desktop/MasterDB_03M17D15H34m54s.dat','wb') as f:
sPOSE = _sPOSE()
sPOSE.sPOSX = 0.1
sPOSE.sPOSY = 0.2
sPOSE.sDirection = 0.01
size = ctypes.sizeof(sPOSE)
print(size)
  1. 如何获得sPOS的大小? len(sPOS)不起作用.. ctypes.sizeof(sPOS)为零..

  2. 我想知道使用bytearray(sPOS)的方法。 ex)buf =((char *)& _sPOS,sizeof(sPOS))

0 个答案:

没有答案