0

I am using pyserial library to deal with serial communications between my CM4 and a particular device. This are my settings:

_baudrate = 9600
_parity=serial.PARITY_EVEN
_stopbits=serial.STOPBITS_ONE
_bytesize=serial.SEVENBITS
serial_port_B = serial.Serial(port='/dev/ttyAMA1',baudrate = _baudrate, parity=_parity, stopbits=_stopbits, bytesize=_bytesize, timeout=1)

And I read the port with:

serial_message_B = serial_port_B.read()

When the equipment that I am talking to has the same settings, all works fine but when the equipment changes settings I don't get any error on my read(). For example, if the parity changes shouldn't I get an exception for parity error? or if baudrate changes some type of error? Stranger is that if equipment changes the parity from EVEN to ODD I still get the message if my parity is EVEN, no errors, but if equipment changes parity to NONE and I am with EVEN I get nothing.

Any thoughts?

1
  • 1
    "Any thoughts" yes - you don't understand serial communication. If parity is wrong you may get error 50% of the time but rarely on 7 bit. Speed differences are NOT detected. If you REALLY want to check look at ioctl
    – Milliways
    Sep 29, 2022 at 8:47

1 Answer 1

0

Once upon a time parity was used as an error detection technique on unreliable analog transmission systems using electromechanical hardware.

Early electronic systems circa 1960 implemented parity to interwork with these but since ~1970 this was largely ignored in favour of more reliable techniques. Even in the 1970s I don't think I ever used parity. It is rarely used on current systems although UART implementations make parity errors available.

If your sender sends 7 bits and the receiver receives 7 bits you will get 7 bits. If the parity is wrong or missing you will still get 7 bits but 50% of the time parity will be wrong but AFAIK pyserial has no mechanism to report this.

On a digital transmission system error rate is so low it is unnecessary to check an knowing it is wrong doesn't help. Most microcomputers do not use parity; 8bit NP is usually the default.

It is possible to detect baud rate (I wrote a few adaptive serial routines in the 1970s but these generally require access to the raw logic levels). This is infeasible when logic is outsourced to UART hardware.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.