import struct
from ctypes import * class MyStruct(Structure):
_fields_ = [
("v1", c_char), # c_byte
("v2", c_char), # c_byte
("v1_dire", c_char), # c_byte
("v2_dire", c_char) # c_byte
] mys = MyStruct()
mys.v1 = 20
print(type(mys.v1))
mys.v2 = 30
mys.v1_dire = 0
mys.v2_dire = 0
msg = struct.pack('cccc', mys.v1, mys.v2, mys.v1_dire, mys.v2_dire) # BBBB
print(msg)
ss = struct.unpack('cccc', msg) # BBBB
05-20 16:59