comm
Class CommPortIdentifier

java.lang.Object
  extended by comm.CommPortIdentifier
All Implemented Interfaces:
CommPortIdentifierInterface

public class CommPortIdentifier
extends java.lang.Object
implements CommPortIdentifierInterface

A handle for obtaining a communications port.

Version:
2.0.3
Author:
Chris Burdess

Method Summary
static void addPortName(java.lang.String portName, int portType, CommDriver driver)
          Adds the specified port name to the list of available ports.
 void addPortOwnershipListener(CommPortOwnershipListener listener)
          Adds the specified listener to the list of ownership listeners for this port.
 java.lang.String getCurrentOwner()
          Returns the current owner of this port.
 java.lang.String getName()
          Returns the port name, typically an OS-dependent hardware label.
static CommPortIdentifier getPortIdentifier(CommPortInterface portInterface)
          Returns the port identifier for the specified port.
static CommPortIdentifierInterface getPortIdentifier(java.lang.String portName)
          Returns the port identifier for the specified name.
static java.util.Enumeration getPortIdentifiers()
          Returns an enumeration of all port identifiers in the system.
 int getPortType()
          Returns the port type, PORT_SERIAL or PORT_PARALLEL.
 boolean isCurrentlyOwned()
          Indicates whether this port is currently owned.
 CommPortInterface open(java.io.FileDescriptor fd)
          Opens this port using a file descriptor.
 CommPortInterface open(java.lang.String appName, int timeout)
          Opens this communications port.
 void removePortOwnershipListener(CommPortOwnershipListener listener)
          Removes the specified listener from the list of ownership listeners for this port.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getPortIdentifiers

public static java.util.Enumeration getPortIdentifiers()
Returns an enumeration of all port identifiers in the system.


getPortIdentifier

public static CommPortIdentifierInterface getPortIdentifier(java.lang.String portName)
                                                     throws NoSuchPortException
Returns the port identifier for the specified name.

Parameters:
portName - the name of the port
Throws:
NoSuchPortException - if the specified port does not exist

getPortIdentifier

public static CommPortIdentifier getPortIdentifier(CommPortInterface portInterface)
                                            throws NoSuchPortException
Returns the port identifier for the specified port.

Parameters:
portInterface - the open port
Throws:
NoSuchPortException - if the specified port is invalid

addPortName

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

Parameters:
portName - the port name
portType - PORT_SERIAL or PORT_PARALLEL
driver - the driver controlling the specified port

getName

public java.lang.String getName()
Returns the port name, typically an OS-dependent hardware label.

Specified by:
getName in interface CommPortIdentifierInterface

getPortType

public int getPortType()
Returns the port type, PORT_SERIAL or PORT_PARALLEL.

Specified by:
getPortType in interface CommPortIdentifierInterface

getCurrentOwner

public java.lang.String getCurrentOwner()
Returns the current owner of this port.

Specified by:
getCurrentOwner in interface CommPortIdentifierInterface

isCurrentlyOwned

public boolean isCurrentlyOwned()
Indicates whether this port is currently owned.

Specified by:
isCurrentlyOwned in interface CommPortIdentifierInterface

open

public CommPortInterface open(java.lang.String appName,
                              int timeout)
                       throws PortInUseException
Opens this communications port. If the port is in use by another application, it will be notified with a PORT_OWNERSHIP_REQUESTED event. If the current owner closes the port, then this method will succeed. Otherwise a PortInUseException will be thrown.

Specified by:
open in interface CommPortIdentifierInterface
Parameters:
appName - the name of the application requesting the port
timeout - number of miliseconds to wait for the port to open
Throws:
PortInUseException

open

public CommPortInterface open(java.io.FileDescriptor fd)
                       throws UnsupportedCommOperationException
Opens this port using a file descriptor.

Specified by:
open in interface CommPortIdentifierInterface
Parameters:
fd - the file descriptor
Throws:
UnsupportedCommOperationException - if the platform does not support this functionality

addPortOwnershipListener

public void addPortOwnershipListener(CommPortOwnershipListener listener)
Adds the specified listener to the list of ownership listeners for this port.

Specified by:
addPortOwnershipListener in interface CommPortIdentifierInterface
Parameters:
listener - the ownership listener to add

removePortOwnershipListener

public void removePortOwnershipListener(CommPortOwnershipListener listener)
Removes the specified listener from the list of ownership listeners for this port.

Specified by:
removePortOwnershipListener in interface CommPortIdentifierInterface
Parameters:
listener - the ownership listener to remove