Skip to content
Advertisement

Serial communication on Linux with flow control enabled – bad behaviour

I wrote common functions in order to manage serial ports, based on the following structure:

JavaScript

I am calling these functions (see below) in another file in order to test an RS232 serial port. The flow control needs to be enabled.

JavaScript

In order to validate the implementation, the pinouts Tx and Rx have been connected together, idem for CTS and RTS. Everything works fine, the message sent can be read correctly. In addition, when Tx is disconnected from the Rx nothing is reading as expected.

But when the CTS is unplugged from the RTS the test blocks after the port closing step (~20 seconds).

However, if the function setuart() is called with flowControl == 0, the test does not block and returns the exepected error code without delay.

I probably understood something wrongly especially in port configuration. Is it the good way to do ?

Advertisement

Answer

The problem you are facing is a correct behaviour.

Leaving CTS unconnected with flow control enabled, means DTE (AKA PC) cannot send data to DCE (slave device).

When you try to write to the UART output buffer it, probably, is full and application temporarily stops running and waits until some buffer space becomes available.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement