Serial Port API

G

GMM50

Hello:

I am new to JAVA (very new) and thinking about using JAVA to control
instruments connected to a PC via the serial port. I've searched the
group and came across discussions about problems with early releases
of Sun's serial API.
Can anyone comment on the current state of the API? And does anyone
have first hand experience?
I'm only looking to perform simple serial I/O. My messages both ways
will be single line printable characters.

Thanks
George
 
J

julielaurek

Hello:

I am new to JAVA (very new) and thinking about using JAVA to control
instruments connected to a PC via the serial port. I've searched the
group and came across discussions about problems with early releases
of Sun's serial API.
Can anyone comment on the current state of the API? And does anyone
have first hand experience?
I'm only looking to perform simple serial I/O. My messages both ways
will be single line printable characters.

Thanks
George

the java comm api has some sample classes, simpleread and simplewrite
(i think they're downloaded with the necessary jar files and
properties and stuff) that should work fine if you're doing simple
serial i/o. they worked for me. :)
here's simpleread.java:
http://java.sun.com/developer/releases/javacomm/SimpleRead.java
and simplewrite:
http://java.sun.com/developer/releases/javacomm/SimpleRead.java
in case you can't find them in your downloaded files.

cheers!
JL
 
K

Knute Johnson

GMM50 said:
Hello:

I am new to JAVA (very new) and thinking about using JAVA to control
instruments connected to a PC via the serial port. I've searched the
group and came across discussions about problems with early releases
of Sun's serial API.
Can anyone comment on the current state of the API? And does anyone
have first hand experience?
I'm only looking to perform simple serial I/O. My messages both ways
will be single line printable characters.

Thanks
George

George:

The JavaComm API is no longer supported by Sun for Windows machines.
Version 2.0 is still available from Sun here:

http://javashoplm.sun.com/ECom/docs...spec-oth-JSpec&SiteId=JSC&TransactionId=noreg

I have had no problems with this code running on XP machines. I don't
know if it will work on Vista. Why Sun decided to drop support for
serial I/O on Windows machines I don't know.

You may be directed to use RXTX but is has some serious bugs in its
Windows version and I've found it unusable.
 
M

Martin Gregorie

GMM50 said:
Hello:

I am new to JAVA (very new) and thinking about using JAVA to control
instruments connected to a PC via the serial port. I've searched the
group and came across discussions about problems with early releases
of Sun's serial API.
Can anyone comment on the current state of the API? And does anyone
have first hand experience?
I'm only looking to perform simple serial I/O. My messages both ways
will be single line printable characters.
If you are comfortable with C, an practical approach is to write a
user-space server with the minimum functionality needed to get bytes
into and out of the serial port and talk to it from Java via a TCP/IP
connection.

If this sounds like a possible approach for you, take a look at
http://www.gregorie.org/computing/serialport/ - I wrote it for a private
application that hasn't yet surfaced. The project provides code for the
C server, a Java interface class, test harness and an example (glass
teletype) application. The C should compile and run in any ANSI C
environment that supports the poll() function and would be easy enough
to port to compilers that use select() - e.g. the DJGPP gcc port for
Windows.

HTH
 
G

GMM50

If you are comfortable with C, an practical approach is to write a
user-space server with the minimum functionality needed to get bytes
into and out of the serial port and talk to it from Java via a TCP/IP
connection.

If this sounds like a possible approach for you, take a look athttp://www.gregorie.org/computing/serialport/- I wrote it for a private
application that hasn't yet surfaced. The project provides code for the
C server, a Java interface class, test harness and an example (glass
teletype) application. The C should compile and run in any ANSI C
environment that supports the poll() function and would be easy enough
to port to compilers that use select() - e.g. the DJGPP gcc port for
Windows.

HTH

Hi Martin:

That's really what I'm looking to do. I'm very comfortable in C and
not yet even a beginner in Java.
The end goal is to interface PCs with the instruments either using
RS232 or Ethernet.
In both cases the data would be printable text.

The attraction to Java is the write once run anywhere plan. If Java
were automatically loaded and executed what a simple world it would
be. I'm trying to avoid loading all the drivers and special dlls that
come with C and Windows.

It appears the using the serial port will require that special piece
of code (a dll) on the users machine. That's OK for development and
the earlier users of this project.

And My hope is that the Ethernet interface will not require any of
that special code.

I've used Visual C, Visual Basic and C++ Builder. They all stumble
when you need to install on users machines and support is difficult.

Thanks for the input.
 
K

Knute Johnson

GMM50 wrote:

If you don't need bidirectional I/O then you can just open the com port
as a stream.
 
M

Martin Gregorie

GMM50 said:
It appears the using the serial port will require that special piece
of code (a dll) on the users machine. That's OK for development and
the earlier users of this project.
As you know by now, Java doesn't have built-in serial port support, and
there are issues with the various standard packages: SimpleSerial is the
simplest, but its slow: it was designed to support byte at a time comms
with a PIC microchip. Neither it or the Sun package are very current and
RXTX looks complex to install. I looked at them all and decided that
writing my own looked to be less problematic.

You're right about needing specialized code. Serial ports are simple to
handle under some OSen, e.g. Linux, any other *NIX, or Microware's OS9,
but quite hard under DOS or Windows.

A while back I needed to talk to a Parallax STAMP from C. I was using a
Borland compiler. Neither its standard libraries nor DOS/Windows
supplied any serial port support worth a damn and I couldn't find any
usable OSS code on the 'net. I ended up buying a copy of Willies
Software's COMM/DRV package, which "just worked". If you do have to talk
to serial ports on a DOS/Windows box this product is worth a look no
matter what you end up putting behind it.
And My hope is that the Ethernet interface will not require any of
that special code.
If your devices have built-in TCP/IP support then it should be easy to
handle them because Java's TCP/IP support is good and fairly easy to
use, especially if you've used sockets or datagrams in C.

Otherwise, you're going to end up building some sort of non-Java
interface. I think the options are:

1)to build something that's likely to look remarkably like my
SerialPort server and talk to it over TCP/IP. Done right,
this code can be application independent: effectively just
a byte pipe that any application can use to talk to any device
plugged onto a serial port.

2)use JINI to let Java talk directly to a lump of C that drives
the ports. I think this would require the application to live
on the same box as the serial ports - either that or you ending up
writing another serial server, but this time in Java.

3)as (1) but use a small, dedicated interface box that runs the server
and nothing else. Plug it onto your LAN where Java can find it.
It could run under the OS of your choice, would be small and low
powered and would allow the control software to be installed on any
other host(s) that can see it.

If you go for (3) the support hardware could be anything from a Beck
IPC@CHIP PC-on-a-chip or a Gumstix mini board upwards. The next step up
would be small form factor kit like NorhTec's MicroClient Jr, the Sumo
ST166 or systems based on mini-ITX boards. Many of these come with
minimal Linux distros as a standard option, so that would solve the
serial hardware interfacing problem. Or, or course, you could use a
regular PC with its backplane crammed with serial ports.
I've used Visual C, Visual Basic and C++ Builder. They all stumble
when you need to install on users machines and support is difficult.
It seems to me that using a dedicated interface box to handle the serial
ports is worth a close look. The benefit is that all the specialized
support libraries, etc only exist on the interface box. All applications
can be written in Java or whatever seems sensible and don't need
anything (except possibly an interface class) to connect to it: they
certainly don't need to know what's running in it.

If you use Java for the applications then they can even be installed
automatically on user's systems if you use Web Start to deploy them.

HTH
 
G

GMM50

Lots of good stuff!!! Thanks all.
How about this one?

There are USB to serial converters available for CPU that lost their
serial ports.
Could I get one plug it into the USB port on a PC.
Then use Java's USB support to drive this adapter.
Or did I just transfer the Java Serial Port problems to the Java USB
Port problems?

Am I off base here?

Thanks
George
 
H

Hunter Gratzner

The end goal is to interface PCs with the instruments either using
RS232 or Ethernet.
In both cases the data would be printable text.

The attraction to Java is the write once run anywhere plan. If Java
were automatically loaded and executed what a simple world it would
be. I'm trying to avoid loading all the drivers and special dlls that
come with C and Windows.

There is no way in Java around extra, native code. Sun had that extra
code as a separate Java extension under the name JavaComm, but
effectively dropped it for maybe 95% of all Java installations when
dropping support for Windows. They still support JavaComm for Linux
and Solaris. I know RxTx is regularly bad-mouthed in this group, but
it is worth a look and can replace JavaComm on many platforms http://rxtx.org/
And My hope is that the Ethernet interface will not require any of
that special code.

Java TCP/IP support is OK, but not fantastic. E.g. access to ICMP and
to the more obscure configuration options of typical TCP/IP stacks is
not provided. If you plan to run anything else than IP as Layer 3 and
UDP or TCP as Layer 4 protocol then you are out of luck with Java, but
this has become rare these days.
I've used Visual C, Visual Basic and C++ Builder. They all stumble
when you need to install on users machines and support is difficult.

