【发布时间】:2015-08-14 21:35:53
【问题描述】:
我正在开发一个需要使用 pyserial 模块将字节数组发送到串行端口的应用程序。我已经成功地在树冠中运行代码来做到这一点:
import serial
ser = serial.Serial('/dev/ttyACM0', 9600, serial.EIGHTBITS, serial.PARITY_NONE, serial.STOPBITS_ONE)
ser.write([4, 9, 62, 144, 56, 30, 147, 3, 210, 89, 111, 78, 184, 151, 17, 129])
Out[7]: 16
但是当我在 Spyder 中运行相同的代码(两者都运行 Python 2.7.6)时,我收到一条错误消息,如
import serial
ser = serial.Serial('/dev/ttyACM0', 9600, serial.EIGHTBITS, serial.PARITY_NONE, serial.STOPBITS_ONE)
ser.write([4, 9, 62, 144, 56, 30, 147, 3, 210, 89, 111, 78, 184, 151, 17, 129])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 475, in write
n = os.write(self.fd, d)
TypeError: must be string or buffer, not list
如何让 Spyder 在这方面表现得像 Canopy?
【问题讨论】:
-
ser.write(bytearray([4, 9, 62, 144, 56, 30, 147, 3, 210, 89, 111, 78, 184, 151, 17, 129])) -
在 Canopy 和 Spyder 中可能有不同版本的包 pyserial (
serial.version)?
标签: python pyserial spyder canopy