stella.io
Class RS485Configurator

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 stella.io.RS485Server
                          extended by stella.io.RS485Configurator
All Implemented Interfaces:
Driver, Cloneable, ExitCleaning, Initializable, LocalizedSupplying, PropertySupplying, ResourceSupplying
Direct Known Subclasses:
JRS485Config

public class RS485Configurator
extends RS485Server

A command-line tool for setting the configuration of a serial I/O module. This is a very generic class. It uses the properties handed over at the construction phase to derive the available commands. Note that the command line tool is not ment ot be sophisticated. In particular, the baud rate is not set by giving the baud rate explicetly, but merely by adding the appropriate baud-rate code.

In most cases you will use the graphical tool that comes with the configurator:

See Also:
JRS485Config

Nested Class Summary
 
Nested classes/interfaces inherited from class stella.io.RS485Server
RS485Server.Checksum, RS485Server.Command, RS485Server.Info, RS485Server.Scan
 
Nested classes/interfaces inherited from class io.AbstractSerialDriver
AbstractSerialDriver.Available
 
Nested classes/interfaces inherited from class util.PropertyResources
PropertyResources.URLResource
 
Field Summary
protected static String ADDRESSFILL
          The address fill-in String ("**").
private static TreeMap CODETOBAUD
          A hash map matching baud codes to baud rates.
private static String DEFADDRESS
          The default address of the module (00).
private static TreeMap INPUTTOVOLT
          A hash map matching input ranges to volts.
static String KEY_ADDRESS
          The key linked to the hexadecimal address of the module.
protected static String LEADCHAR
          The command characterizing leading char ("-").
private  HashMap no
          Matching no-parameter commands to command lines.
private  HashMap one
          Matching one-parameter commands to command lines.
private  String orgconf
          The original configuration read in at port opening.
protected static String[] RESERVED
          The default keyword recognized.
static String SIMPLE_COMMAND
          A key starting with this prefix is linked to a no-parameter command.
static String SINGLE_COMMAND
          Keys starting with this prefix are single-parameter commands.
 
Fields inherited from class stella.io.RS485Server
KEY_CHECKCHAR, KEY_CHECKSUM, KEY_CLOSE, KEY_CR, KEY_ECHO, KEY_FAILTIME, KEY_FAILURES, KEY_INVALID, KEY_MAXBUFFER, KEY_MAXBUSY, KEY_QUERYTIME, KEY_REINIT, KEY_RESPONDTIME, KEY_STARTUP, KEY_TIMEBUSY, 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
RS485Configurator(Map prop)
          Constructs a new RS485Configurator.
 
Method Summary
 String getAddressFromReply()
          Return the code segment of the reply after readstatus defining the return address.
 Set getAllBaudCodes()
          Returns all baud codes as a set.
 Set getAllRangeCodes()
          Returns all input ranges as a set.
 Set getAllSimple()
          Returns the command names for all non-parameter commands as a set.
 Set getAllSingle()
          Returns the command names for all one-parameter commands as a set.
 String getBaudFromCode(String baudcode)
          Converts the baud 2-character code into the actual bitrate.
 String getBaudFromReply()
          Return the code segment of the reply after readstatus defining the baud rate.
 String getChecksumCodeFromFlag(boolean flag)
          Returns the value of the checksumming code as a function as the checksum flag.
 boolean getChecksumFlagFromCode(String code)
          Returns the value of the checksumming flag out of the checksumming code.
 String getChecksumFromReply()
          Return the code segment of the reply after readstatus defining the checksum flag.
 String getCodeFromBaud(String baud)
          Converts the baud rate, given as an integer, to the baud-rate code.
 String getCodeFromRange(String volt)
          Converts a descriptive input range into the code to send to the module.
private static String getCodeFromValue(String value, Map target)
          Returns the key asociated with a certain value in the given map.
 String getRangeFromCode(String code)
          Converts the two-character input range code into a more descriptive input range.
 String getTypeFromReply()
          Return the code segment of the reply after readstatus defining the module type.
static void main(String[] arg)
          Sends a configuration command to the serial port.
private  void readConf()
          Reads the currecnt configuration.
private  String replace(String which)
           
 boolean sendCommandLine(String line)
          Sends the command line to the serial port.
protected  boolean sendConfigCommand(String oldadd, String newadd, String code, String baud, String checkflag)
          Sends the main configure command to the serial port.
protected  boolean sendReserved(String type, String arg)
          Writes one of the reserved commands.
 boolean setOpen()
          Opens the serial port.
 
Methods inherited from class stella.io.RS485Server
deferCommand, ensureCommand, exit, getCheckSum, getCheckSumming, isReading, open, readString, setCheckSumming, toString, writeCommand, writeString
 
Methods inherited from class io.AbstractSerialDriver
close, 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
 
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

SIMPLE_COMMAND

public static final String SIMPLE_COMMAND
A key starting with this prefix is linked to a no-parameter command.

See Also:
Constant Field Values

SINGLE_COMMAND

public static final String SINGLE_COMMAND
Keys starting with this prefix are single-parameter commands.

