I am using java/pi4j to for serial port in raspberry pi (Raspbian OS) to connect it to a device which has serial port. I am wondering is it possible to use software flow control (xonxoff) in my communication?

I couldn't find this feature in pi4j serial port class. If it doesn't have this capability, is there an alternative library supporting xonxoff for raspberry serial port (preferably in Java)?

PS: Or my question is wrong and, for xonxoff, I have to configure the port not from my program but from somewhere else?

  • I am just very curios as to what uses XON/XOFF in 2016?? Its a very buggy implementation and just left in the standard for fun I think? What device are you trying to communicate with?
    – Piotr Kula
    Oct 31, 2016 at 9:46
  • @ppumkin I was trying to communicate with a laboratory blood analyzer (which was old but the communication standard was even older!). Nov 3, 2016 at 8:02

2 Answers 2


You do not need a library written especially for the Raspberry Pi. The major point of standardization and modularization of components, software and hardware, is interchangeability. A serial port is a serial port.

Of course, accessing a serial port "natively" on Windows is probably going to be different than on Linux (I presume you are using the latter), just as accessing a file at a low level natively on Windows is different than it is on Linux. However, when we use high level portable languages such as Java, these differences are abstracted away. There is not a java.io.microsoft, a java.io.linux, a java.io.osx, a java.io.raspberrypi, java.io.acme.laptop, etc., etc. There is just java.io.

The java core doesn't, as far as I know, include any serial port functionality, but I am sure (just from a quick internet search) that there is a small pile of third party serial com libs that you could check for your two requirements:

  • Linux compatible.
  • Supports xonxoff.

Actually there's a third, because almost certainly this library will have to make use of native code, i.e., be compiled from something that isn't pure Java, meaning it will have to be open source, unless you can find one precompiled for ARMv6 or 7 (depending on your model of pi).

Anyway, Arduino tools are written in Java, run on Linux, and require use of the serial port. They are also open source, and apparently the serial com library they use is RxTx -- no ARM binaries, but the source repo is available via the downloads page.

That's one example, and an explanation of what it is you are looking for, to make it easier for you to look yourself.


Software XON and XOFF are just a software implementation for controlling the flow of characters. (XON/XOFF does not work with binary streams. It is also really old and over 25 years I have never actually used that, anytime)

So it sounds like all you have to do is listen for these charcters on your "serial" port and do the appropriate actions.

enter image description here

When you get the XOFF you just stop transmitting and when you get XON you start transmitting again.

Obviosly from the Pi's side you will never need to send XOFF because the Pi has enough processor power to handle 115kbs of text without backing up its "buffer"

reference: Implemenation abstract

  • 1
    XON/XOFF is much older (I used it more than 40 years ago) commonly used over modem links with no support for hardware control. The whole point of either flow control mechanism is that it is implemented by a lower level, hopefully invisible to the user. It is supported by the Linux drivers, although it obviously needs to be activated e.g. by IOCTL. It still has its uses because serial drivers still have limited buffer sizes.
    – Milliways
    Oct 31, 2016 at 10:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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