Serial read with python

Error checking active only on the transmitting side will add a checksum to the data packet that is then mishandled on the receiving side. The checksum can be any number of bytes.

(I tried to warn everyone. :stuck_out_tongue_winking_eye: )

image

The '\x00' appears to be a two-byte checksum added by the sending device. @juniorprogrammer, what is your dongle talking to? That is the device that might be adding an error detection checksum. If the receiving device isn’t expecting a checksum in the data, it will treat the checksum as data. If the receiving device is expecting a checksum and it knows how many bytes are in the checksum, then the receiving device will strip out the checksum.

PuTTY is stripping off the extra two bytes after the \r\n. The PuTTY manual refers to detecting CRC errors but doesn’t say anything about enabling Error Checking, so it might be ‘always enabled’ internally. If your dongle can be set to use CRC (or whatever error checking the sending device is using), then your dongle will strip the extra byte (assuming it’s a checksum). There is also one more setting to check: Flow Control.

image

The serial.Serial() class has a flow control argument, so check the PuTTY ‘Flow Control’ setting above and put one of these in your ser = serial.Serial() statement to use the same flow control that PuTTY is using.

xonxoff=True,
rtscts=True,

THEN…  Get the serial settings of the transmitting (sending) device and look for error checking enabled. And make sure both sides of the serial link have the same settings–including the error checking.