Expect to have similar problems with Java, when it comes to the
installation of the JRE. You can either bundle the JRE with your
applications, or you can insist that the user installs a JRE
separately. In the first case you are responsible for bundling and
installing the right JRE versions for all platforms you want to
support. In the later case you need to rely on users who notoriously
get things wrong.

On top of the JRE the serial interface extension needs to be
installed. Installing JavaComm is error-prone, and it resists Web
Start installation (can be made to work with ugly hacks). Installing
RxRt is tricky at times, too.

Then you can finally deploy your application via Web Start or
otherwise,

If you need small formfactor PC hardware, then the Jetway J7F2 mini-
ITX boards with an additional four-port serial interface expansion
board are nice.

If you instead want to equip your serial devices with Serial-to-
Ethernet interfaces, then look at Lantronix XPort. This is a component
the size of a slightly larger Ethernet RJ45. It is supposed to go on
the device's circuit board. They are expensive, but an XPort even
contain an embedded web server, SNTP management, telnet, TFTP and E-
Mail alert support. All in that one RJ45 socket.
 
H

Hunter Gratzner

Could I get one plug it into the USB port on a PC.
Then use Java's USB support to drive this adapter.

Java has no USB support. Sun promised it for years and is running a a
specification request. But nothing is ready. There are prototype
implementations available, but I consider them a joke.

BTW, have you considered doing your stuff with LabVIEW? It is the
standard in that area.
 
M

Martin Gregorie

GMM50 said:
>
There are USB to serial converters available for CPU that lost their
serial ports.
Could I get one plug it into the USB port on a PC.
Then use Java's USB support to drive this adapter.
Or did I just transfer the Java Serial Port problems to the Java USB
Port problems?

Am I off base here?
A quick scan shows two packages, jUSB and JSR-80, that can handle USB
serial converters. I don't think there are any more or a 2006 review
article in Java.net would have mentioned them.

jUSB is dependent on javax.comm for serial port support, so runs on
Solaris/Linux/Windows same as javax.comm. Sourceforge shows no code
releases since 2001.

I haven't found enough info to know JSR-80's limitations. It doesn't
seem to depend on other packages. Instead is has its own set of
OS-dependent JAR files and it looks as if these use C++ via JINI for its
hardware interface. I think its Linux support is more developed than its
Windows support (which is only in beta). I couldn't get an impression of
how active its developer community is.

The bottom line seems to be that USB support is in much the same state
as serial port support.

BTW, you don't say what your preferred target OS is, so I've been
assuming Windows. Is this correct?
 
R

Roedy Green

If you go for (3) the support hardware could be anything from a Beck
IPC@CHIP PC-on-a-chip or a Gumstix mini board upwards.

back in the 80's I had a serial task of controlling department store
fans and lights using an 80286 and DOS. I used an intelligent board
that handled the interrupts and buffering. It was a snap to interface
to with FORTH. It takes a load off the CPU and ensures you don't drop
characters. It worked flawlessly. I guess with serial ports going
the way of the dodo we won't see any evolution toward smarter hardware
as standard.
 
K

Knute Johnson

Hunter said:
There is no way in Java around extra, native code. Sun had that extra
code as a separate Java extension under the name JavaComm, but
effectively dropped it for maybe 95% of all Java installations when
dropping support for Windows. They still support JavaComm for Linux
and Solaris. I know RxTx is regularly bad-mouthed in this group, but
it is worth a look and can replace JavaComm on many platforms http://rxtx.org/

RXTX uses a dll just like JavaComm. There is no reason not to use
JavaComm, it works fine. RXTX has some serious bugs in their Windows
version. For example they can't do blocking I/O and the timeouts are
all messed up.

JavaComm works just fine! It is portable and it works on Windows, Linux
and Solaris. The only problem with it is that it isn't supported by Sun
any more. But then neither is JMF and thousands of people are still
using that.
 
G

GMM50

I am new to JAVA (very new) and thinking about using JAVA to control
instruments connected to a PC via the serial port.

OK conclusions for what I'm trying to accomplish the Sun Java Com API
looks just fine. Simple Text in and out. I'm actually sending and
receiving complete lines terminated by a carriage return. I'll load
their drivers and the low end systems will have serial support.

Thank all for your comments and help. A very useful conversation.
Except the suggestion about Forth.
Just Kidding!!!! But you know how much heat you take and I also
suspect you know how useful Forth really is.

Thank you all again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top