Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Pyserial,设备无响应_Python_Pyserial - Fatal编程技术网

Python Pyserial,设备无响应

Python Pyserial,设备无响应,python,pyserial,Python,Pyserial,我正在尝试与一个使用Python3.5在Win7上使用pyserial的设备通信。我能够连接到正确的端口“COM4”,但忽略所有其他通信。我所做的是: from serial import * s = Serial('COM4', stopbits=2) # All other settings are default 到目前为止没有错误。但我收到了一个错误,错误如下: >> s.write('REM') # Should put the device in 'Remote'

我正在尝试与一个使用Python3.5在Win7上使用pyserial的设备通信。我能够连接到正确的端口“COM4”,但忽略所有其他通信。我所做的是:

from serial import *
s = Serial('COM4', stopbits=2)  # All other settings are default
到目前为止没有错误。但我收到了一个错误,错误如下:

>> s.write('REM')  # Should put the device in 'Remote' mode
TypeError: unicode strings are not supported, please encode to bytes.
所以我把它改成:

>> s.write(b'REM')
3
然后它返回我试图发送到设备的字符串的字符数。例如,如果我尝试“S1”,它将返回2。该设备不响应该命令,也不会给出错误。我认为缺少通信是由于将字符串更改为字节造成的,但我不确定。有人有什么好主意能解开我的谜团吗