logo

请问uctypes.struct()如何得到字节数组

2020-02-19 21:22
8
bg1v

请问uctypes.struct()如何得到字节数组。我个人理解struct函数是存储数据的字典。但SDK中说明可通过此函数得到字节数组。

2020-02-21 14:10
I
网红小智智 星瞳科技

https://docs.singtown.com/micropython/zh/latest/openmvcam/library/ustruct.html

使用pack函数可以得到字节串。

例子:

import struct
struct.pack('hhl', 1, 2, 3)
b'\x00\x01\x00\x02\x00\x00\x00\x03'

完整的用法,中文pytnon文档:

https://docs.python.org/zh-cn/3/library/struct.html

https://cn.bing.com/search?q=struct+pack%E5%87%BD%E6%95%B0&qs=n&form=QBRE&sp=-1&pq=struct+packhan+sh&sc=0-17&sk=&cvid=6920009B8B2A465EABD669BCD329A9FD