我有一个温度控制器,我可以通过 USB 与之通信,你有两种类型的命令,getter 和 setter。B2 等命令将获得当前风扇模式,预期响应为 0 或 1。命令 b2 将设置风扇模式,根据文档 b2 1 CR 应将风扇设置为模式 1,但我得到以下响应 0x11。根据文档,这意味着已收到命令,但终止字符是错误的。所有可能的终止字符都是(NULL、#、CR、LF)。
例子
风扇 1 模式
# getter
command: B2
response: 0x00
# setter
command: b2 1 CR
response: 0x11
传感器 1 温度限制
# getter
command: G1
response: 0xffffb1e00001869f
# setter
command:g1 -20 000 120 000 CR
response: 0x11
我正在使用 PyVISA,它是 VISA 库的前端。我查看了 pyvisa 的代码,看看它是否添加了任何内容或修改了我编写的命令,但找不到类似的东西。我已经尝试了所有终止字符(NULL、#、CR、LF)。难道 pyvisa 正在后台做一些改变命令的事情?或者这里发生了什么?
我制作了一个 python 脚本来测试命令。
import pyvisa
import threading
def listen(keithley):
while True:
if keithley.bytes_in_buffer >= 1:
out = ''
out = keithley.read_bytes(keithley.bytes_in_buffer).hex()
print(out + '\n')
if __name__ == '__main__':
rm = pyvisa.ResourceManager()
keithley = rm.open_resource("ASRL5::INSTR")
threading.Thread(target=listen, args=(keithley,)).start()
print('Enter your commands below.\r\nInsert "quit" to leave the application.')
print("Main : start receiver")
while True:
data = input(">> ")
if data == "quit":
keithley.before_close()
keithley.close()
quit()
else:
keithley.write(data)