我有一个Python脚本,它通过pySerial将数据包写入Arduino板。 有时在将代码写入主板时,pySerial会引发errno 5的输入/输出错误。使用pySerial从Python获取输入/输出错误
一些研究表明,这表示在写入表示与Arduino板连接的文件时出现错误。
发送的代码,只发送单字节的数据包:
try:
# Check if it's already a single byte
if isinstance(byte, str):
if len(byte) == 1: # It is. Send it.
self.serial.write(byte)
else: # It's not
raise PacketException
# Check if it's an integer
elif isinstance(byte, int):
self.serial.write(chr(byte)) # It is; convert it to a byte and send it
else: raise PacketException # I don't know what this is.
except Exception as ex:
print("Exception is: " + ex.__getitem__() + " " + ex.__str__())
由该代码印刷错误是:
OS错误输入/输出错误errno的5
我的代码在发送时有问题吗?我是否需要检查串行连接是否准备好发送或发送后是否有延迟? 或者硬件或与硬件的连接有问题吗?
编辑:我查看了pyserial的Linux实现,实现只是将错误传递给我的代码。所以从那里没有新的真正的见解。 有没有一种很好的方法来测试程序中发生了什么?
我有同样的问题 - 你有任何想法如何赶上/防止这个错误? – 2013-05-13 18:07:26