RXTX on Windows and Bluetooth SPP doesn't work as expected

430 views
Skip to first unread message

Bruce Boyes

unread,
Jul 16, 2008, 7:20:22 PM7/16/08
to rx...@qbang.org
Hi

So I'm using RXTX on windows XP SP2 and talking to a Blue Soleil USB Bluetooth adapter with their software 5.2.227.1. Ultimately we want the PC app to control a robot with the remote Bluetooth adapter.
http://trackbot.systronix.com/bluetooth.html

If I use realterm to open a virtual COM25 port it automatically connects through the USB BT to a remote BT device (a Lemos Int LM-048). I can open and close the port as many times as I want to and the connection gets made and then disconnected as it should. So this tends to tell me that the USB BT adapter is OK and the Blue Soleil drivers seem to be working OK. RealTerm and the USB BT don't use RXTX as far as I know.

On the remote BT device I have it connected to another PC with RealTerm running. One of the BT adapters sends a CONNECT and DISCONNECT message at the appropriate times and I can see those on the remote PC RealTerm window. I can type data both ways.

However, when I try to use my own simple Java App on the PC, with RXTX to the virtual COM port, things fall apart.

BTW the same app on a cabled serial connection works fine, for millions of messages, with RXTX, so the problem doesn't appear to be in my serial code, or the RXTX comm package but in the use of BT or BT in combination with RXTX? That's what I can't yet figure out.

My Java code uses code like this to open the UART:

CommPortIdentifier cpi = CommPortIdentifier.getPortIdentifier(portName);
then
SerialPort serialPort = (SerialPort) cpi.open("TrackBot", 5000); // try-catch causes this to always fail!
then
in = serialPort.getInputStream(); // in a try-catch

With a clean powerup of the remote BT (Lemos LM-048), my Java code can open an input stream and write some data. But:

1) I see a CONNECT and then a DISCONNECT - but have no idea why the DISCONNECT happens. AFAIK my code isn't closing the COM port anywhere
2) then another CONNECT?? Why?
3) then my short app runs, sends some data to the COM port and it's transmitted over BT
4) then my app closes the serial port and terminates

If I try to run my app again, it reports that it got an instance of the UART (COM25, a virtual serial port from Bluetooth) but in fact there is no BT connection made. How is this possible?

I have to power cycle the Lemos LM-048 adapter in order to get my code to run again. The adapter takes 45 seconds to power up! This also seems strange.

And finally, if I put the cpi.open() in a try-catch block like this:
      try {
        SerialPort serialPort = (SerialPort) cpi.open("TrackBot", 5000);
        } catch (Exception piue) {
                  System.out.println(portName + " exception: " + piue.getMessage());
                  piue.printStackTrace();
        }
if (null == serialPort) {
         System.out .println("Error! " + getClass().getName()
        + " can't get Serial Port " + portName);
        System. exit(2);
        } else {
         System.out .println(getClass().getName() + " got Serial Port " + portName);
        }

The Exception is never thrown, but the value of serialPort is null so I see the message. If I take the open() out of the try-catch, serialPort is not null. I'm baffled.

Can anyone shed some light on this?

I'm going to write a simpler test program using javaxcomm and see if it acts differently, and then try it with RXTX as well as with a wired connection for both javaxcomm and rxtx.

best regards

Bruce

------- WWW.SYSTRONIX.COM ----------
  Real embedded Java and much more
+1-801-534-1017  Salt Lake City, USA

grudolph

unread,
Jul 16, 2008, 9:13:16 PM7/16/08
to Systronix TrackBot
Bruce,
I can't shed light on your problem myself,
but I would suggest talking to the Lejos NXT people
Brian Bagnall or Lawrie Griffiths, and maybe browsing
the Lejos iCommand code would help.
You probably alreeady know this, but iCommand is Java
code that runs on the PC but lets you control an NXT brick
via Bluetooth.
They had previously run into similar problems, and
solved them, I think, using Bluecove libraries.

George



On Jul 16, 7:20 pm, Bruce Boyes <bbo...@systronix.com> wrote:
> Hi
> So I'm using RXTX on windows XP SP2 and talking to a Blue Soleil USB Bluetooth adapter with their software 5.2.227.1. Ultimately we want the PC app to control a robot with the remote Bluetooth adapter.http://trackbot.systronix.com/bluetooth.htmlIf I use realterm to open a virtual COM25 port it automatically connects through the USB BT to a remote BT device (a Lemos Int LM-048). I can open and close the port as many times as I want to and the connection gets made and then disconnected as it should. So this tends to tell me that the USB BT adapter is OK and the Blue Soleil drivers seem to be working OK. RealTerm and the USB BT don't use RXTX as far as I know.
> On the remote BT device I have it connected to another PC with RealTerm running. One of the BT adapters sends a CONNECT and DISCONNECT message at the appropriate times and I can see those on the remote PC RealTerm window. I can type data both ways.
> However, when I try to use my own simple Java App on the PC, with RXTX to the virtual COM port, things fall apart.
> BTW the same app on a cabled serial connection works fine, for millions of messages, with RXTX, so the problem doesn't appear to be in my serial code, or the RXTX comm package but in the use of BT or BT in combination with RXTX? That's what I can't yet figure out.
> My Java code uses code like this to open the UART:
> CommPortIdentifier cpi = CommPortIdentifier.getPortIdentifier(portName);
> then
> SerialPort serialPort = (SerialPort) cpi.open("TrackBot", 5000); // try-catch causes this to always fail!
> thenin= serialPort.getInputStream(); // in a try-catch
> With a clean powerup of the remote BT (Lemos LM-048), my Java code can open an input stream and write some data. But:
> 1) I see a CONNECT and then a DISCONNECT - but have no idea why the DISCONNECT happens. AFAIK my code isn't closing the COM port anywhere
> 2) then another CONNECT?? Why?
> 3) then my short app runs, sends some data to the COM port and it's transmitted over BT
> 4) then my app closes the serial port and terminates
> If I try to run my app again, it reports that it got an instance of the UART (COM25, a virtual serial port from Bluetooth) but in fact there is no BT connection made. How is this possible?
> I have to power cycle the Lemos LM-048 adapter in order to get my code to run again. The adapter takes 45 seconds to power up! This also seems strange.
> And finally, if I put the cpi.open() in a try-catch block like this:
>      try{
>         SerialPort serialPort = (SerialPort) cpi.open("TrackBot", 5000);
>         }catch(Exception piue) {
>                   System.out.println(portName +" exception: "+ piue.getMessage());
>                   piue.printStackTrace();
>         }if(null==serialPort) {
>          System.out.println("Error! "+ getClass().getName()
>         +" can't get Serial Port "+ portName);
>         System.exit(2);
>         }else{
>          System.out.println(getClass().getName() +" got Serial Port "+ portName);
Reply all
Reply to author
Forward
0 new messages