python的ctypes模块详解数组_ctypes模块-PYTHON

本文详细介绍了如何使用Python的ctypes模块解析struct数据类型,包括创建对应的结构体类stBPDynamicData,并展示了如何将结构体转换为字符串的方法。
摘要由CSDN通过智能技术生成

# 原始数据
# struct _stBPDynamicData {
# unsigned char encrypt;
# _StructTime gpsTime;
# unsigned int longitude;
# unsigned int latitude;
# unsigned short unGpsSpeed;
# unsigned short unTachographSpeed;
# unsigned int uiMileageTotal;
# unsigned short angle;
# unsigned short state;
# unsigned short alarm;
# };

# 对应的python数据, 一定要派生于ctypes.Structure
class _stBPDynamicData(Structure):
 _fields_ =[('encrypt',c_ubyte),
 ('gpsTime',_StructTime), 
 ('longitude',c_uint),
 ('latitude',c_uint),
 ('unGpsSpeed',c_ushort),
 ('unTachographSpeed',c_ushort),
 ('uiMileageTotal',c_uint),
 ('angle',c_ushort),
 ('state',c_ushort),
 ('alarm',c_ushort)];
 # 转换成字符串使用的函数
 def __str__(self):
 return u'({0},{1}),{6},sp:{2},angle:{3},st:{4},al:{5}'.format(self.longitude,
 self.latitude,self.unGpsSpeed,
 self.angle ,self.state,self.alarm,self.gpsTime );
 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值