Java Reference
In-Depth Information
To monitor a port for changes in its ownership, you can implement the
CommPortOwnershipListener interface. You must override the method
ownerShipChange (int typeChange) ,which can detect three types of
ownership changes: ownership attained, port now available, and ownership
requested.
23.4.4 Port communications
The procedure to communicate over a port involves the following operations:
1. open() in the port's CommPortIdentifier provides a CommPort object for the
port.
2. getInputStream() and getOutputStream() in CommPort provide streams for
reading data from and writing data to the port.
3. Use these streams to carry out the desired I/O.
4. close() in CommPort releases the port for other applications to use.
Other CommPort methods can set parameters for the port communications such
as the I/O buffer sizes and how long the read operation will wait for data before
returning.
23.4.5 Serial port I/O
The javax.comm serial port classes assume the system has one or more ports
following the RS-232 (or EIA232) standard. Table 23.1 lists the pins for the DB9
connector that follows this standard. RS-232 originated in the 1960s and dealt
with a computer talking to a display terminal. This historical basis explains some
of the names for the 9 pins on the connector. (See [7] for a description of the less
common 25-pin DB25 connector.)
Serial ports send and receive one bit at a time using a positive voltage (between
3 and 25V) to indicatea0bit and a negative voltage (between
25V) to
indicatea1bit. The duration of a voltage depends inversely on the baud rate .
An asynchronous serial protocol (not part of the RS-232 standard) is required
to determine how to decode the bits into bytes. The standard protocol groups the
bits into a standard data unit (SDU) consisting typically of either 7 data bits (for
ASCII) or 8 data bits. To indicate where a SDU begins, a start bit value of 0 is
sent. To indicate the end of a SDU, the group ends with one or two stop bits ,
each of value 1. To combat noise and bit errors, a parity bit is usually included.
For even parity the bit value is 1 if the number of one bits in the SDU is even
and zero if the number is odd. For odd parity the bit value is 1 if the number of
one bits is odd and zero if even. So, depending on the protocol settings, the total
number of bits sent for an SDU can vary from 9 bits (7 data bits, 1 stop bit and
no parity) up to 12 bits (8 data bits, 2 stop bits and a parity bit).
3to
Search WWH ::




Custom Search