io
Class SerialDriver

java.lang.Object
  extended by util.PropertyContainer
      extended by util.PropertyResources
          extended by util.PropertyBundles
              extended by io.AbstractDriver
                  extended by io.AbstractSerialDriver
                      extended by io.SerialDriver
All Implemented Interfaces:
Driver, Cloneable, ExitCleaning, Initializable, LocalizedSupplying, PropertySupplying, ResourceSupplying
Direct Known Subclasses:
CalibUnit

public class SerialDriver
extends AbstractSerialDriver
implements ExitCleaning

A simple serial driver for use in stella.calib.CalibUnit and MotorController


Nested Class Summary
static class SerialDriver.Debug
          Reads the properties from a file, open the port and writes a command to it.
static class SerialDriver.Scan
          Scans the comunication busses for available ports.
 
Nested classes/interfaces inherited from class io.AbstractSerialDriver
AbstractSerialDriver.Available
 
Nested classes/interfaces inherited from class util.PropertyResources
PropertyResources.URLResource
 
Field Summary
private static long DEFDELAY
          The default reading delay in ms.
private static long DEFRWCOOLDOWN
          The default reading delay in ms.
private static boolean DEFSTATICLOCK
          The default locking behaviour.
private  BufferedReader input
          Wrapped around the input stream.
static String KEY_DELAY
          The key to the reading delay in msec.
static String KEY_RWCOOLDOWN
          The key to the reading cooldown in msec.
static String KEY_STATICLOCK
          If true, we lock on the static lock.
 
Fields inherited from class io.AbstractSerialDriver
inport, KEY_BAUDRATE, KEY_CLOSETIMEOUT, KEY_DATABIT, KEY_FLOWCONTROL, KEY_INBUFFER, KEY_NOTIFYCOOLDOWN, KEY_OUTBUFFER, KEY_PARITYBIT, KEY_PORTNAME, KEY_RECEIVEFRAMING, KEY_RECEIVETHRESHOLD, KEY_RECEIVETIMEOUT, KEY_STOPBIT, KEY_TIMEOUT, outport, staticlock
 
Fields inherited from class io.AbstractDriver
KEY_DRIVERNAME
 
Fields inherited from class util.PropertyBundles
KEY_LOCALECOUNTRY, KEY_LOCALELANGUAGE, KEY_RESOURCEBUNDLES
 
Fields inherited from class util.PropertyResources
KEY_NOINITONCREATE, localurl, locate, POSTFIX_DIR, POSTFIX_EXT, POSTFIX_FILE, POSTFIX_LIST, POSTFIX_URL, urlset
 
Fields inherited from class util.PropertyContainer
KEY_LISTSEPARATOR, KEY_MAPKEYVALUECHAR, KEY_MAPSEPARATOR
 
Fields inherited from interface util.ResourceSupplying
KEY_URLRESOURCES, KEY_URLUSECONFIG, KEY_URLUSECURRENT, KEY_URLUSEHOME
 
Fields inherited from interface util.PropertySupplying
CONFIG, KEY_CLASS
 
Constructor Summary
SerialDriver(Map info)
          Constructor.
 
Method Summary
 boolean close()
          Additionally closes the input buffered reader.
private  String doReadWriteCycle(String cmd)
          Does a clear-line, write command, read-line cycle.
 void exit()
          Closes the port.
 boolean open()
          Initializes the serial port and wraps a buffered reader around the input stream.
 String readString()
          Reads a string from the serial line.
protected  String readString(long timeout)
          Get the response from the controller.
 String writeCommand(String cmd)
          Writes a command and returns the result.
 String writeString(String cmd)
          Writes a string to the serial port.
 
Methods inherited from class io.AbstractSerialDriver
createPortEventListener, createPortEventListener, deregisterSoleEventListener, disableEvent, enableEvent, getDriverName, isOpen, registerSoleEventListener, resetOriginalParameters
 
Methods inherited from class io.AbstractDriver
createDriver, equals, hashCode
 
