Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get Java to use the serial port in Linux?

We make use of a java application that manages a pinpad via the serial port. This works perfectly on windows with the Sun Comm.jar, the supplied dll and the properties file.

Now we are attempting to use this solution on Linux (actually it does run on various other flavours of linux out in the field) - with Ubuntu server mode.

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

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

An external comm test shows the comm ports: /dev/ttyS0 and /dev/ttyS1 But the java application says unable to open port /dev/ttyS1

(using the RXRT files produces invalid port errors)

Has anyone been able to use java 1.4.2 on linux for serial port communication and found a solution that I could apply in my scenario?

greatly appreciated

Phill

like image 676
Phillip Gibb Avatar asked Mar 12 '09 13:03

Phillip Gibb


People also ask

Can JavaScript read serial port?

A serial port is a bidirectional communication interface that allows sending and receiving data byte by byte. The Web Serial API provides a way for websites to read from and write to a serial device with JavaScript.

How do I know if my serial port is working Linux?

Use the setserial command to check and use serial ports. The setserial is a program designed to set and/or report the configuration information associated with a serial port.


2 Answers

I know this is an old question but I have created a Java package and native library to allow serial port read and write, currently in synchronous mode only.

It's open source and available on GitHub:

j232 - The Java source code

libj232 - j232's native library.

The wiki page is here.

Note this is a Linux only package and library.

like image 102
D-Dᴙum Avatar answered Sep 26 '22 18:09

D-Dᴙum


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

like image 30
jassuncao Avatar answered Sep 24 '22 18:09

jassuncao