Serial error recovering

What is the best way to detect a serial transmission error?

Now, for framing errors, I am checking the internal nframe counter using tcgetcounters() function.

But my main question is what do I have to do if I detect a frame error (or any other transmission error)?

I am using the CRTSTOGGLE mode to control a RS485 device transmission / reception. I have found that every once in a while the RTS toggling stops working (the line is always active), and it seems to be caused by a framing error. How can I recover from that situation?

Regards,
Jose

You won’t be able to detect transmit errors, that’s the nature of Serial. Your protocol layer needs to be able to detect errors and re-request information. That’s why protocols like Modbus () use a start character and a CRC on the end of a data packet to help detect these kinds of problems.

For RTS toggle, it’s meant for use with RS485 communication (half duplex), so if you receive data while RTS is being toggled, you may run into problems where it gets ‘stuck’. So make sure you’re using it in a half duplex fashion or just toggle the pin as a GPIO before and after the write.