# rxtx and serial port access

## bawolk

I am trying to access the serial port using the Java Communications API and RXTX.  I am getting the following error:

check_group_uucp(): error testing lock file

creation Error details: Permission deniedcheck_lock_status: No permission to create lock file.

After googling I found that it may be necessary to change the serial port permission to 666.   I have already added myself to the uucp group.

But if I chmod 666 /dev/ttyS0, it doesn't seem to have any effect.

[bruce@pogo bin]$ls /dev/ttyS0 -al

lr-xr-xr-x  1 root root 5 Jun  5 23:06 /dev/ttyS0 -> tts/0

Any ideas?

----------

## rodericj

I have written to serial ports before in java. I have not yet done it under Gentoo.

I would like to try a few things but my test apps aren't working. 

```
 CommPortIdentifier.getPortIdentifiers();
```

seems to return an empty iterator. This was supposed to just cycle through all of my available ports till we found a good one. Doesn't seem to work anymore. 

Have you done this?

How did you find the serial ports?

Is it compiled into your kernel at all? I did not see an option for this.

Once I get this, I should be able to help you. 

Thoughts?

----------

## R. Bosch

Hi,

The problem I have is that I cant create files in /var/lock...

I changed the permissions to 775 since group uucp is group-owner of /var/lock but nothing.... 

Is there an update-program I missed?

I'm member of group uucp, but have no rights there  :Confused: 

Do you have that too, rodericj?

----------

## R. Bosch

On rxtx.org in the mailinglist I found that you don't import javax.comm but gnu.io!

Yes, gnu.io!

In code:

```

//import javax.comm.*; //old way

import gnu.io.*; //new way

```

If you hava alotta code:

```

sed s:^"import javax.comm.*;":"import gnu.io.*;": -i *.java

```

 :Wink:   :Very Happy: 

This DOES work.

----------

## rodericj

Hmmm...well I didn't get that to work. What did you use for your classpath?

I got the typical compiler errors that one would get if it couldn't find the library.

Comments? What do you point the classpath too...is it the comm.jar file in rxtx directory?

----------

## R. Bosch

 *rodericj wrote:*   

> I got the typical compiler errors that one would get if it couldn't find the library.
> 
> 

 

Let's work off the list:

- What do you see when you pull RXTXcomm.jar trhough `unzip-l` ?

- Directory could be javax/comm or gnu/io

- What version rxtx do you use? (me rxtx-2.1-7pre17)

- Sun or blackdown (Not sure about blackdown)

- Got  Solaris/SPARC or Solaris/x86 ? Use Solaris/SPARC.

Hope this helps a bit

----------

## bawolk

I finally was able to access the serial port using rxtx-2.0.5-linux.tar.gz.  This was unpacked and the files then were moved to various places:

	cp librx*.so $JAVA_HOME/jre/lib/i386

	cp jcl.jar $JAVA_HOME/jre/lib/ext

	cp javax.comm.properties $JAVA_HOME/jre/lib

I copied the the comm.api file from the Java Communications API to $JAVA_HOME/jre/lib/ext

IMPORTANT NOTE:  rxtx would not work unless the permission on /var/lock was set to 775 (from 755)!!!  Also change the driver in javax.comm.properties to:

Driver=gnu.io.RXTXCommDriver.

It works fine now.

----------

## rodericj

 *R. Bosch wrote:*   

>  *rodericj wrote:*   I got the typical compiler errors that one would get if it couldn't find the library.
> 
>  
> 
> Let's work off the list:
> ...

 

Sorry for the delay...

