我的标题可能看起来很奇怪,因为Python中没有uchar和ushort这样的东西,所以让我解释一下: 我从大容量传输中得到一个8位数据的列表,但我需要16位的数据。因此,我这样做:
frame = dev.read(0x82, packetLength, interface, timeout) # bulk transfer
if len(frame) == packetLength
for i in range(0, packetLength, 2):
newFrame.append(frame[i+1]*256 + frame[i])
所以是的,它是有效的,但它是非常缓慢的,我需要运行它在树莓皮。。。在
你们中有谁知道做同样事情更好的方法吗?在
使用
struct
,解决方案是:fmt
字符串说明:<
-数据采用little-endian格式%d
-数组的大小(它修改以下格式说明符)H
-格式说明符将数据解释为ushorts相关问题 更多 >
编程相关推荐