This one: javax.comm.SerialPort.setRTS(). You set and unset the voltage on the line following your desired protocol, like in the good old times. It's pretty low-level: RTS/CTS handshaking
The question is: Does the UART or the OS do the low-level RTS/CTS flow control exchange or do I have to manually setRTS(true)
to make the attached device send data, while checking for the attached device's permission to send data using isCTS()
?
Yes, this is unclear. I will go out on a limb and say that in principle the OS should handle this once the desire for flow control has been asserted. I cannot remember doing manual flow control (it's been a few years) and The Linux Serial Howto says:
Under Linux, the small UART FIFO buffers are not protected by flow
control but instead rely on a fast response to the interrupts they
issue. Some UART chips can be set to do hardware flow control to
protect their FIFOs but Linux (as of early 2003) doesn't seem to
support it. FIFO stand for "First In, First Out" which is the way it
handles bytes in a queue. All the 3 buffers use the FIFO rule but only
the one in the UART is named "FIFO". This is the essence of flow
control but there are still some more details.
and also RTS/CTS and DTR/DSR Flow Control:
This is "hardware" flow control. Flow control was previously explained
in the Flow Control subsection but the pins and voltage signals were
not. Linux only supports RTS/CTS flow control at present (but a
special driver may exist for a specific application which supports
DTR/DSR flow control). Only RTS/CTS flow control will be discussed
since DTR/DSR flow control works the same way. To get RTS/CTS flow
control one needs to either select hardware flow control in an
application program or use the command: stty -F /dev/ttyS2 crtscts (or
the like). This enables RTS/CTS hardware flow control in the Linux
device driver.
I would see whether everything works as expected by not doing explicit flow control. Also, use one of these serial line checkers if you can to physically check the status of RTS.
Note that the InputStream you get from a CommPort may block until data is available. This makes sense when the flow control is handled automagically underneath (...or the API designer expects you to do multithreading to handle everything. I hope not). Same for OutputStream.write()
, which will block until all the data have been sent out.