Methods inherited from class util.PropertyBundles
clone, getLocalized, getLocalized, getLocalizedString, getLocalizedString, loadResource
 
Methods inherited from class util.PropertyResources
createFrom, createFrom, createFrom, getApplet, getAsResources, getLocalClassLoader, getPropertiesToKey, getPropertiesToKey, getResource, getResourceAsStream, getResourceFromKey, getResources, init, keyCreate, keyCreate, reload, setApplet
 
Methods inherited from class util.PropertyContainer
augment, augment, augment, 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, isNew, parseObject, reload, removeProperty, rescanned, setObject, setProperties, setProperty, stringProperties, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface util.ResourceSupplying
getResource, getResourceAsStream, getResources
 
Methods inherited from interface util.PropertySupplying
defaultBoolean, defaultChar, defaultDouble, defaultFloat, defaultInt, defaultLong, defaultObject, defaultObject, defaultProperties, defaultProperty, getAsBoolean, getAsChar, getAsDouble, getAsFloat, getAsInt, getAsList, getAsLong, getAsMap, getAsObject, getAsObject, getProperties, getProperty, has, parseObject, removeProperty, setObject, setProperty, stringProperties
 
Methods inherited from interface util.Initializable
init
 

Field Detail

KEY_STATICLOCK

public static final String KEY_STATICLOCK
If true, we lock on the static lock. Prevents any other serial acc.

See Also:
Constant Field Values

KEY_DELAY

public static final String KEY_DELAY
The key to the reading delay in msec.

See Also:
Constant Field Values

KEY_RWCOOLDOWN

public static final String KEY_RWCOOLDOWN
The key to the reading cooldown in msec.

See Also:
Constant Field Values

DEFSTATICLOCK

private static final boolean DEFSTATICLOCK
The default locking behaviour.

See Also:
Constant Field Values

DEFDELAY

private static final long DEFDELAY
The default reading delay in ms.

See Also:
Constant Field Values

DEFRWCOOLDOWN

private static final long DEFRWCOOLDOWN
The default reading delay in ms.

See Also:
Constant Field Values

input

private BufferedReader input
Wrapped around the input stream.

Constructor Detail

SerialDriver

public SerialDriver(Map info)
Constructor. Opening of the serial port is delayed until init. Here only properties are read.

Method Detail

open

public boolean open()
             throws IOException
Initializes the serial port and wraps a buffered reader around the input stream.

Specified by:
open in interface Driver
Overrides:
open in class AbstractSerialDriver
Returns:
True if initialization was successful.
Throws:
IOException

exit

public void exit()
Closes the port.

Specified by:
exit in interface ExitCleaning

writeString

public String writeString(String cmd)
                   throws IOException
Writes a string to the serial port. No sync etc.

Specified by:
writeString in class AbstractSerialDriver
Returns:
The string as it was truely sent to the line, including LF etc.
Throws:
IOException

readString

public String readString()
                  throws IOException
Reads a string from the serial line. The string is terminated with a newline.

Specified by:
readString in class AbstractSerialDriver
Throws:
IOException

writeCommand

public String writeCommand(String cmd)
                    throws IOException
Writes a command and returns the result. Locks on the static lock before writing, if KEY_STATICLOCK is true, otherwise we lock on this. Releases the lock after reading.

Specified by:
writeCommand in class AbstractSerialDriver
Throws:
IOException

doReadWriteCycle

private String doReadWriteCycle(String cmd)
                         throws IOException
Does a clear-line, write command, read-line cycle.

Throws:
IOException

close

public boolean close()
              throws IOException
Additionally closes the input buffered reader.

Specified by:
close in interface Driver
Overrides:
close in class AbstractSerialDriver
Returns:
True if clean-up was successful.
Throws:
IOException

readString

protected String readString(long timeout)
                     throws IOException
Get the response from the controller.

Parameters:
timeout - Maximum time the program should wait for the controller's response in ms. It is useful to set it if response is expected with some delay from the controller.
Returns:
String containing the controllers response.
Throws:
IOException