|
comm API Version 2.0 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
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
IEEE 1284 parallel port |
static int |
PORT_SERIAL
RS-232 serial port |
Method Summary | |
static void |
addPortName(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. |
String |
getCurrentOwner()
Returns the owner of the port. |
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(String portName)
Obtains a CommPortIdentifier object by using a port name.
|
static 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(FileDescriptor fd)
Opens the communications port using a FileDescriptor
object on platforms that support this technique. |
CommPort |
open(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
Method Detail |
public static Enumeration getPortIdentifiers()
CommPortIdentifier
object for each port in the system.
Enumeration
object that can be used to
enumerate all the ports known to the systemEnumeration
public static CommPortIdentifier getPortIdentifier(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(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 String getName()
CommPortIdentifier
object using getPortIdentifier(String portName)
method.
public int getPortType()
PORT_SERIAL
or PORT_PARALLEL
public String getCurrentOwner()
public boolean isCurrentlyOwned()
true
if the port is owned by some application,
false
if the port is not owned.public CommPort open(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(FileDescriptor fd) throws UnsupportedCommOperationException
FileDescriptor
object on platforms that support this technique.
fd
- The FileDescriptor
object used to build
a CommPort
.
CommPort
object.
UnsupportedCommOperationException
- is thrown on platforms
which do not support this functionality.public void addPortOwnershipListener(CommPortOwnershipListener listener)
PORT_OWNED
: Port became ownedPORT_UNOWNED
: Port became unownedPORT_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
- a CommPortOwnershipListener
callback objectpublic void removePortOwnershipListener(CommPortOwnershipListener listener)
CommPortOwnershipListener
registered using
addPortOwnershipListener
listener
- The CommPortOwnershipListener object that was
previously registered using addPortOwnershipListener
|
comm API Version 2.0 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |