我有一个Python脚本,通过pySerial将数据包写入Arduino板。
有时在将代码写入主板时,erServ 5会引发输入/输出错误。
一些研究表明,这表示写入代表与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 Error Input/Output Error Errno 5
我的代码在发送时有问题吗?我是否需要检查串行连接是否准备好发送或发送后是否有延迟?
或者硬件或与硬件的连接有问题吗?
编辑:我从pyserial看着Linux实现,实现只是将错误传递给我的代码。所以从那里没有新的真正的见解。
有没有一种好方法来测试程序中发生了什么?