public interface ModemConnection extends CommConnection
Abstraction of a modem interface which allows to monitor and control the
signal lines on a serial interface. The ModemConnection
is usually either
a data terminal equipment (DTE) or a data communication equipment (DCE) (modem)
but combinations of these roles may exist.
If a CommConnection supports control of the modem lines,
a call to Connector.open
with the protocol scheme defined by CommConnection
must return a ModemConnection
.
The ModemConnection
defines additional signal lines for communicating device states.
These are Data Terminal Ready (DTR), Data Set Ready (DSR),
Data Carrier Detect (DCD) and Ring Indicator (RING).
If the ModemConnection is associated with a modem (DCE), the DCD, DSR and RING
lines are output lines and DTR is an input line. If it is a DTE,
the DCD, DSR and RING lines are input lines and DTR is an output line.
Note that a modem connection may combine the DCE and DTE roles and that
the specific set of input and output lines of a device is implementation dependent.
Any attempt of setting the state of a signal line in input mode results in an IOException
.
CommConnection cc = null; try { cc = (CommConnection) Connector.open("comm:com0;baudrate=19200"); // are we a ModemConnection that allows to control these lines ? if (cc instanceof ModemConnection) { ModemConnection mc = (ModemConnection) cc; // Create a listener for changes to the RI signal mc.addListener(new ModemListener() { public void signalChanged(ModemConnection mc, int signalLine, boolean signalState) { System.out.println ("New state on RI Signal line:"+signalState); } }, ModemConnection.RI_SIGNAL); // Set the DTR line mc.setLineState(ModemConnection.DTR_SIGNAL, true); ... }; ... cc.close(); } catch (IOException e) { e.printStackTrace(); } }
Modifier and Type | Field and Description |
---|---|
static int |
DCD_SIGNAL
Data Carrier Detect (DCD)
|
static int |
DSR_SIGNAL
Data Set Ready (DSR)
|
static int |
DTR_SIGNAL
Data Terminal Ready (DTR)
|
static int |
INPUT_MODE
Signal line is in input mode.
|
static int |
OUTPUT_MODE
Signal line is in output mode.
|
static int |
RI_SIGNAL
Ring Indicator (RING)
|
static int |
UNSUPPORTED
Signal line is not supported.
|
Modifier and Type | Method and Description |
---|---|
void |
addListener(ModemListener listener,
int signalLine)
Register a listener to receive state changes of a modem signal line.
|
int |
getLineMode(int signalLine)
Query whether a signal line is supported by the implementation and whether
it is in input mode or output mode.
|
boolean |
getLineState(int signalLine)
Return the state of the signal line of the serial port.
|
void |
removeListener(ModemListener listener)
Remove a listener.
|
void |
setLineState(int signalLine,
boolean signalState)
Set the state of the signal line of the serial port.
|
getBaudRate, setBaudRate
openDataInputStream, openInputStream
openDataOutputStream, openOutputStream
close
static final int DCD_SIGNAL
static final int DSR_SIGNAL
static final int DTR_SIGNAL
static final int INPUT_MODE
static final int OUTPUT_MODE
static final int RI_SIGNAL
static final int UNSUPPORTED
void addListener(ModemListener listener, int signalLine)
Register a listener to receive state changes of a modem signal line. The listener is called on each state change of the related signal line on the serial port. Multiple listeners may be registered for a connection, their calling sequence is implementation dependent.
The signalLine
must be one of DTR_SIGNAL
,
DCD_SIGNAL
, DSR_SIGNAL
or RI_SIGNAL
.
listener
- an instance of a ModemListenersignalLine
- signal line to be observedjava.lang.NullPointerException
- if the listener is nulljava.lang.IllegalArgumentException
- if the signal line is not in input mode
or not one of DTR_SIGNAL, DCD_SIGNAL, DSR_SIGNAL or RI_SIGNALremoveListener(ModemListener)
int getLineMode(int signalLine)
signalLine
- signal line to be queriedjava.lang.IllegalArgumentException
- if the signalLine
is not one of DTR_SIGNAL, DCD_SIGNAL, DSR_SIGNAL or RI_SIGNAL.boolean getLineState(int signalLine) throws java.io.IOException
signalLine
must be one of DTR_SIGNAL
,
DCD_SIGNAL
, DSR_SIGNAL
or RI_SIGNAL
.signalLine
- signal line to be observedjava.lang.IllegalArgumentException
- if the signalLine
is not one of DTR_SIGNAL, DCD_SIGNAL, DSR_SIGNAL or RI_SIGNAL.java.io.IOException
- if the state cannot be read.setLineState(int, boolean)
void removeListener(ModemListener listener)
listener
- an instance of a ModemListener that was previously registeredjava.lang.NullPointerException
- if the listener is nulljava.lang.IllegalArgumentException
- if the listener was not previously
registered to this ModemConnectionvoid setLineState(int signalLine, boolean signalState) throws java.io.IOException
signalLine
must be one of DTR_SIGNAL
,
DCD_SIGNAL
, DSR_SIGNAL
or RI_SIGNAL
.signalLine
- signal line to be changedsignalState
- the new state of the signal linejava.lang.IllegalArgumentException
- if the signalLine
is not one of DTR_SIGNAL, DCD_SIGNAL, DSR_SIGNAL or RI_SIGNAL.java.io.IOException
- if the state cannot be set.getLineState(int)
Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. Use of this specification is subject to license terms.