Java Communications Extension API (draft)
Version 1.1 (EA3)
This document provides an overview of the components of the Java Communications
API, which is a standard extension to the Java platform. It is not a tutorial;
readers should know the basics of serial and parallel port programming,
and be comfortable reading the Java Communications Extension API reference
pages.
Like all Java standard extensions, the Java Communications Extension
API is intended to be implementable from specification by third parties.
javax.comm Extension Package
We thank you for the excellent feedback to date. Based on your comments,
we are investigating revisions to the API and reference implementations
at this time.
There are three levels of classes in the Java Communications Extension
API:
-
High-level classes like CommPortIdentifier and CommPort
manage access and ownership of communication ports.
-
Low-level classes like SerialPort and ParallelPort provide
an interface to physical communications ports. The current release of the
Java Communications Extension API enables access to serial (RS-232) and
parallel (IEEE 1284) ports.
-
Driver-level classes provide an interface between the low-level classes
and the underlying operating system. Driver-level classes are part of the
implementation but not the Java Communications Extension API. They should
not be used by application programmers.
The javax.comm package provides the following basic services:
-
Enumerate the available ports on the system. The static method CommPortIdentifier.getPortIdentifiers
returns an enumeration object that contains a CommPortIdentifier
object for each available port. This CommPortIdentifier object
is the central mechanism for controlling access to a communications port.
-
Open and claim ownership of communications ports by using the high level
methods in their CommPortIdentifier objects.
-
Resolve port ownership contention between multiple Java applications. Events
are propagated to notify interested applications of ownership contention
and allow the port's owner to relinquish ownership. PortInUseException
is thrown when an application fails to open the port.
-
Perform asynchronous and synchronous I/O on communications ports. Low-level
classes like SerialPort and ParallelPort have methods
for managing I/O on communications ports.
-
Receive events describing communication port state changes. For example,
when a serial port has a state change for Carrier Detect, Ring Indicator,
DTR, etc. the SerialPort object propagates a SerialPortEvent
that describes the state change.
A Simple Reading Example
SimpleRead.java opens
a serial port and creates a thread for asynchronously reading data through
an event callback technique.
A Simple Writing Example
SimpleWrite.java
opens a serial port for writing data.
Solaris Notes
The Solaris implementation of the Java Communications Extension API requires
the Solaris Native Threads
Pack for JDK 1.1.x.
Here's how to test the SampleRead.java example above on Solaris:
-
Attach a null-modem cable between two serial ports.
-
Start tip(1) on one of the serial ports:
% tip -9600 /dev/term/b
-
Compile ReadSample.java:
% javac ReadSample.java
-
Run ReadSample:
% java -native ReadSample
-
Type text into the tip(1) window.
java-commapi-comments@eng.sun.com