Java Reference
In-Depth Information
reader to these sources for more details about using the parallel port and for
aspects of serial port I/O not covered here.
23.4.1 Port classes
There are two types of port classes in
javax.comm
. The abstract class
CommPort
holds methods to control and perform I/O over a specific port. The
class
CommPortIdentifier
gives information about the ports on the system
and can create an instance of
CommPort
for a given port.
23.4.1.1 CommPort
This abstract class for port representation includes various methods such as
getInputStream()
and
getOutputStream()
to obtain streams to trans-
mit and receive data over a port. The subclasses of
CommPort
, also abstract,
include:
SerialPort
- this class works with RS-232 ports. Methods in this class provide for
control, monitoring, transmission and reception. You can set parameters such as the baud
rate, parity, numbers of stop bits and data bits and can choose flow control protocols.
Individual control pins, such as
DTR
(Data Terminal Ready) and
CTS
(Clear to Send),
can be set directly.
ParallelPort
- this class works with the 8-bit IEEE-1284 parallel (or printer) port.
Methods allow for setting the port mode such as the extended and enhanced modes.
Also, the transmission can be suspended and restarted (useful for pausing and restarting
a printout), and several status messages can be read such as
paper out
and
printer busy
.
Concrete subclasses of
SerialPort
and
ParallelPort
are available in
javax.comm
for each particular platform. You do not create instances of
these classes directly from their constructors but from factory methods in the
CommPortIdentifier
class.
23.4.1.2 CommPortIdentifier
An instance of this class, discussed further in the next section, provides informa-
tion about a specific port, such as the port's name and type, but it does not set
ownership of the port or allow for any control or I/O over the port. Instead, you
use the
open()
method of an instance of
CommPortIdentifier
for a specific
port to obtain an instance of a
CommPort
subclass for that port.
As with the
SerialPort
and
ParallelPort
classes, you do not normally
obtain instances of
CommPortIdentifier
directly from a constructor but with
afactory method in
CommPortIdentifier.
23.4.2 Finding ports
The
CommPortIdentifier
class acts as both a source of information about
ports on a system and also as a descriptor of a particular port. The static method
Search WWH ::
Custom Search