Arduino, Bluetooth, Linux continued

FindPorts.java (909Bytes)

Bluetooth, java, Linux - seem to be working together in harmony now. Some things I learned along the way regarding the RXTX java library and Linux com ports in general:

By default, only the root user has access to read/write the serial ports on the system. So if I take the sample code from RXTX I've attached called FindPorts.java and run it from the command line with my user account it will not list any ports. This code was lifted straight from the RXTX site. I've packaged it in a jar file for ease of use from the command line:

[scott@borg-cube ~]$ java -Djava.library.path=/home/scott/rxtx-2.1-7-bins-r2/Linux/i686-unknown-linux-gnu -jar findports.jar
Experimental: JNI_OnLoad called.
Stable Library
=========================================
Native lib Version = RXTX-2.1-7
Java lib Version = RXTX-2.1-7

There's no error, it just doesn't enumerate any ports which is odd, because I know they are there :) So running the same command as root gives me what I would expect:

[scott@borg-cube ~]$ sudo java -Djava.library.path=/home/scott/rxtx-2.1-7-bins-r2/Linux/i686-unknown-linux-gnu -jar findports.jar

Experimental: JNI_OnLoad called.
Stable Library
=========================================
Native lib Version = RXTX-2.1-7
Java lib Version = RXTX-2.1-7
/dev/ttyS1 - Serial
/dev/ttyS0 - Serial
/dev/lp0 - Parallel

It seems that my /dev/rfcomm1 serial port isn't showing up - after I RTFM I found the command line magic that makes my bluetooth serial port available to RXTX. Also, the comm port is not created until the PC and the bluetooth modem are connected, so it will not show up until you successfully run the rfcomm connect command mentioned in my previous post:

[scott@borg-cube ~]$ sudo java -Dgnu.io.rxtx.SerialPorts=/dev/rfcomm1 -Djava.library.path=/home/scott/rxtx-2.1-7-bins-r2/Linux/i686-unknown-linux-gnu -jar findports.jar

Experimental: JNI_OnLoad called.
Stable Library
=========================================
Native lib Version = RXTX-2.1-7
Java lib Version = RXTX-2.1-7
/dev/rfcomm1 - Serial
/dev/lp0 - Parallel

With that knowledge and some additional java code to wire everything together, I can read data in to my robot "dashboard" running in my Eclipse IDE.

 

 

 

 

Just a screenshot…

Screenshot.png

javafx radar widget for dashboard …

Wanted to post a screen shot showing the radar/sonar widget while the dashboard is running…

I’ve also cleaned up the gui freezing/synchronization issues i was experiencing when reading from the serial port.

sonar.png