我正在使用python-seabreeze与光谱仪交谈。一些但不是全部可用的命令都是在python-seabreeze中实现的。我可以从OceanOptics Flame-T手册中看到以下命令(例如):
.
.
0x09 Request Spectra
0x0A Set Trigger Mode
0x0B Query number of Plug-in Accessories Present
0x0C Query Plug-in Identifiers
0x0D Detect Plug-ins
0x12 LED Status
0x60 General I2C Read
0x61 General I2C Write
0x62 General SPI I/O
0x68 PSOC Read
0x69 PSOC Write
0x6A Write Register Information
0x6B Read Register Information
0x6C Read PCB Temperature
0x6D Read Irradiance Calibration
.
.
从seabreeze / pyseabreeze / protocol.py中,我可以看到这些命令的格式如下:
import functools
import struct
msgs = {
code: functools.partial(struct.Struct(msg).pack, code)
for code, msg in {
0x01: "<B", # OP_INITIALIZE
0x02: "<BI", # OP_ITIME
0x03: "<BH", # set Strobe/Lamp enable Line
0x05: "<BB", # OP_GETINFO
0x09: "<B", # OP_REQUESTSPEC
0x0A: "<BH", # OP_SETTRIGMODE
0x6A: "<BBH", # OP_WRITE_REGISTER
0x6B: "<BB", # OP_READ_REGISTER
0x71: "<BBB", # OP_TECENABLE_QE
0x72: "<B", # OP_READTEC_QE
0x73: "<Bh", # OP_TECSETTEMP_QE
0xFE: "<B", # OP_USBMODE
}.items()
} # add more here if you implement new features
例如,Request Spectra
根据手册0x09
,,是,当它来自python时,一条消息
struct.Struct('<B').pack(0x09)
已发送。我通过阅读有关struct格式字符串的方法来试图了解正在发生的事情,并且发现这<
意味着“ little endian”,B
意味着unsigned char,h
意味着short等。
应该怎么知道,从手动,该格式为OP_GETINFO
是<BB
,而OP_WRITE_REGISTER
这是<BBH
?这里的逻辑是什么?您会采用什么格式0x6C Read PCB Temperature
?为什么?
似乎您需要阅读要使用什么参数才能发送合法命令,该协议仅定义了您希望发送的某些项目,例如:
code_partial_function = functools.partial(struct.Struct(msg).pack, code)
...
0x6B: "<BB", # OP_READ_REGISTER
...
# used like this later:
# example for register number 1
# final_packed_bytes will contain both the operation id and the register number
final_packed_bytes = code_partial_function(0x1)
对于此操作读寄存器,protocol.py将创建一个已经包含操作ID(0x6b)的部分函数,并要求您提供附加的“ B”,表示另一个无符号字符,可能是您希望读取的寄存器号。
该协议仅将ID作为打包功能的第一个输入,而其余的值留给用户。每个操作在操作ID之后需要不同的值,有些需要更多(“ BBH”),有些需要更少(“ B”)。
对于0x6c,我将搜索格式并从中了解要给这个包函数留下什么。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句