gnu.io
Class CommPortIdentifier

java.lang.Object
  extended bygnu.io.CommPortIdentifier

public class CommPortIdentifier
extends java.lang.Object

Communications port management. CommPortIdentifier is the central class for controlling access to communications ports. It includes methods for: - Determining the communications ports made available by the driver. - Opening communications ports for I/O operations. - Determining port ownership. - Resolving port ownership contention. - Managing events that indicate changes in port ownership status. An application first uses methods in CommPortIdentifier to negotiate with the driver to discover which communication ports are available and then select a port for opening. It then uses methods in other classes like CommPort, ParallelPort and SerialPort to communicate through the port.

Author:
juangui TODO To change the template for this generated type comment go to Window - Preferences - Java - Code Style - Code Templates

Field Summary
static java.lang.String[] PORT_NAMES
           
static int PORT_PARALLEL
           
static int PORT_SERIAL
           
static int TOTAL_PORT_NUMBER
           
 
Method Summary
static void addPortName(java.lang.String portName, int portType, CommDriver driver)
          Adds portName to the list of ports.
 void addPortOwnershipListener(CommPortOwnershipListener listener)
           
 java.lang.String getCurrentOwner()
          Returns the owner of the port, that is, the name of the application owning the port.
 java.lang.String getName()
          Returns the name of the port.
static CommPortIdentifier getPortIdentifier(CommPort port)
           
static CommPortIdentifier getPortIdentifier(java.lang.String _portName)
          Obtains a CommPortIdentifier object by using a port name.
static java.util.Enumeration getPortIdentifiers()
          Obtains an enumeration object that contains a CommPortIdentifier object for each port in the system.
 int getPortType()
          Returns the port type
 boolean isCurrentlyOwned()
           
 CommPort open(java.io.FileDescriptor fd)
          Opens the communications port using a FileDescriptor object on platforms that support this technique.
 CommPort open(java.lang.String appname, int timeout)
          Opens the communications port. open obtains exclusive ownership of the port.
 void removePortOwnershipListener(CommPortOwnershipListener listener)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PORT_SERIAL

public static int PORT_SERIAL

PORT_PARALLEL

public static int PORT_PARALLEL

TOTAL_PORT_NUMBER

public static int TOTAL_PORT_NUMBER

PORT_NAMES

public static java.lang.String[] PORT_NAMES
Method Detail

addPortName

public static void addPortName(java.lang.String portName,
                               int portType,
                               CommDriver driver)
Adds portName to the list of ports.

Parameters:
portName - - The name of the port being added
portType - - The type of the port being added
driver - - The driver representing the port being added

addPortOwnershipListener

public void addPortOwnershipListener(CommPortOwnershipListener listener)

getCurrentOwner

public java.lang.String getCurrentOwner()
Returns the owner of the port, that is, the name of the application owning the port.

Returns:
current owner of the port.

getName

public java.lang.String getName()
Returns the name of the port. The port name should be identifiable by the user. Ideally, it should be the label on the hardware. For example, "COM1" and "COM2" on PCs; "Serial A" and "Serial B" on Sun Ultra workstations. The port name may be stored by an application and subsequently used to create a CommPortIdentifier object using getPortIdentifier(String portName) method.

Returns:

getPortIdentifier

public static CommPortIdentifier getPortIdentifier(CommPort port)
                                            throws NoSuchPortException
Throws:
NoSuchPortException

getPortIdentifier

public static CommPortIdentifier getPortIdentifier(java.lang.String _portName)
                                            throws NoSuchPortException
Obtains a CommPortIdentifier object by using a port name. The port name may have been stored in persistent storage by the application.

Parameters:
_portName - - name of the port to open
Returns:
a CommPortIdentifier object
Throws:
NoSuchPortException - - if the port does not exist

getPortIdentifiers

public static java.util.Enumeration getPortIdentifiers()
Obtains an enumeration object that contains a CommPortIdentifier object for each port in the system.

Returns:

getPortType

public int getPortType()
Returns the port type

Returns:
- PORT_SERIAL or PORT_PARALLEL

isCurrentlyOwned

public boolean isCurrentlyOwned()

open

public CommPort open(java.io.FileDescriptor fd)
              throws UnsupportedCommOperationException
Opens the communications port using a FileDescriptor object on platforms that support this technique.

Parameters:
fd - - The FileDescriptor object used to build a CommPort.
Returns:
a CommPort object.
Throws:
UnsupportedCommOperationException - - is thrown on platforms which do not support this functionality.

open

public CommPort open(java.lang.String appname,
                     int timeout)
              throws PortInUseException
Opens the communications port. open obtains exclusive ownership of the port. If the port is owned by some other application, a PORT_OWNERSHIP_REQUESTED event is propagated using the CommPortOwnershipListener event mechanism. If the application that owns the port calls close during the event processing, then this open will succeed. There is one InputStream and one OutputStream associated with each port. After a port is opened with open, then all calls to getInputStream will return the same stream object until close is called.

Parameters:
appname - - Name of application making this call. This name will become the owner of the port. Useful when resolving ownership contention.
timeout - - time in milliseconds to block waiting for port open.
Returns:
a CommPort object
Throws:
PortInUseException - - if the port is in use by some other application that is not willing to relinquish ownership

removePortOwnershipListener

public void removePortOwnershipListener(CommPortOwnershipListener listener)