See Also:
Constant Field Values

KEY_ADDRESS

public static final String KEY_ADDRESS
The key linked to the hexadecimal address of the module.

See Also:
Constant Field Values

RESERVED

protected static final String[] RESERVED
The default keyword recognized. Require an obscure command schema.


DEFADDRESS

private static final String DEFADDRESS
The default address of the module (00).

See Also:
Constant Field Values

LEADCHAR

protected static final String LEADCHAR
The command characterizing leading char ("-").

See Also:
Constant Field Values

ADDRESSFILL

protected static final String ADDRESSFILL
The address fill-in String ("**").

See Also:
Constant Field Values

no

private HashMap no
Matching no-parameter commands to command lines.


one

private HashMap one
Matching one-parameter commands to command lines.


orgconf

private String orgconf
The original configuration read in at port opening.


INPUTTOVOLT

private static final TreeMap INPUTTOVOLT
A hash map matching input ranges to volts.


CODETOBAUD

private static final TreeMap CODETOBAUD
A hash map matching baud codes to baud rates.

Constructor Detail

RS485Configurator

public RS485Configurator(Map prop)
Constructs a new RS485Configurator. The properties are scanned for none, single and two-parameter commands. All keys found in the properties starting with the appropriate prefix are stored into individual look-up tables.

Method Detail

setOpen

public boolean setOpen()
                throws IOException
Opens the serial port. input and output streams are definitely opened. Before the first command is sent, the configuration is read in and stored.

Throws:
IOException

readConf

private void readConf()
               throws IOException
Reads the currecnt configuration. Comprises address, baud rate and checksum setting.

Throws:
IOException

sendCommandLine

public boolean sendCommandLine(String line)
                        throws IOException
Sends the command line to the serial port. The command is the first string token found and must start with a LEADCHAR. First, the reserved command names are scanned. If no match is found the no-parameter commands are scanned. Again if no match is found the one-parameter commands are scanned. If no match is found at all false is returned.

When a match is found the appropriate command is constructed and sent to the serial server. The command is constructed in an obscure way if the command is one of the reserved words. For no-parameter commands, the appropriate value found in the no-parameter look-up table is sent. One parameter commands are augmented with whatever is found after the command name in the command line. No response is read in.

Throws:
IOException

replace

private String replace(String which)

sendReserved

protected boolean sendReserved(String type,
                               String arg)
                        throws IOException
Writes one of the reserved commands. Only the address is changed in the properties.

Throws:
IOException

sendConfigCommand

protected boolean sendConfigCommand(String oldadd,
                                    String newadd,
                                    String code,
                                    String baud,
                                    String checkflag)
                             throws IOException
Sends the main configure command to the serial port. The old and new address, the baud rate and the state of the checksumming flag must already be coded in a serial-port understandable format. The KEY_ADDRESS property is set to the new value but baud rate and checksumming is left unchanged. After the string has been sent, the configuration is read in again with a call to readConf().

Throws:
IOException

getAddressFromReply

public String getAddressFromReply()
Return the code segment of the reply after readstatus defining the return address.


getTypeFromReply

public String getTypeFromReply()
Return the code segment of the reply after readstatus defining the module type.


getBaudFromReply

public String getBaudFromReply()
Return the code segment of the reply after readstatus defining the baud rate.


getChecksumFromReply

public String getChecksumFromReply()
Return the code segment of the reply after readstatus defining the checksum flag.


getBaudFromCode

public String getBaudFromCode(String baudcode)
Converts the baud 2-character code into the actual bitrate. If the code cannot be converted into a baudrate, the default setting is returned.

Implementation note: the code-to-baud rate is hard-coded into the program.


getCodeFromBaud

public String getCodeFromBaud(String baud)
Converts the baud rate, given as an integer, to the baud-rate code.


getRangeFromCode

public String getRangeFromCode(String code)
Converts the two-character input range code into a more descriptive input range.


getCodeFromRange

public String getCodeFromRange(String volt)
Converts a descriptive input range into the code to send to the module.


getAllBaudCodes

public Set getAllBaudCodes()
Returns all baud codes as a set.


getAllRangeCodes

public Set getAllRangeCodes()
Returns all input ranges as a set.


getAllSimple

public Set getAllSimple()
Returns the command names for all non-parameter commands as a set.


getAllSingle

public Set getAllSingle()
Returns the command names for all one-parameter commands as a set.


getChecksumFlagFromCode

public boolean getChecksumFlagFromCode(String code)
Returns the value of the checksumming flag out of the checksumming code. The code must be a two-digit hex string.


getChecksumCodeFromFlag

public String getChecksumCodeFromFlag(boolean flag)
Returns the value of the checksumming code as a function as the checksum flag.


getCodeFromValue

private static final String getCodeFromValue(String value,
                                             Map target)
Returns the key asociated with a certain value in the given map.


main

public static void main(String[] arg)
                 throws IOException
Sends a configuration command to the serial port. The command line must take the properties as the first argument, then the command to send with a trailing "-". Additional parameters are entered as a single string after the command.

Throws:
IOException