0

Do I have to use serialPort.setRTS(true) every time before reading data from serial inputstream or only once at the time of initializing the serialPort it is required

What is the difference between setRTS = true or false.

Not able to find detail description of this API.

Thanks in advance

pritz
  • 29
  • 2
  • 3

1 Answers1

0

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.

David Tonhofer
  • 14,559
  • 5
  • 55
  • 51
  • Thanks for the input. But what difference it will make if I make setRTS(false) or setRTS(true), in both of the scenario I am able to communicate. – pritz Aug 26 '14 at 06:28
  • I am looking to enable hardware flow control in my current implementation, currently I am only performing serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_RTSCTS_IN | SerialPort.FLOWCONTROL_RTSCTS_OUT); Is this sufficient or along with this serialPort.setRts(true) is also required Any feedback will be appreciated – pritz Aug 26 '14 at 06:31
  • @pritz Added more stuff. – David Tonhofer Aug 26 '14 at 09:45