How to access serial port - Linux, JRuby 1.7.2, Java 1.8?


What are my options for using a serial port on this setup?

$ jruby -v
jruby 1.7.2 (1.9.3p327) 2013-01-04 302c706 on Java HotSpot(TM) 64-Bit Server VM 1.8.0-ea-b71 +indy [linux-amd64]

Craig -

JRuby accesses system resources through the Java Virtual Machine, so the
question becomes ‘how do I access the serial port in Java?’. I googled
“java access serial port”. There were several solutions; this one was
at the top of the list:

http://pharos.ece.utexas.edu/wiki/index.php/How_to_Access_Your_Serial_Port_using_Java

It discusses using rxtx (Download - Rxtx)
as a library providing/simplifying access to the serial port. You
download the tar ball, install the .so files, and use the .jar file
included in it.

You can ignore all the instructions relating to Eclipse in any way,
everything you need to do should be doable on the command line without
Eclipse.

For a third party jar file, you can just put it somewhere accessible,
and add its filespec to $CLASSPATH at runtime. I have an example of
doing that with an Oracle JDBC jar file in an article at
http://www.bbs-software.com/blog/2013/01/09/using-oracle-in-jruby-and-rails/.

Then you’ll need to call the Java library from your JRuby code.

  • Keith

Keith R. Bennett

On further examination, I recommend reading
Accessing serial ports the easy way.
He says that PureJavaComm is better than rxtx, and shows a way to access
the serial port without any special code at all using sockets and the
socat utility.

  • Keith