How to force Java to use the serial port in Linux?

We are using a Java application that manages a pin via a serial port. This works fine on windows with Sun Comm.jar supplied by the dll and properties file.

Now we are trying to use this solution on Linux (in fact, it works on various other versions of Linux in the field) - with Ubuntu server mode.

After many attempts - blood, sweat and almost tears, we have this scenario:

Java version 1.4.2_17 Linux - Ubuntu Comm libs - Comm3 supplied by the sun with the default driver specified

An external comm test shows the communication ports: / dev / ttyS0 and / dev / ttyS 1 But the Java application says that it is not possible to open the port / dev / ttyS 1

(invalid port errors occur using RXRT files)

Could anyone use java 1.4.2 for linux to communicate over the serial port and find a solution that I could apply in my script?

much appreciated

Phill

+6
java linux serial-port
source share
5 answers

I know this is an old question, but I created a Java package and a built-in library to allow reading and writing to the serial port, currently only in synchronous mode.

It is open source and available on GitHub:

j232 - Java source code

libj232 is the native j232 library.

The wiki page is here .

Please note that this is only a Linux package and library.

+3
source share

Make sure that you are using a user with serial access permissions. Some distributions put serial ports in the uucp group, so make sure the user belongs to this group.

+2
source share

It has been some time since I did this. I remember that you cannot just open / dev / ttyS 0 as a file and I / O.

I remember the same problem with Sun IO banks.

The solution I remember about was to create a small C command-line program that echoed stdin to the serial port and serial port to stdout. Then I ran this program from my java process. I don't have code, but there are many examples on the Internet for c programs that write to linux serial ports.

+1
source share

For several years now we have been using SerialIO libraries for Java serial communication on both Windows and Linux with great results (and no, I do not work for them :-)):

http://serialio.com/products/serialport/serialport.php

Libraries cannot automatically detect available serial ports on Linux, but you will have to manually configure them.

+1
source share

We have not changed much, nothing in the libraries used. but eliminating the use of EventListener in the serial port object fixes the problem.

This actually allowed our code to work with linux (jre1.4.2, slackware and Suns Comm3 drivers), where this was not a problem for Windows - strange.

Phill

0
source share

All Articles