jmri.jmrix
Class AbstractSerialPortController

Show UML class diagram
java.lang.Object
  extended by jmri.jmrix.AbstractPortController
      extended by jmri.jmrix.AbstractSerialPortController
All Implemented Interfaces:
PortAdapter, SerialPortAdapter
Direct Known Subclasses:
AcelaPortController, Dcc4PcPortController, EasyDccPortController, GcPortController, IEEE802154PortController, InternalAdapter, LnPortController, MrcPortController, Mx1PortController, NcePortController, Port, PortController, PortController, QsiPortController, RfidPortController, SerialAdapter, SerialPortController, SerialPortController, SerialPortController, SerialPortController, SerialPortController, SerialPortController, SerialPortController, SerialSensorAdapter, SpeedoPortController, SprogPortController, TamsPortController, XNetSerialPortController, XNetSimulatorPortController, XpaPortController

public abstract class AbstractSerialPortController
extends AbstractPortController
implements SerialPortAdapter

Provide an abstract base for *PortController classes.

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

See Also:
SerialPortAdapter

Nested Class Summary
(package private)  class AbstractSerialPortController.reconnectwait
           
 
Nested classes/interfaces inherited from class jmri.jmrix.AbstractPortController
AbstractPortController.Option
 
Field Summary
protected static org.slf4j.Logger log
           
protected  String mBaudRate
           
protected  String mPort
           
(package private)  Vector<String> portNameVector
           
 
Fields inherited from class jmri.jmrix.AbstractPortController
allowConnectionRecovery, mDisabled, mManufacturer, opened, option1Name, option2Name, option3Name, option4Name, options, reconnectinterval, retryAttempts
 
Constructor Summary
AbstractSerialPortController()
           
 
Method Summary
protected  void closeConnection()
           
 void configureBaudRate(String rate)
          Set the baud rate.
 void connect()
          Open the connection
 int currentBaudNumber(String currentBaudRate)
          Convert a baud rate string to a number.
 void dispose()
           
 String getCurrentBaudRate()
           
 String getCurrentPortName()
           
 Vector<String> getPortNames()
          Provide a vector of valid port names, each a String.
 SystemConnectionMemo getSystemConnectionMemo()
           
 String handlePortBusy(PortInUseException p, String portName, org.slf4j.Logger log)
          Standard error handling for port-busy case
 String handlePortNotFound(NoSuchPortException p, String portName, org.slf4j.Logger log)
          Standard error handling for port-not-found case
 void reconnect()
          Attempts to reconnect to a failed Server
 void recover()
          This is called when a connection is initially lost.
protected  void resetupConnection()
           
 void setDisabled(boolean disabled)
          Sets whether the connection is disabled
 void setPort(String port)
          Remember the associated port name
 int[] validBaudNumber()
          Get an array of valid baud rates as integers.
 
Methods inherited from class jmri.jmrix.AbstractPortController
configureOption1, configureOption2, configureOption3, configureOption4, getDisabled, getInputStream, getManufacturer, getOption1Name, getOption2Name, getOption3Name, getOption4Name, getOptionChoices, getOptionDisplayName, getOptions, getOptionState, getOutputStream, isOptionAdvanced, safeSleep, setClosed, setManufacturer, setOpened, setOptionState, status
 
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, configureOption1, configureOption2, configureOption3, configureOption4, getManufacturer, openPort, setManufacturer, status, validBaudRates
 
Methods inherited from interface jmri.jmrix.PortAdapter
getDisabled, getInputStream, getOption1Name, getOption2Name, getOption3Name, getOption4Name, getOptionChoices, getOptionDisplayName, getOptions, getOptionState, getOutputStream, isOptionAdvanced, setOptionState
 

Field Detail

mPort

protected String mPort

mBaudRate

protected String mBaudRate

portNameVector

Vector<String> portNameVector

log

protected static final org.slf4j.Logger log
Constructor Detail

AbstractSerialPortController

public AbstractSerialPortController()
Method Detail

handlePortBusy

public String handlePortBusy(PortInUseException p,
                             String portName,
                             org.slf4j.Logger log)
Standard error handling for port-busy case

Specified by:
handlePortBusy in interface SerialPortAdapter
See Also:
AbstractSerialPortController

handlePortNotFound

public String handlePortNotFound(NoSuchPortException p,
                                 String portName,
                                 org.slf4j.Logger log)
Standard error handling for port-not-found case


connect

public void connect()
             throws Exception
Description copied from interface: PortAdapter
Open the connection

Specified by:
connect in interface PortAdapter
Throws:
Exception

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 PortAdapter
Specified by:
getCurrentPortName in interface SerialPortAdapter
Specified by:
getCurrentPortName in class AbstractPortController

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)

getPortNames

public Vector<String> getPortNames()
Description copied from interface: SerialPortAdapter
Provide a vector of valid port names, each a String.

Specified by:
getPortNames in interface SerialPortAdapter

getSystemConnectionMemo

public SystemConnectionMemo getSystemConnectionMemo()
Specified by:
getSystemConnectionMemo in interface PortAdapter
Specified by:
getSystemConnectionMemo in class AbstractPortController

setDisabled

public void setDisabled(boolean disabled)
Description copied from interface: PortAdapter
Sets whether the connection is disabled

Specified by:
setDisabled in interface PortAdapter
Specified by:
setDisabled in class AbstractPortController

dispose

public void dispose()
Specified by:
dispose in interface PortAdapter

recover

public void recover()
This is called when a connection is initially lost. It closes the client side socket connection, resets the open flag and attempts a reconnection.

Specified by:
recover in interface PortAdapter
Specified by:
recover in class AbstractPortController

closeConnection

protected void closeConnection()
                        throws Exception
Throws:
Exception

resetupConnection

protected void resetupConnection()

reconnect

public void reconnect()
Attempts to reconnect to a failed Server



Copyright © 1997-2014 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: Get JMRI Model Railroad Interface at SourceForge.net. Fast, secure and Free Open Source software downloads