```

Archive:  RXTXcomm.jar

  Length     Date   Time    Name

 --------    ----   ----    ----

     7426  12-05-01 14:35   META-INF/MANIFEST.MF

        0  12-05-01 14:34   gnu/io/

      251  12-05-01 14:35   gnu/io/CommDriver.class

     1016  12-05-01 14:35   gnu/io/CommPortEnumerator.class

     5575  12-05-01 14:35   gnu/io/CommPortIdentifier.class

     1621  12-05-01 14:35   gnu/io/CommPort.class

      377  12-05-01 14:35   gnu/io/CommPortOwnershipListener.class

     4043  12-05-01 14:35   gnu/io/Configure.class

      775  12-05-01 14:35   gnu/io/Configure$1.class

      824  12-05-01 14:35   gnu/io/Configure$2.class

     1072  12-05-01 14:35   gnu/io/Configure$3.class

      502  12-05-01 14:35   gnu/io/Configure$4.class

     6341  12-05-01 14:35   gnu/io/I2C.class

      762  12-05-01 14:35   gnu/io/I2C$I2COutputStream.class

     1057  12-05-01 14:35   gnu/io/I2C$I2CInputStream.class

     1830  12-05-01 14:35   gnu/io/I2C$MonitorThread.class

      821  12-05-01 14:35   gnu/io/I2CPortEvent.class

      258  12-05-01 14:35   gnu/io/I2CPortEventListener.class

     1672  12-05-01 14:35   gnu/io/I2CPort.class

     5685  12-05-01 14:35   gnu/io/LPRPort.class

      884  12-05-01 14:35   gnu/io/LPRPort$ParallelOutputStream.class

      918  12-05-01 14:35   gnu/io/LPRPort$ParallelInputStream.class

      892  12-05-01 14:35   gnu/io/LPRPort$MonitorThread.class

      304  12-05-01 14:35   gnu/io/NoSuchPortException.class

      618  12-05-01 14:35   gnu/io/ParallelPortEvent.class

      278  12-05-01 14:35   gnu/io/ParallelPortEventListener.class

      950  12-05-01 14:35   gnu/io/ParallelPort.class

      361  12-05-01 14:35   gnu/io/PortInUseException.class

     6504  12-05-01 14:35   gnu/io/Raw.class

      762  12-05-01 14:35   gnu/io/Raw$RawOutputStream.class

     1057  12-05-01 14:35   gnu/io/Raw$RawInputStream.class

     1830  12-05-01 14:35   gnu/io/Raw$MonitorThread.class

      821  12-05-01 14:35   gnu/io/RawPortEvent.class

      258  12-05-01 14:35   gnu/io/RawPortEventListener.class

     1109  12-05-01 14:35   gnu/io/RawPort.class

     6401  12-05-01 14:35   gnu/io/RS485.class

      782  12-05-01 14:35   gnu/io/RS485$RS485OutputStream.class

     1077  12-05-01 14:35   gnu/io/RS485$RS485InputStream.class

     1852  12-05-01 14:35   gnu/io/RS485$MonitorThread.class

      827  12-05-01 14:35   gnu/io/RS485PortEvent.class

      266  12-05-01 14:35   gnu/io/RS485PortEventListener.class

     1680  12-05-01 14:35   gnu/io/RS485Port.class

     8704  12-05-01 14:35   gnu/io/RXTXCommDriver.class

    12735  12-05-01 14:35   gnu/io/RXTXPort.class

     2020  12-05-01 14:35   gnu/io/RXTXPort$SerialOutputStream.class

     2026  12-05-01 14:35   gnu/io/RXTXPort$SerialInputStream.class

     2338  12-05-01 14:35   gnu/io/RXTXPort$MonitorThread.class

      393  12-05-01 14:35   gnu/io/RXTXVersion.class

      830  12-05-01 14:35   gnu/io/SerialPortEvent.class

      270  12-05-01 14:35   gnu/io/SerialPortEventListener.class

     1684  12-05-01 14:35   gnu/io/SerialPort.class

      332  12-05-01 14:35   gnu/io/UnsupportedCommOperationException.class

 --------                   -------

   103671                   52 files

```

The version of RXTX that I use...

1.5

I don't know what your version is...

I use blackdown...not sun....

Hmm...I think I am using SOlaris/x86....Let me try this stuff out. I will get back to you later tonight(possibly)

Thanks mang.

----------

## R. Bosch

 *rodericj wrote:*   

>  *R. Bosch wrote:*   
> 
> - What version rxtx do you use? (me rxtx-2.1-7pre17)
> 
>  
> ...

 

The version of RXTX that I use...

1.5

I don't know what your version is...

[/quote]

Question answered   :Wink: 

----------

## centryfox

hey gang...     has anybody gotten the emerge for rxtx v2.1.7_pre17 to work like it's supposed to?   

I was able to get my program to run without any errors by :

 - emerging rxtx

 - including /usr/share/rxtx-2/lib/RXTXcomm.jar in my classpath

 - copying /opt/rxtx-2/lib/librxtx*.so to $JAVA_HOME/jre/lib/i386/

 - using "import gnu.io.CommPortIdentifier;"   instead of "import javax.comm.*;"   

I'm using sun's jdk v1.5 - I've also tried using sun's jdk v1.4 - to no avail.   

NOW..    as I said,  the program runs fine - no exceptions...    BUT  none of my ports are available when I try to enumerate them.    Does anybody else have any experience with this?   Moreover,   does anybody else know what the problem is or how to fix it?

I've tried doing the install on a mandrake box from source - the 2.0 implementation (without the Solaris comm.jar file)  worked okay,  but the 2.1 implementation that used the solaris comm.jar file would never work, giving some nasty java exceptions...       The instructions for installing from source left me wanting more...    I'd really like to get the emerged version working   :Confused: 

If anybody can help clear this up for me - it'd be much appreciated! =)

Cheers!

----------

## Cicero

It is pretty easy to build from source.

./configure

make

make install

Also, I reccomend getting the "CVS" version, which seems to just be a snapshot for 2.1.7_pre20. I had problems with the pre17 in portage, and just built the CVS version myself. It works great.

----------

## centryfox

I'll give that a try tomorrow at work.   I ended up getting version 1.4 working using the solaris/sparc comm.jar file - but no luck with 2.0  :Sad: 

I was able (ultimately) to get 2.1 to install and work,  but I've been told to use the version that uses the solaris/spark comm api.    

I'll give the source install a go.    Thanks!

----------

## ksenos

I spent all the day trying to make rxtx to work.... but I fail... I have installed version 2.1.7_pre17 and any operation that is performed causes the following:

```

An unexpected exception has been detected in native code outside the VM.

Unexpected Signal : 11 occurred at PC=0xB7E6B9F9

Function=__libc_free+0x49

Library=/lib/libc.so.6

Current Java thread:

   at gnu.io.RXTXPort.open(Native Method)

   - locked <0xab85ec50> (a gnu.io.RXTXPort)

   at gnu.io.RXTXPort.<init>(RXTXPort.java:84)

   at gnu.io.RXTXCommDriver.getCommPort(RXTXCommDriver.java:772)

   at gnu.io.CommPortIdentifier.open(CommPortIdentifier.java:343)

   - locked <0xab81be70> (a gnu.io.CommPortIdentifier)

   at gr.ksquare.serialcomm.SerialComm2.<init>(SerialComm2.java:76)

   at gr.ksquare.serialcomm.SerialCommGUI.startSerialComm(SerialCommGUI.java:19)

   at gr.ksquare.serialcomm.SerialCommGUI.btnSetPortActionPerformed(SerialCommGUI.java:126)

   at gr.ksquare.serialcomm.SerialCommGUI.access$3(SerialCommGUI.java:124)

   at gr.ksquare.serialcomm.SerialCommGUI$4.actionPerformed(SerialCommGUI.java:113)

   at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1786)

   at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1839)

   at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)

   at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)

   at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)

   at java.awt.Component.processMouseEvent(Component.java:5100)

   at java.awt.Component.processEvent(Component.java:4897)

   at java.awt.Container.processEvent(Container.java:1569)

   at java.awt.Component.dispatchEventImpl(Component.java:3615)

   at java.awt.Container.dispatchEventImpl(Container.java:1627)

   at java.awt.Component.dispatchEvent(Component.java:3477)

   at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3483)

   at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3198)

   at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3128)

   at java.awt.Container.dispatchEventImpl(Container.java:1613)

   at java.awt.Window.dispatchEventImpl(Window.java:1606)

   at java.awt.Component.dispatchEvent(Component.java:3477)

   at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)

   at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)

   at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)

   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)

   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)

   at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)

Dynamic libraries:

08048000-08056000 r-xp 00000000 03:02 1453574    /opt/sun-jdk-1.4.2.08/bin/java

08056000-08059000 rwxp 0000d000 03:02 1453574    /opt/sun-jdk-1.4.2.08/bin/java

08059000-081fb000 rwxp 08059000 00:00 0          [heap]

aace8000-aad03000 r-xp 00000000 03:02 70580      /usr/lib/X11/locale/lib/common/ximcp.so.2

aad03000-aad05000 rwxp 0001b000 03:02 70580      /usr/lib/X11/locale/lib/common/ximcp.so.2

aad05000-aad0d000 r-xp 00000000 03:02 78979      /usr/lib/libXcursor.so.1.0.2

aad0d000-aad0e000 rwxp 00007000 03:02 78979      /usr/lib/libXcursor.so.1.0.2

aad1a000-aad25000 r-xp 00000000 03:02 1472768    /opt/rxtx-2/lib/librxtxSerial.so

aad25000-aad26000 rwxp 0000a000 03:02 1472768    /opt/rxtx-2/lib/librxtxSerial.so

aad26000-aade0000 r-xp 00000000 03:02 1454052    /opt/sun-jdk-1.4.2.08/jre/lib/i386/libfontmanager.so

aade0000-aadfb000 rwxp 000b9000 03:02 1454052    /opt/sun-jdk-1.4.2.08/jre/lib/i386/libfontmanager.so

aadfc000-aae11000 r-xp 00000000 03:02 78252      /usr/lib/libICE.so.6.3

aae11000-aae12000 rwxp 00014000 03:02 78252      /usr/lib/libICE.so.6.3

aae14000-aae1c000 r-xp 00000000 03:02 85515      /usr/lib/libSM.so.6.0

aae1c000-aae1d000 rwxp 00007000 03:02 85515      /usr/lib/libSM.so.6.0

aae1d000-aaee5000 r-xp 00000000 03:02 80957      /usr/lib/libX11.so.6.2

aaee5000-aaee9000 rwxp 000c7000 03:02 80957      /usr/lib/libX11.so.6.2

aaee9000-aaef6000 r-xp 00000000 03:02 78261      /usr/lib/libXext.so.6.4

aaef6000-aaef7000 rwxp 0000d000 03:02 78261      /usr/lib/libXext.so.6.4

aaef7000-aaf45000 r-xp 00000000 03:02 78272      /usr/lib/libXt.so.6.0

aaf45000-aaf49000 rwxp 0004d000 03:02 78272      /usr/lib/libXt.so.6.0

aaf49000-aaf50000 r-xp 00000000 03:02 86154      /usr/lib/libXp.so.6.2

aaf50000-aaf51000 rwxp 00006000 03:02 86154      /usr/lib/libXp.so.6.2

aaf54000-aaf56000 r-xp 00000000 03:02 420420     /usr/lib/gconv/ISO8859-7.so

aaf56000-aaf58000 rwxp 00001000 03:02 420420     /usr/lib/gconv/ISO8859-7.so

aaf58000-aaf5e000 r-xs 00000000 03:02 5587       /usr/lib/gconv/gconv-modules.cache

aaf5e000-aaf65000 r-xp 00000000 03:02 79157      /usr/lib/libXrender.so.1.2.2

aaf65000-aaf66000 rwxp 00006000 03:02 79157      /usr/lib/libXrender.so.1.2.2

aaf66000-aaf68000 r-xp 00000000 03:02 70582      /usr/lib/X11/locale/lib/common/xlcDef.so.2

aaf68000-aaf69000 rwxp 00001000 03:02 70582      /usr/lib/X11/locale/lib/common/xlcDef.so.2

aaf69000-aafbc000 r-xp 00000000 03:02 1454063    /opt/sun-jdk-1.4.2.08/jre/lib/i386/libmlib_image.so

aafbc000-aafbd000 rwxp 00052000 03:02 1454063    /opt/sun-jdk-1.4.2.08/jre/lib/i386/libmlib_image.so

aafbd000-ab28e000 r-xp 00000000 03:02 1454080    /opt/sun-jdk-1.4.2.08/jre/lib/i386/libawt.so

ab28e000-ab2a4000 rwxp 002d0000 03:02 1454080    /opt/sun-jdk-1.4.2.08/jre/lib/i386/libawt.so

ab2c9000-ab2d8000 r-xs 00000000 03:02 1473155    /usr/share/rxtx-2/lib/RXTXcomm.jar

ab2d8000-ab394000 r-xs 00000000 03:02 1454042    /opt/sun-jdk-1.4.2.08/jre/lib/ext/localedata.jar

ab394000-ab3a1000 r-xs 00000000 03:02 1454041    /opt/sun-jdk-1.4.2.08/jre/lib/ext/ldapsec.jar

ab3a1000-ab3bd000 r-xs 00000000 03:02 1454040    /opt/sun-jdk-1.4.2.08/jre/lib/ext/sunjce_provider.jar

ab5c1000-ab5ed000 r-xp 00000000 03:02 420937     /usr/lib/locale/el_GR/LC_CTYPE

b37f3000-b37f7000 r-xp 00000000 03:02 78177      /usr/lib/libXtst.so.6.1

b37f7000-b37f8000 rwxp 00004000 03:02 78177      /usr/lib/libXtst.so.6.1

b58a0000-b5e40000 r-xs 00000000 03:02 1454178    /opt/sun-jdk-1.4.2.08/jre/lib/charsets.jar

b5e40000-b5e51000 r-xs 00000000 03:02 1454188    /opt/sun-jdk-1.4.2.08/jre/lib/jce.jar

b5e51000-b5f2e000 r-xs 00000000 03:02 1454112    /opt/sun-jdk-1.4.2.08/jre/lib/jsse.jar

b5f2e000-b5f44000 r-xs 00000000 03:02 1454139    /opt/sun-jdk-1.4.2.08/jre/lib/sunrsasign.jar

b5f8e000-b7939000 r-xs 00000000 03:02 1454180    /opt/sun-jdk-1.4.2.08/jre/lib/rt.jar

b7939000-b794d000 r-xp 00000000 03:02 1454054    /opt/sun-jdk-1.4.2.08/jre/lib/i386/libzip.so

b794d000-b7950000 rwxp 00013000 03:02 1454054    /opt/sun-jdk-1.4.2.08/jre/lib/i386/libzip.so

b7950000-b7970000 r-xp 00000000 03:02 1454065    /opt/sun-jdk-1.4.2.08/jre/lib/i386/libjava.so

b7970000-b7972000 rwxp 0001f000 03:02 1454065    /opt/sun-jdk-1.4.2.08/jre/lib/i386/libjava.so

b7972000-b797a000 r-xp 00000000 03:02 420164     /lib/libnss_files-2.3.4.so

b797a000-b797c000 rwxp 00007000 03:02 420164     /lib/libnss_files-2.3.4.so

b797c000-b7983000 r-xp 00000000 03:02 420195     /lib/libnss_compat-2.3.4.so

b7983000-b7985000 rwxp 00006000 03:02 420195     /lib/libnss_compat-2.3.4.so

b7987000-b7997000 r-xp 00000000 03:02 1454049    /opt/sun-jdk-1.4.2.08/jre/lib/i386/libverify.so

b7997000-b7999000 rwxp 0000f000 03:02 1454049    /opt/sun-jdk-1.4.2.08/jre/lib/i386/libverify.so

b7999000-b799d000 rwxs 00000000 03:05 123        /tmp/hsperfdata_ksenos/21227

b799d000-b79be000 r-xp 00000000 03:02 420173     /lib/libm-2.3.4.so

b79be000-b79c0000 rwxp 00020000 03:02 420173     /lib/libm-2.3.4.so

b79c0000-b79d1000 r-xp 00000000 03:02 420203     /lib/libnsl-2.3.4.so

b79d1000-b79d3000 rwxp 00010000 03:02 420203     /lib/libnsl-2.3.4.so

b79d5000-b7ddb000 r-xp 00000000 03:02 1454060    /opt/sun-jdk-1.4.2.08/jre/lib/i386/client/libjvm.so

b7ddb000-b7df6000 rwxp 00405000 03:02 1454060    /opt/sun-jdk-1.4.2.08/jre/lib/i386/client/libjvm.so

b7e09000-b7f19000 r-xp 00000000 03:02 420190     /lib/libc-2.3.4.so

b7f19000-b7f1a000 ---p 00110000 03:02 420190     /lib/libc-2.3.4.so

b7f1a000-b7f1b000 r-xp 00110000 03:02 420190     /lib/libc-2.3.4.so

b7f1b000-b7f1e000 rwxp 00111000 03:02 420190     /lib/libc-2.3.4.so

b7f20000-b7f22000 r-xp 00000000 03:02 420196     /lib/libdl-2.3.4.so

b7f22000-b7f24000 rwxp 00001000 03:02 420196     /lib/libdl-2.3.4.so

b7f25000-b7f33000 r-xp 00000000 03:02 420206     /lib/libpthread-0.10.so

b7f33000-b7f34000 r-xp 0000d000 03:02 420206     /lib/libpthread-0.10.so

b7f34000-b7f35000 rwxp 0000e000 03:02 420206     /lib/libpthread-0.10.so

b7f79000-b7f7c000 r-xs 00000000 03:02 1454039    /opt/sun-jdk-1.4.2.08/jre/lib/ext/dnsns.jar

b7f7c000-b7f84000 r-xp 00000000 03:02 420171     /lib/libnss_nis-2.3.4.so

b7f84000-b7f86000 rwxp 00007000 03:02 420171     /lib/libnss_nis-2.3.4.so

b7f86000-b7f8e000 r-xp 00000000 03:02 1454056    /opt/sun-jdk-1.4.2.08/jre/lib/i386/native_threads/libhpi.so

b7f8e000-b7f8f000 rwxp 00007000 03:02 1454056    /opt/sun-jdk-1.4.2.08/jre/lib/i386/native_threads/libhpi.so

b7f8f000-b7fa4000 r-xp 00000000 03:02 420181     /lib/ld-2.3.4.so

b7fa5000-b7fa7000 rwxp 00015000 03:02 420181     /lib/ld-2.3.4.so

bfb8f000-bfba4000 rwxp bfb8f000 00:00 0          [stack]

ffffe000-fffff000 ---p 00000000 00:00 0          [vdso]

Heap at VM Abort:

Heap

 def new generation   total 576K, used 481K [0xab7f0000, 0xab890000, 0xabcd0000)

  eden space 512K,  86% used [0xab7f0000, 0xab85efb0, 0xab870000)

  from space 64K,  58% used [0xab880000, 0xab889568, 0xab890000)

  to   space 64K,   0% used [0xab870000, 0xab870000, 0xab880000)

 tenured generation   total 1408K, used 1395K [0xabcd0000, 0xabe30000, 0xaf7f0000)

   the space 1408K,  99% used [0xabcd0000, 0xabe2cfe8, 0xabe2d000, 0xabe30000)

 compacting perm gen  total 4864K, used 4693K [0xaf7f0000, 0xafcb0000, 0xb37f0000)

   the space 4864K,  96% used [0xaf7f0000, 0xafc85440, 0xafc85600, 0xafcb0000)

Local Time = Mon Aug 29 22:47:32 2005

Elapsed Time = 13

#

# The exception above was detected in native code outside the VM

#

# Java VM: Java HotSpot(TM) Client VM (1.4.2_08-b03 mixed mode)

#

```

Please note that I am trying to use the gnu.io.* package. I don't need to use the javax.comm api. Does anyone understand what this huge output means? Thank you very much.

Kostas

----------

