All Packages Class Hierarchy This Package Previous Next Index
java.lang.Object | +----javax.comm.CommPort
CommPort
is an abstract class
that describes a communications port made available by the underlying
system. It includes high-level methods for controlling I/O that are
common to different kinds of communications ports. SerialPort
and ParallelPort
are subclasses of CommPort
that include additional methods for low-level control of physical
communications ports.
There are no public constructors for CommPort
. Instead
an application should use the static method
CommPortIdentifier.getPortIdentifiers
to generate a list
of available ports. It then chooses a port from this list and calls
CommPortIdentifier.openPort
to create a CommPort
object. Finally, it casts the CommPort
object to a
physical communications device class like SerialPort
or
ParallelPort
.
After a communications port has been identified and opened it can
be configured with the methods in the low-level classes like
SerialPort
and ParallelPort
. Then an IO
stream can be opend for reading and writing data. Once the application
is done with the port, it must call the closePort method. Thereafter the
application must not call any methods in the port object. Doing so will
cause a java.lang.IllegalStateException
to be thrown.
protected String name
public String getName()
public abstract InputStream getInputStream() throws IOException
getInputStream
returns null.
The read behaviour of the input stream returned by
getInputStream
depends on combination of the
threshold and timeout values. The possible behaviours are
described in the table below:
Threshold | Timeout | Read Buffer Size | Read Behaviour | ||
---|---|---|---|---|---|
State | Value | State | Value | ||
disabled | - | disabled | - | n bytes | block until any data is available |
enabled | m bytes | disabled | - | n bytes | block until min(m,n) bytes are available |
disabled | - | enabled | x ms | n bytes | block for x ms or until any data is available |
enabled | m bytes | enabled | x ms | n bytes | block for x ms or until min(m,n) bytes are available |
public abstract OutputStream getOutputStream() throws IOException
getOutputStream
returns null.
public void closePort()
closePort
when it is done with the port.
Notification of this ownership change will be propagated to all classes
registered using addPortOwnershipListener
.
public abstract void enableRcvThreshold(int thresh)
read
from the input stream for this port will return immediately.
enableRcvThreshold
is an advisory method which the driver
may not implement. By default, receive threshold is not enabled.
An application can determine whether the driver supports this feature
by first calling the enableRcvThreshold
method and then
calling the isRcvThresholdEnabled
method. If
isRcvThresholdEnabled
still returns false, then receive
threshold is not supported by the driver. If the driver does not implement
this feature, it will return from blocking reads at an appropriate time.
read
.
public abstract void disableRcvThreshold()
public abstract boolean isRcvThresholdEnabled()
public abstract int getRcvThreshold()
public abstract void enableRcvTimeout(int rcvTimeout)
read
from the input stream for this port will return immediately.
enableRcvTimeout
is an advisory method which the driver
may not implement. By default, receive timeout is not enabled.
An application can determine whether the driver supports this feature
by first calling the enableRcvTimeout
method and then
calling the isRcvTimeout
method. If
isRcvTimeout
still returns false, then receive timeout
is not supported by the driver.
read
, regardless of bytes in
input buffer.
public abstract void disableRcvTimeout()
public abstract boolean isRcvTimeoutEnabled()
public abstract int getRcvTimeout()
public abstract void enableRcvFraming(int framingByte)
read
from the input stream for this port will return immediately.
enableRcvFraming
is an advisory method which the driver
may not implement. By default, receive framing is not enabled.
An application can determine whether the driver supports this feature
by first calling the enableRcvFraming
method and then
calling the isRcvFramingEnabled
method. If
isRcvFramingEnabled
still returns false, then receive
framing is not supported by the driver.
framingByte
are used while the upper 24 bits are masked off. A value outside the range
of 0-255 will be converted to the value of its lowest 8 bits.
public abstract void disableRcvFraming()
public abstract boolean isRcvFramingEnabled()
public abstract int getRcvFramingByte()
getRcvFramingByte
is an integer, the low 8 bits of which represent the current byte
used for receive framing.
public abstract void setInputBufferSize(int size)
public abstract int getInputBufferSize()
public abstract void setOutputBufferSize(int size)
public abstract int getOutputBufferSize()
All Packages Class Hierarchy This Package Previous Next Index