jmri.jmrix
Class AbstractPortController

java.lang.Object
  extended by jmri.jmrix.AbstractPortController
All Implemented Interfaces:
PortAdapter, SerialPortAdapter
Direct Known Subclasses:
AcelaPortController, EasyDccPortController, EcosPortController, GcPortController, LnPortController, MrcPortController, Mx1PortController, NcePortController, Port, PortController, PortController, QsiPortController, SerialAdapter, SerialPortController, SerialPortController, SerialPortController, SerialPortController, SerialPortController, SerialPortController, SerialPortController, SerialSensorAdapter, SprogPortController, SRCPPortController, XNetPortController, XpaPortController

public abstract class AbstractPortController
extends Object
implements SerialPortAdapter

Provide an abstract base for *PortController classes.

This is complicated by the lack of multiple inheritance. SerialPortAdapter is an Interface, and it's implementing classes also inherit from various PortController types. But we want some common behaviours for those, so we put them here.

Author:
Bob Jacobsen Copyright (C) 2001, 2002
See Also:
SerialPortAdapter

Field Summary
protected static org.apache.log4j.Category log
           
protected  String mBaudRate
           
protected  String mOpt1
           
protected  String mOpt2
           
protected  String mPort
           
 
Constructor Summary
AbstractPortController()
           
 
Method Summary
 void configureBaudRate(String rate)
          Set the baud rate.
 void configureOption1(String value)
          Set the second port option.
 void configureOption2(String value)
          Set the second port option.
 int currentBaudNumber(String currentBaudRate)
          Convert a baud rate string to a number.
 String getCurrentBaudRate()
           
 String getCurrentOption1Setting()
           
 String getCurrentOption2Setting()
          Get current option 2 value
 String getCurrentPortName()
           
abstract  DataInputStream getInputStream()
           
abstract  DataOutputStream getOutputStream()
           
 String handlePortBusy(javax.comm.PortInUseException p, String portName, org.apache.log4j.Category log)
          Standard error handling for port-busy case
 String handlePortNotFound(javax.comm.NoSuchPortException p, String portName, org.apache.log4j.Category log)
          Standard error handling for port-not-found case
 String option1Name()
          Get a String that says what Option 1 represents May be an empty string, but will not be null
 String option2Name()
          Get a String that says what Option 2 represents May be an empty string, but will not be null
 void setPort(String port)
          Remember the associated port name
abstract  boolean status()
          Query the status of this connection.
 int[] validBaudNumber()
          Get an array of valid baud rates as integers.
 String[] validOption1()
          Get an array of valid values for "option 1"; used to display valid options.
 String[] validOption2()
          Get an array of valid values for "option 2"; used to display valid options.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface jmri.jmrix.SerialPortAdapter
configure, getPortNames, openPort, validBaudRates
 

Field Detail

mPort

protected String mPort

mBaudRate

protected String mBaudRate

mOpt1

protected String mOpt1

mOpt2

protected String mOpt2

log

protected static org.apache.log4j.Category log
Constructor Detail

AbstractPortController

public AbstractPortController()
Method Detail

getInputStream

public abstract DataInputStream getInputStream()

getOutputStream

public abstract DataOutputStream getOutputStream()

status

public abstract boolean status()
Description copied from interface: PortAdapter
Query the status of this connection. If all OK, at least as far as is known, return true

Specified by:
status in interface PortAdapter
Specified by:
status in interface SerialPortAdapter

handlePortBusy

public String handlePortBusy(javax.comm.PortInUseException p,
                             String portName,
                             org.apache.log4j.Category log)
Standard error handling for port-busy case

Specified by:
handlePortBusy in interface SerialPortAdapter
See Also:
AbstractPortController

handlePortNotFound

public String handlePortNotFound(javax.comm.NoSuchPortException p,
                                 String portName,
                                 org.apache.log4j.Category log)
Standard error handling for port-not-found case


setPort

public void setPort(String port)
Description copied from interface: SerialPortAdapter
Remember the associated port name

Specified by:
setPort in interface SerialPortAdapter

getCurrentPortName

public String getCurrentPortName()
Specified by:
getCurrentPortName in interface SerialPortAdapter

configureBaudRate

public void configureBaudRate(String rate)
Set the baud rate. This records it for later.

Specified by:
configureBaudRate in interface SerialPortAdapter

getCurrentBaudRate

public String getCurrentBaudRate()
Specified by:
getCurrentBaudRate in interface SerialPortAdapter

validBaudNumber

public int[] validBaudNumber()
Get an array of valid baud rates as integers. This allows subclasses to change the arrays of speeds. This method need not be reimplemented unless the subclass is using currentBaudNumber, which requires it.


currentBaudNumber

public int currentBaudNumber(String currentBaudRate)
Convert a baud rate string to a number. Uses the validBaudNumber and validBaudRates methods to do this.

Returns:
-1 if no match (configuration system should prevent this)

validOption1

public String[] validOption1()
Get an array of valid values for "option 1"; used to display valid options. May not be null, but may have zero entries

Specified by:
validOption1 in interface SerialPortAdapter

option1Name

public String option1Name()
Get a String that says what Option 1 represents May be an empty string, but will not be null

Specified by:
option1Name in interface SerialPortAdapter

configureOption1

public void configureOption1(String value)
Set the second port option.

Specified by:
configureOption1 in interface SerialPortAdapter

getCurrentOption1Setting

public String getCurrentOption1Setting()
Specified by:
getCurrentOption1Setting in interface SerialPortAdapter

validOption2

public String[] validOption2()
Get an array of valid values for "option 2"; used to display valid options. May not be null, but may have zero entries

Specified by:
validOption2 in interface SerialPortAdapter

option2Name

public String option2Name()
Get a String that says what Option 2 represents May be an empty string, but will not be null

Specified by:
option2Name in interface SerialPortAdapter

configureOption2

public void configureOption2(String value)
Set the second port option.

Specified by:
configureOption2 in interface SerialPortAdapter

getCurrentOption2Setting

public String getCurrentOption2Setting()
Description copied from interface: SerialPortAdapter
Get current option 2 value

Specified by:
getCurrentOption2Setting in interface SerialPortAdapter


Copyright © 1997 - 2008 JMRI Community.
JMRI, DecoderPro, PanelPro, SoundPro, DispatcherPro and associated logos are our trademarks.

Additional information on copyright, trademarks and licenses is linked here.
Site hosted by: SourceForge_Logo