I have a Python script that writes data packets to an Arduino board through pySerial. Sometimes while writing the code to the board pySerial raises an input/output error with errno 5.
Some research says that this indicates an error while writing in the file representing the connection to the Arduino board.
The code that sends, sends only single byte packets:
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__())
The error printed by this code is:
OS Error Input/Output Error Errno 5
Is there something wrong in my code while sending? Do I need to check if the serial connection is ready to send something or should there be a delay after the sending? Or could there be a problem with the hardware or the connection with the hardware?
Edit: I looked into the Linux implementation from pyserial and the implementation is only passing the error to my code. So no new real insights from there. Is there a good way to test what is happening in the program?