7

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

3
  • Are you sure that java process has permissions to open /dev/ttyS[01]? Commented Mar 12, 2009 at 13:14
  • what is the error? And I agree with Eugene that it is likely permissions
    – TofuBeer
    Commented Mar 12, 2009 at 14:29
  • any solutions for this problem? I'm also have same error.
    – Sastrija
    Commented Mar 11, 2011 at 2:09

5 Answers 5

4

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.

2

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.

1

It's been a while since I've done this. I remember that you can't just open /dev/ttyS0 as a file and I/O to it.

I remember having the same problem with Sun IO jars also.

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

1
  • hmmm, I have offered a solution to the guy in New Zealand who are looking for help on this. But I need to wait for tomorrow (11 hrs ahead) to see if they get anywhere. Then I will place my finding here. thanks man Commented Mar 12, 2009 at 14:55
1

We've been using the SerialIO libraries for Java serial communications on both Windows and Linux for several years now with great results (and no, I don't work for them :-)):

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

The libraries do not autodetect the available serial ports on Linux though - you have to manually configure them.

2
  • Hi tony, I am trying to configure SerialIO in Ubuntu. I get the native lib loaded correctly for my ubuntu 64bit but when I try to open a port I get javax.comm.NoSuchPortException: /dev/ttyUSB0: not found in port list. but the device IS there and it's not used by any other app. Any help will be greately appreciated. Maybe I can make a question that you can answer? Thanks! Commented Apr 27, 2013 at 23:50
  • @DavidHofmann Oooof ... it's been a couple of years since I worked on that stuff - not sure I even have the code anymore :-(. I do remember that exact problem though and I think I had to manually add /dev/tty/USB0: to a config file that I think mapped the USB port to a serial port. Not much help I'm afraid :-(. I'll hunt around and see if I can dig out the original code.
    – tonys
    Commented Apr 29, 2013 at 6:43
0

We did not change much, nothing in the libraries used. but removing the use of an EventListener on the serial port object fixed the problem.

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

Phill

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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