comm
Interface CommPortInterface

All Known Subinterfaces:
CommPortInterface, ParallelPortInterface, SerialPortInterface, SerialPortInterface
All Known Implementing Classes:
CommPort, CommPort, ParallelPort, ParallelPort, RXTXPort, SerialPort, SerialPort

public interface CommPortInterface

A communications port. CommPortInterface is an interface that describes a communications port made available by the underlying system. CommPort is an abstract class that 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.

See Also:
CommPortIdentifier, ParallelPort, SerialPort

Method Summary
 void close()
          Closes this communications port.
 void disableReceiveFraming()
          Disables receive framing.
 void disableReceiveThreshold()
          Disables receive threshold.
 void disableReceiveTimeout()
          Disables receive timeout.
 void enableReceiveFraming(int framingByte)
          Enables receive framing.
 void enableReceiveThreshold(int thresh)
          Enables receive threshold.
 void enableReceiveTimeout(int rcvTimeout)
          Enables receive timeout.
 int getInputBufferSize()
           
 java.io.InputStream getInputStream()
           
 java.lang.String getName()
          Gets the name of the communications port.
 int getOutputBufferSize()
           
 java.io.OutputStream getOutputStream()
           
 int getReceiveFramingByte()
           
 int getReceiveThreshold()
           
 int getReceiveTimeout()
           
 boolean isReceiveFramingEnabled()
           
 boolean isReceiveThresholdEnabled()
           
 boolean isReceiveTimeoutEnabled()
           
 void setInputBufferSize(int size)
          Sets the input buffer size.
 void setOutputBufferSize(int size)
          Sets the output buffer size.
 java.lang.String toString()
           
 

Method Detail

toString

java.lang.String toString()
Overrides:
toString in class java.lang.Object
Returns:
a string representation of this port.

getName

java.lang.String getName()
Gets the name of the communications port. This name should correspond to something the user can identify, like the label on the hardware.

Returns:
name of the port

getInputStream

java.io.InputStream getInputStream()
                                   throws java.io.IOException
Returns:
an input stream that can be used to read data from the communications port. If the port doesn't support reading data, this method returns null.

The blocking behaviour of this input stream depends on the threshold and timeout values, as shown below for a read buffer size of n bytes:

Threshold Timeout Blocking behaviour
StateValue StateValue
disabled disabled block until data is available
enabledm bytes disabled block until min(m, n) bytes are available
disabled enabledt ms block for t ms or until data is available
enabledm bytes enabledt ms block for t ms or until min(m, n) bytes are available
Throws:
java.io.IOException

getOutputStream

java.io.OutputStream getOutputStream()
                                     throws java.io.IOException
Returns:
an output stream that can be used to send data to the communications port. If the port doesn't support sending data, this method returns null.
Throws:
java.io.IOException

close

void close()
Closes this communications port. All PortOwnershipListeners will be  notified of this change of ownership. Further method calls on this  object will throw IllegalStateException. Further calls on the  associated InputStream or OutputStream will throw IOException.

Close does not block. Undelivered data is discarded. Blocked read and  write operations are aborted if the underlying operating systems  supports an IO abort mechanism. To await the delivery of undelivered  data call OutputStream.flush() or OutputStream.close() before calling  Port.close().


enableReceiveThreshold

void enableReceiveThreshold(int thresh)
                            throws UnsupportedCommOperationException
Enables receive threshold. When the specified threshold number of bytes are retrieved, read will return immediately.

Parameters:
thresh - the number of bytes in the input buffer
Throws:
UnsupportedCommOperationException - if receive threshold is not supported by the driver
See Also:
disableReceiveThreshold()

disableReceiveThreshold

void disableReceiveThreshold()
Disables receive threshold.

See Also:
enableReceiveThreshold(int)

isReceiveThresholdEnabled

boolean isReceiveThresholdEnabled()
Returns:
true if receive threshold is enabled.
See Also:
enableReceiveThreshold(int)

getReceiveThreshold

int getReceiveThreshold()
Returns:
the receive threshold value. If receive threshold is diabled or not supported, this value is meaningless.
See Also:
enableReceiveThreshold(int)

enableReceiveTimeout

void enableReceiveTimeout(int rcvTimeout)
                          throws UnsupportedCommOperationException
Enables receive timeout. When the specified number of milliseconds have elapsed, read will return immediately.

Parameters:
rcvTimeout - the number of milliseconds to block for
Throws:
UnsupportedCommOperationException - if receive timeout is not supported by the driver
See Also:
disableReceiveTimeout()

disableReceiveTimeout

void disableReceiveTimeout()
Disables receive timeout.

See Also:
enableReceiveTimeout(int)

isReceiveTimeoutEnabled

boolean isReceiveTimeoutEnabled()
Returns:
true if receive timeout is enabled.
See Also:
enableReceiveTimeout(int)

getReceiveTimeout

int getReceiveTimeout()
Returns:
the receive timeout value. If receive timeout is diabled or not supported, this value is meaningless.
See Also:
enableReceiveTimeout(int)

enableReceiveFraming

void enableReceiveFraming(int framingByte)
                          throws UnsupportedCommOperationException
Enables receive framing. The supplied byte value in the input suggests the end of the received frame, and read returns immediately. Only the low 8 bits of the supplied value are significant.

Parameters:
framingByte - the frame delimiter
Throws:
UnsupportedCommOperationException - if receive framing is not supported by the driver
See Also:
disableReceiveFraming()

disableReceiveFraming

void disableReceiveFraming()
Disables receive framing.

See Also:
enableReceiveFraming(int)

isReceiveFramingEnabled

boolean isReceiveFramingEnabled()
Returns:
true if receive framing is enabled.
See Also:
enableReceiveFraming(int)

getReceiveFramingByte

int getReceiveFramingByte()
Returns:
true if receive framing byte. If receive framing is diabled or not supported, this value is meaningless.
See Also:
enableReceiveFraming(int)

setInputBufferSize

void setInputBufferSize(int size)
Sets the input buffer size. The driver may choose to ignore this method.

Parameters:
size - in bytes

getInputBufferSize

int getInputBufferSize()
Returns:
the input buffer size. The driver may choose not to report correct values.

setOutputBufferSize

void setOutputBufferSize(int size)
Sets the output buffer size. The driver may choose to ignore this method.

Parameters:
size - in bytes

getOutputBufferSize

int getOutputBufferSize()
Returns:
the output buffer size. The driver may choose not to report correct values.