I'm trying to send 9 bytes through a serial port (tested with RS232, RS485) with Python 2.7 pySerial package. If I write out the bytes to the serial port, some of the bytes randomly get lost (do not arrive on the receiving end). If I use a 1 millisec wait between every write of a single byte, all bytes arrive to the receiving end.
I tested the functionality between 2 serial terminals on the same OS.
Here is the code fragment which causes packet (byte) losses:
import serial
import struct
ser = serial.Serial()
ser.baudrate = 9600
ser.parity = "N"
ser.rtscts = False
ser.xonxoff = False
ser.write(struct.pack('B', 0x61))
ser.write(struct.pack('B', 0x62))
ser.write(struct.pack('B', 0x63))
...
ser.close()
The fragment which is working:
import serial
import struct
from time import sleep
ser = serial.Serial()
ser.baudrate = 9600
ser.parity = "N"
ser.rtscts = False
ser.xonxoff = False
ser.write(struct.pack('B', 0x61))
sleep(0.001)
ser.write(struct.pack('B', 0x62))
sleep(0.001)
ser.write(struct.pack('B', 0x63))
sleep(0.001)
...
ser.close()
What can be the root cause for the random packet losses?
System details:
- OSX 10.9.4
- Python 2.7
- Minicom or screen was used for terminal emulation
Test environment:
- ATC USB/RS485 converters
- ATC Serial/RS485 converters with USB-Serial adapter
'\x61'
. And also write accept multiple bytes:ser.write('\x61\x62\x63')
. I believe the receiving end is unable to read those multiple writes consistently. – JBernardoser.write('\x61\x62\x63\x64\x65\x66\x67')
but had the same result. Additionally I have concerns on the theory that the receiving end is unable to handle multiple bytes - I'm using a terminal emulator (minicom or just screen) on the same PC. – balas