public abstract class AbstractSerialDriver extends AbstractDriver
| Modifier and Type | Class and Description |
|---|---|
protected class |
AbstractSerialDriver.Available
To catch the asynchronous output, we use a serial event listener.
|
| Modifier and Type | Field and Description |
|---|---|
private static int |
DEFBAUDRATE
The default baudrate to use.
|
private static long |
DEFCLOSETIMEOUT
The default time out.
|
private static int |
DEFDATABIT
The default databits to use.
|
private static int |
DEFFLOWCONTROL
The default flow control.
|
private static int |
DEFINBUFFER
The default value for the buffer size of the output-stream.
|
private static long |
DEFNOTIFYCOOLDOWN
The default notify cool down time out.
|
private static int |
DEFOUTBUFFER
The default value for the buffer size of the output-stream.
|
private static int |
DEFPARITYBIT
The default parity bit to use.
|
private static String |
DEFPORTNAME
The default name of the communications port.
|
private static int |
DEFRECEIVETHRESHOLD
The default receiving threshold, zero is disabled.
|
private static int |
DEFRECEIVETIMEOUT
The default receiving timeout, zero is disabled.
|
private static int |
DEFSTOPBIT
The default stopbits to use.
|
private static int |
DEFTIMEOUT
The default time out.
|
protected InputStream |
inport
The stream to the input from the serial line.
|
private boolean |
isOpen
Gets true once we successfully opened the serial port.
|
static String |
KEY_BAUDRATE
The key to the baud rate.
|
static String |
KEY_CLOSETIMEOUT
The key to the close timeout in ms.
|
static String |
KEY_DATABIT
The key to the number of data bits.
|
static String |
KEY_FLOWCONTROL
The key to the flow control integer mask.
|
static String |
KEY_INBUFFER
The key to the buffer size of the input stream.
|
static String |
KEY_NOTIFYCOOLDOWN
The key to the notify-read timeout in ms.
|
static String |
KEY_OUTBUFFER
The key to the buffer size of the output stream.
|
static String |
KEY_PARITYBIT
The key to the parity bit.
|
static String |
KEY_PORTNAME
Serial communication port the unit attached to.
|
static String |
KEY_RECEIVEFRAMING
The key to the framing byte.
|
static String |
KEY_RECEIVETHRESHOLD
The key to the receive threshold byte number.
|
static String |
KEY_RECEIVETIMEOUT
The key to the receive timeout ms number.
|
static String |
KEY_STOPBIT
The key to the number of stop bits.
|
static String |
KEY_TIMEOUT
The key to the timeout in ms.
|
protected Object |
LOCK
A locking Object to prevent concurrent access to the serial port.
|
private int |
orgbaud
The original baud rate of the serial port.
|
private int |
orgdata
The original data bit number of the serial connection.
|
private int |
orgparity
The original parity bit number of the serial connection.
|
private int |
orgstop
The original stop bit number of the serial connection.
|
protected OutputStream |
outport
The stream to the output of the serial line.
|
private gnu.io.SerialPort |
serial
The instance of the communication port for issuing command.
|
protected static Object |
STATICLOCK
A locking Object to prevent concurrent access to the serial port.
|
KEY_DRIVERNAMEKEY_LISTSEPARATOR, KEY_MAPKEYVALUECHAR, KEY_MAPSEPARATORCONFIG, KEY_CLASS| Modifier | Constructor and Description |
|---|---|
protected |
AbstractSerialDriver(Map<String,String> info)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
close()
Closes the serial port.
|
gnu.io.SerialPortEventListener |
createPortEventListener(int count,
Object notify)
Creates a serial port event listener that listens to this input
port.
|
gnu.io.SerialPortEventListener |
createPortEventListener(Object notify)
Creates a serial port event listener that listens to this input
port.
|
void |
deregisterSoleEventListener()
Deregisters a serial event listener to the underlying serial port.
|
void |
disableEvent(int type)
Disables the specified event for passing to the sole event listener
registered on this serial port.
|
void |
enableEvent(int type)
Enables the specified event for passing to the sole event listener
registered on this serial port.
|
String |
getDriverName()
Returns the name of the server.
|
void |
init()
Initializing means checking if the port is set,
otherwise we fail here before opening.
|
boolean |
isOpen()
Queries if we are already open.
|
boolean |
open()
Initializing the communication port.
|
abstract String |
readString()
Reads a string from the serial line.
|
void |
registerSoleEventListener(gnu.io.SerialPortEventListener sel)
Registers a serial event listener to the underlying serial port.
|
boolean |
resetOriginalParameters()
Resets the original serial port settings.
|
private void |
setEvent(int type,
boolean val)
Sets the specific event type's notification property to the given
boolean value.
|
abstract String |
writeCommand(String cmd)
Writes a command to the serial line and retrieves the coresponding
reply.
|
abstract String |
writeString(String cmd)
Writes a single string to the serial line without waiting/reading of
a response.
|
createDriver, equals, hashCodeaugment, augment, augment, augment, augment, clone, defaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsEnums, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsMap, getAsObject, getAsObject, getProperties, getProperty, has, initProperties, isNew, parseObject, parseObject, reload, reload, removeProperty, requires, rescanned, setObject, setProperties, setProperty, stringProperties, toStringpublic static final String KEY_PORTNAME
public static final String KEY_TIMEOUT
public static final String KEY_CLOSETIMEOUT
public static final String KEY_NOTIFYCOOLDOWN
public static final String KEY_BAUDRATE
public static final String KEY_DATABIT
public static final String KEY_STOPBIT
public static final String KEY_PARITYBIT
public static final String KEY_FLOWCONTROL
public static final String KEY_RECEIVEFRAMING
public static final String KEY_RECEIVETHRESHOLD
public static final String KEY_RECEIVETIMEOUT
public static final String KEY_OUTBUFFER
public static final String KEY_INBUFFER
private static final String DEFPORTNAME
private static final long DEFNOTIFYCOOLDOWN
private static final int DEFTIMEOUT
private static final long DEFCLOSETIMEOUT
private static final int DEFBAUDRATE
private static final int DEFDATABIT
private static final int DEFSTOPBIT
private static final int DEFPARITYBIT
private static final int DEFFLOWCONTROL
private static final int DEFRECEIVETHRESHOLD
private static final int DEFRECEIVETIMEOUT
private static final int DEFOUTBUFFER
private static final int DEFINBUFFER
protected static final Object STATICLOCK
protected final Object LOCK
protected OutputStream outport
protected InputStream inport
private gnu.io.SerialPort serial
private boolean isOpen
private int orgbaud
private int orgdata
private int orgstop
private int orgparity
public void init()
throws InitException
InitExceptionpublic boolean open()
throws IOException
IOExceptionpublic String getDriverName()
AbstractDriver.KEY_DRIVERNAME property.getDriverName in interface DrivergetDriverName in class AbstractDriverpublic boolean isOpen()
public boolean resetOriginalParameters()
public boolean close()
throws IOException
IOExceptionpublic void registerSoleEventListener(gnu.io.SerialPortEventListener sel)
enableEvent(int) method after
registering an event listener to actually pass events to the listener.
Note that the current implementation of the comm-API allows only a single event listener to be registered. Note also that after closing and re-opening of a serial port the listener has to be registered again.
public void deregisterSoleEventListener()
Note that the current implementation of the comm-API allows only a single event listener to be registered. Note also that after closing the serial port the listener is deregistered automatically.
public void enableEvent(int type)
Note that it is implementation depended whether some events are available at all.
disableEvent(int)public void disableEvent(int type)
Note that it is implementation depended whether some events are available at all.
enableEvent(int)private void setEvent(int type,
boolean val)
public abstract String writeCommand(String cmd) throws IOException
IOExceptionpublic abstract String writeString(String cmd) throws IOException
IOExceptionpublic abstract String readString() throws IOException
IOExceptionpublic gnu.io.SerialPortEventListener createPortEventListener(Object notify)
notify - An object that should be notified on the event.public gnu.io.SerialPortEventListener createPortEventListener(int count,
Object notify)
count - The minimum number of bytes that have to be available.notify - An object that should be notified on the event.