Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2006

Tip: Looking for answers? Try searching our database.

porting RXTX linux code to windows

Thread view: 
Arash Nikkar - 12 Apr 2006 18:50 GMT
I am trying to port some Java code which was written specifically for
linux over to windows, and I have run into a bit of a problem.

The linux code uses a USB->Ir dongle, but uses the RXTX comm package. I
am a bit confused by this, because I though the comm package does not
support USB. Is the Comm package being "fooling" (sorry couldn't think
of a better term), into thinking that the USB is a serial port. The
code is as follows:

String port = "/dev/ttyUSB0";  //also seems to use: /dev/ttyS0 for
testing
RXTXCommDriver gnuDriver = new RXTXCommDriver();
CommPortIdentifier.addPortName(port,
  CommPortIdentifier.PORT_SERIAL, gnuDriver);
portId = CommPortIdentifier.getPortIdentifier(port);
if (portId.getPortType() != CommPortIdentifier.PORT_SERIAL) {
    System.out.println("Port " + port + " is not a serial port");
    return;
};
serialPort = (SerialPort)portId.open("Test", 2000);
outputStream = serialPort.getOutputStream();
serialPort.setSerialPortParams(9600,
      SerialPort.DATABITS_8,
      SerialPort.STOPBITS_1,
      SerialPort.PARITY_NONE);

Seems straighforward to me, except for the PORT part. Is it possible to
mimick this code in windows?

The traditional way I have used serial ports with java is by asking the
system for all the available comm ports, and iterating through them:

List<SerialPort> serialPortList = new ArrayList<SerialPort>();
while (portList.hasMoreElements()) {
    CommPortIdentifier portId =
(CommPortIdentifier)portList.nextElement();
       if(portId.getPortType() == CommPortIdentifier.PORT_SERIAL &&
                       !portId.isCurrentlyOwned()) {
               try {
                   SerialPort tempPort = (SerialPort)
portId.open("Test", 2000);
                   tempPort.setSerialPortParams(9600,
SerialPort.DATABITS_8, SerialPort.STOPBITS_1,
                           SerialPort.PARITY_NONE);
...
}

thanks in advance...
Gordon Beaton - 13 Apr 2006 07:37 GMT
> The linux code uses a USB->Ir dongle, but uses the RXTX comm
> package. I am a bit confused by this, because I though the comm
[quoted text clipped - 3 lines]
>
> String port = "/dev/ttyUSB0";

All of the tty devices can be treated as serial ports by software,
regardless of the physical device (if any) they represent.

So even though your software may not support USB directly, the device
has been identified as a USB serial device and it will be supported by
the usbserial driver, which has created /dev/ttyUSB0 for applications
to access it through.

/gordon

Signature

[  do not email me copies of your followups  ]
g o r d o n + n e w s @  b a l d e r 1 3 . s e

Martin Gregorie - 13 Apr 2006 15:44 GMT
>> The linux code uses a USB->Ir dongle, but uses the RXTX comm
>> package. I am a bit confused by this, because I though the comm
[quoted text clipped - 11 lines]
> the usbserial driver, which has created /dev/ttyUSB0 for applications
> to access it through.

I think you'll find that your real problem is serial port support in
Java. I had a hunt around a bit over a year ago and found the following
three possibilities:

- Sun's javax.comm - only available for Solaris and Linux
- SimpleSerial - used to talk to PIC chips. Requires javax.comm
- RXTX, which is essentially a javax.comm replacement.
  Currently for Linux, OSX and Win32 (but this requires Cygwin).

These have all moved on since then. When I did the search RXTX needed a
Linux kernel module, SimpleSerial was standalone and only talked to a
PIC chip and javax.comm seemed to be moribund.

As a consequence I wrote SerialPort (serialport.sourceforge.net).
SerialPort is an interface class using sockets to talk to a C server
that drives the com ports. It is POSIX compliant, so should port easily
to any compiler/OS combo that has decent socket and poll() implementations.

HTH

Signature

martin@   | Martin Gregorie
gregorie. | Essex, UK
org       |

Arash Nikkar - 13 Apr 2006 16:16 GMT
Gordon,

so basically your saying that the USB is being interpreted as a serial
device in linux (since it is a tty), and in order to port the code over
(and continue to use the comm package rather than jUSB) I would have to
figure out a way for windows to treat the USB as a serial device as
well?

Martin,

You are right, the comm package is very lacking, and from what I have
read, Sun has stopped maintaining it. I dont know anything about
simpleSerial, but from what I have read about RXTX it is now fully
compatible with windows as well. Seems like a very robust package...
Martin Gregorie - 13 Apr 2006 22:10 GMT
> You are right, the comm package is very lacking, and from what I have
> read, Sun has stopped maintaining it. I dont know anything about
> simpleSerial, but from what I have read about RXTX it is now fully
> compatible with windows as well. Seems like a very robust package...

Don't forget they you'll need to install Cygwin to use it. I don't know
what implications that has for your production environment.

Mind you, using serial ports under Windows is a pain anyway. I needed to
 do it a while back and after trying to roll my own and then use some
PD drivers, neither being satisfactory, I ended up buying Willies
Software's COMM-DRV package, which worked very nicely. That was all C.
If I was doing it again I think I'd still go the COMM-DRV way.

When you've tried out RXTX touch base here again. I for one would like
to know how you get on with it.

Signature

martin@   | Martin Gregorie
gregorie. | Essex, UK
org       |

Arash Nikkar - 14 Apr 2006 17:52 GMT
Hi Martin,

I think you are wrong about needing cygwin for windows and RXTX. I just
ran a quick test, and I was able to use RXTX with java without cygwin.
I think the new version of RXTX has provided this.

As for my latest problem, I used IrCOMM2k to use my USB ir dongle as a
COMM port, and as far as java/windows is concerned everything seems to
be working fine. I dont get any exceptions, or anything of that sort,
but I can seem to get the communication across.

I think that OBEX is being wrapped incorrectly, but I dont know how to
debug it.
Martin Gregorie - 15 Apr 2006 12:16 GMT
> Hi Martin,
>
> I think you are wrong about needing cygwin for windows and RXTX. I just
> ran a quick test, and I was able to use RXTX with java without cygwin.
> I think the new version of RXTX has provided this.

Fair enough. I was just quoting from the RXTX website. It wasn't obvious
why Cygwin was needed apart from the installation instructions looking
like shell commands.

At a guess RXTX has been completely written at least twice and gained a
lot flexibility and portability in the process. When I first looked at
it, it was Linux-only, being based round a kernel module and native
interface code.

> As for my latest problem, I used IrCOMM2k to use my USB ir dongle as a
> COMM port, and as far as java/windows is concerned everything seems to
> be working fine. I dont get any exceptions, or anything of that sort,
> but I can seem to get the communication across.

Cool. Good to know. I haven't played with IR links yet, but I found
exactly the same transparency with USB<->serial converters under Linux.

Signature

martin@   | Martin Gregorie
gregorie. | Essex, UK
org       |



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.