|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavax.comm.CommPortIdentifier
Communications port management. CommPortIdentifier
is the central class for controlling access to communications ports.
It includes methods for:
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.
CommPort
,
CommPortOwnershipListener
,
ParallelPort
,
SerialPort
Field Summary | |
static int |
PORT_PARALLEL
|
static int |
PORT_SERIAL
|
Constructor Summary | |
CommPortIdentifier(java.lang.String name,
CommPort port,
int type,
CommDriver driver)
Constructor |
Method Summary | |
static void |
addPortName(java.lang.String portName,
int portType,
CommDriver driver)
Adds portName to the list of ports. |
void |
addPortOwnershipListener(CommPortOwnershipListener listener)
Registers an interested application so that it can receive notification of changes in port ownership. |
java.lang.String |
getCurrentOwner()
Returns the owner of the port. |
java.lang.String |
getName()
Returns the name of the port. |
static CommPortIdentifier |
getPortIdentifier(CommPort port)
Obtains the CommPortIdentifier object corresponding
to a port that has already been opened by the application. |
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()
Checks whether the port is owned. |
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. |
void |
removePortOwnershipListener(CommPortOwnershipListener listener)
Deregisters a CommPortOwnershipListener registered using
addPortOwnershipListener |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int PORT_SERIAL
public static final int PORT_PARALLEL
Constructor Detail |
public CommPortIdentifier(java.lang.String name, CommPort port, int type, CommDriver driver)
name
- Name to give this portport
- Instantiaton of CommPort implementationtype
- PORT_SERIAL or PORT_PARALLELdriver
- Driver assosciated with this port.CommPortIdentifier
Method Detail |
public static java.util.Enumeration getPortIdentifiers()
CommPortIdentifier
object for each port in the system.
Enumeration
that can be used to
enumerate all the ports known to the systempublic static CommPortIdentifier getPortIdentifier(java.lang.String portName) throws NoSuchPortException
CommPortIdentifier
object by using a port name.
The port name may have been stored in persistent storage by the application.
portName
- name of the port to open
CommPortIdentifier
object
NoSuchPortException
- if the port does not existpublic static CommPortIdentifier getPortIdentifier(CommPort port) throws NoSuchPortException
CommPortIdentifier
object corresponding
to a port that has already been opened by the application.
port
- a CommPort object obtained from a previous open
CommPortIdentifier
object
NoSuchPortException
- if the port object is invalidpublic static void addPortName(java.lang.String portName, int portType, CommDriver driver)
portName
to the list of ports.
portName
- The name of the port being addedportType
- The type of the port being addeddriver
- The driver representing the port being addedCommDriver
public CommPort open(java.lang.String appname, int timeout) throws PortInUseException
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.
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.
CommPort
object
PortInUseException
- if the port is in use by some other
application that is not willing to relinquish ownershippublic CommPort open(java.io.FileDescriptor fd) throws UnsupportedCommOperationException
FileDescriptor
object on platforms that support this technique.
fd
- The FileDescriptor
associated with this CommPort.
CommPort
object.
UnsupportedCommOperationException
- on platforms
which do not support this functionality.public java.lang.String getName()
public int getPortType()
public java.lang.String getCurrentOwner()
public boolean isCurrentlyOwned()
true
if port is owned by an application,
false
if port is not owned.public void addPortOwnershipListener(CommPortOwnershipListener listener)
PORT_OWNED
: Port became owned
PORT_UNOWNED
: Port became unowned
PORT_OWNERSHIP_REQUESTED
If the application owns this port and is willing to give up ownership,
then it should call close
now.
ownershipChange
method of the listener registered
using addPortOwnershipListener
will be called with one
of the above events.
listener
- CommPortOwnershipListener
callback objectpublic void removePortOwnershipListener(CommPortOwnershipListener listener)
CommPortOwnershipListener
registered using
addPortOwnershipListener
listener
- The CommPortOwnershipListener object that was
previously registered using addPortOwnershipListener
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |