Package jmri.jmrix.bidib.serialdriver
Class SerialDriverAdapter
- java.lang.Object
-
- jmri.jmrix.AbstractPortController
-
- jmri.jmrix.AbstractSerialPortController
-
- jmri.jmrix.bidib.BiDiBSerialPortController
-
- jmri.jmrix.bidib.serialdriver.SerialDriverAdapter
-
- All Implemented Interfaces:
BiDiBPortController
,PortAdapter
,SerialPortAdapter
public class SerialDriverAdapter extends BiDiBSerialPortController
Implements SerialPortAdapter for the BiDiB system.This connects an BiDiB device via a serial com port.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class jmri.jmrix.AbstractSerialPortController
AbstractSerialPortController.Blocking, AbstractSerialPortController.FlowControl
-
Nested classes/interfaces inherited from class jmri.jmrix.AbstractPortController
AbstractPortController.Option
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.String
portNameFilter
protected java.lang.Long
rootNodeUid
protected java.lang.String
selectedSpeed
protected boolean
useAutoScan
protected java.lang.String[]
validSpeeds
protected int[]
validSpeedValues
-
Fields inherited from class jmri.jmrix.bidib.BiDiBSerialPortController
bidib, context
-
Fields inherited from class jmri.jmrix.AbstractSerialPortController
currentSerialPort, mBaudRate, mPort
-
Fields inherited from class jmri.jmrix.AbstractPortController
allowConnectionRecovery, manufacturerName, opened, option1Name, option2Name, option3Name, option4Name, options, reconnectinterval, reconnectMaxAttempts, reconnectMaxInterval
-
-
Constructor Summary
Constructors Constructor Description SerialDriverAdapter()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Long
checkPort(java.lang.String portName)
Internal method to check if the given port is a BiDiB connection and returns the unique ID of the root node.void
configure()
Set up all of the other objects to operate with an BiDiB command station connected to this port.java.lang.String
findPortbyUniqueID(java.lang.Long requid)
Internal method to find a port, possibly with already created BiDiB objectstatic java.lang.String
getCanonicalPortName(java.lang.String portName)
Get the canonical port name from the underlying operating system.java.io.DataInputStream
getInputStream()
Get the InputStream from the port.java.lang.String
getKownPortName(java.lang.Long reqUid)
Check if the port name of a given UID already exists in the cache.java.io.DataOutputStream
getOutputStream()
Get the outputStream to the port.java.util.List<java.lang.String>
getPortIdentifiers()
Get a list of available port namesjava.lang.String
getPortNameFilter()
Get the filter string for port names to scan when autoScan is onjava.lang.String
getRealPortName()
Get the physical port name used with jbidibcstatic java.lang.String
getRealPortName(java.lang.String portName)
Static function to get the port name in the format which is used by jbidibcjava.lang.Long
getRootNodeUid()
Get the root node unique IDboolean
getUseAutoScan()
Get the AutoScan statusjava.lang.String
openPort(java.lang.String portName, java.lang.String appName)
This methods is called from serial connection config and creates the BiDiB object from jbidibc and opens it.void
registerAllListeners(org.bidib.jbidibc.messages.ConnectionListener connectionListener, java.util.Set<org.bidib.jbidibc.core.NodeListener> nodeListeners, java.util.Set<org.bidib.jbidibc.core.MessageListener> messageListeners, java.util.Set<org.bidib.jbidibc.core.node.listener.TransferListener> transferListeners)
Register all Listeners to the specific BiDiB Object.void
setPortNameFilter(java.lang.String filter)
Set the port name filtervoid
setRootNodeUid(java.lang.Long uid)
Set the root node unique IDvoid
setUseAutoScan(boolean flag)
Set the AutoScan statusboolean
status()
Query the status of this connection.int[]
validBaudNumbers()
Get an array of valid baud rate numbers; used to store/load adapter speed option.java.lang.String[]
validBaudRates()
Get an array of valid baud rate strings; used to display valid options in Connections Preferences.-
Methods inherited from class jmri.jmrix.bidib.BiDiBSerialPortController
getContext, getSystemConnectionMemo
-
Methods inherited from class jmri.jmrix.AbstractSerialPortController
activatePort, activatePort, activatePort, closeConnection, closeSerialPort, configureBaudRate, configureBaudRateFromIndex, configureBaudRateFromNumber, configureLeads, configureLeadsAndFlowControl, configureLeadsAndFlowControl, connect, currentBaudNumber, defaultBaudIndex, getActualPortNames, getCurrentBaudIndex, getCurrentBaudNumber, getCurrentBaudRate, getCurrentPortName, getFlowControl, getPortSettingsString, handlePortBusy, handlePortNotFound, handlePortNotFound, isPortOpen, replacePortWithFakePort, reportPortStatus, resetupConnection, setBaudRate, setComPortTimeouts, setDataListener, setFlowControl, setPort
-
Methods inherited from class jmri.jmrix.AbstractPortController
configureOption1, configureOption2, configureOption3, configureOption4, dispose, getDisabled, getManufacturer, getOption1Name, getOption2Name, getOption3Name, getOption4Name, getOptionChoices, getOptionDisplayName, getOptions, getOptionState, getReconnectMaxAttempts, getReconnectMaxInterval, getSystemPrefix, getUserName, isDirty, isOptionAdvanced, isOptionTypePassword, isOptionTypeText, isRestartRequired, purgeStream, reconnect, reconnectFromLoop, recover, safeSleep, setClosed, setDisabled, setManufacturer, setOpened, setOptionState, setReconnectMaxAttempts, setReconnectMaxInterval, setSystemConnectionMemo, setSystemPrefix, setUserName
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jmri.jmrix.PortAdapter
connect, dispose, getDisabled, getOption1Name, getOption2Name, getOption3Name, getOption4Name, getOptionChoices, getOptionDisplayName, getOptions, getOptionState, getReconnectMaxAttempts, getReconnectMaxInterval, getSystemPrefix, getUserName, isDirty, isOptionAdvanced, isOptionTypePassword, isOptionTypeText, isRestartRequired, recover, setDisabled, setOptionState, setReconnectMaxAttempts, setReconnectMaxInterval, setSystemConnectionMemo, setSystemPrefix, setUserName
-
Methods inherited from interface jmri.jmrix.SerialPortAdapter
configureOption1, configureOption2, configureOption3, configureOption4, getManufacturer, getPortNames, setManufacturer
-
-
-
-
Field Detail
-
portNameFilter
protected java.lang.String portNameFilter
-
rootNodeUid
protected java.lang.Long rootNodeUid
-
useAutoScan
protected boolean useAutoScan
-
validSpeeds
protected java.lang.String[] validSpeeds
-
validSpeedValues
protected int[] validSpeedValues
-
selectedSpeed
protected java.lang.String selectedSpeed
-
-
Constructor Detail
-
SerialDriverAdapter
public SerialDriverAdapter()
-
-
Method Detail
-
getPortNameFilter
public java.lang.String getPortNameFilter()
Get the filter string for port names to scan when autoScan is on- Returns:
- port name filter as a string (wildcard is allowed at the end)
-
setPortNameFilter
public void setPortNameFilter(java.lang.String filter)
Set the port name filter- Parameters:
filter
- filter string
-
getRootNodeUid
public java.lang.Long getRootNodeUid()
Get the root node unique ID- Returns:
- UID as Long
-
setRootNodeUid
public void setRootNodeUid(java.lang.Long uid)
Set the root node unique ID- Parameters:
uid
- Unique ID as Long
-
getUseAutoScan
public boolean getUseAutoScan()
Get the AutoScan status- Returns:
- true of autoScan is on, false if not
-
setUseAutoScan
public void setUseAutoScan(boolean flag)
Set the AutoScan status- Parameters:
flag
- true of ON is requested
-
getRealPortName
public java.lang.String getRealPortName()
Get the physical port name used with jbidibc Get the port name in the format which is used by jbidibc- Specified by:
getRealPortName
in interfaceBiDiBPortController
- Overrides:
getRealPortName
in classBiDiBSerialPortController
- Returns:
- real port name
-
getCanonicalPortName
public static java.lang.String getCanonicalPortName(java.lang.String portName)
Get the canonical port name from the underlying operating system. For a symbolic link, the real path is returned.- Parameters:
portName
- human-readable name- Returns:
- canonical path
-
getRealPortName
public static java.lang.String getRealPortName(java.lang.String portName)
Static function to get the port name in the format which is used by jbidibc- Parameters:
portName
- displayed port name- Returns:
- real port name
-
openPort
public java.lang.String openPort(java.lang.String portName, java.lang.String appName)
This methods is called from serial connection config and creates the BiDiB object from jbidibc and opens it. The connectPort method of the traffic controller is called for generic initialisation.- Parameters:
portName
- port name from XMLappName
- not used- Returns:
- error string to be displayed by JMRI. null of no error
-
configure
public void configure()
Set up all of the other objects to operate with an BiDiB command station connected to this port.
-
registerAllListeners
public void registerAllListeners(org.bidib.jbidibc.messages.ConnectionListener connectionListener, java.util.Set<org.bidib.jbidibc.core.NodeListener> nodeListeners, java.util.Set<org.bidib.jbidibc.core.MessageListener> messageListeners, java.util.Set<org.bidib.jbidibc.core.node.listener.TransferListener> transferListeners)
Register all Listeners to the specific BiDiB Object. We need this here since the BidibInterface does not provide this method.- Specified by:
registerAllListeners
in interfaceBiDiBPortController
- Specified by:
registerAllListeners
in classBiDiBSerialPortController
- Parameters:
connectionListener
- where to addnodeListeners
- listeners to addmessageListeners
- listeners to addtransferListeners
- listeners to add
-
getPortIdentifiers
public java.util.List<java.lang.String> getPortIdentifiers()
Get a list of available port names- Returns:
- list of portnames
-
findPortbyUniqueID
public java.lang.String findPortbyUniqueID(java.lang.Long requid)
Internal method to find a port, possibly with already created BiDiB object- Parameters:
requid
- requested unique ID of the root node- Returns:
- port name as String
-
checkPort
public java.lang.Long checkPort(java.lang.String portName)
Internal method to check if the given port is a BiDiB connection and returns the unique ID of the root node. Return the UID from cache if we already know the UID. // * @param bidib a BiDiB object from jbidibc- Parameters:
portName
- port name to check- Returns:
- unique ID of the root node
-
getKownPortName
public java.lang.String getKownPortName(java.lang.Long reqUid)
Check if the port name of a given UID already exists in the cache.- Parameters:
reqUid
- requested UID- Returns:
- port name or null if not found in cache
-
getInputStream
public java.io.DataInputStream getInputStream()
Description copied from class:AbstractPortController
Get the InputStream from the port.- Specified by:
getInputStream
in interfacePortAdapter
- Overrides:
getInputStream
in classAbstractSerialPortController
- Returns:
- the InputStream from the port
-
getOutputStream
public java.io.DataOutputStream getOutputStream()
Description copied from class:AbstractPortController
Get the outputStream to the port.- Specified by:
getOutputStream
in interfacePortAdapter
- Overrides:
getOutputStream
in classAbstractSerialPortController
- Returns:
- the outputStream to the port
-
status
public boolean status()
Query the status of this connection. This is a question of configuration, not transient hardware status.- Specified by:
status
in interfacePortAdapter
- Specified by:
status
in interfaceSerialPortAdapter
- Overrides:
status
in classAbstractPortController
- Returns:
- true if OK, at least as far as known
-
validBaudRates
public java.lang.String[] validBaudRates()
Get an array of valid baud rate strings; used to display valid options in Connections Preferences.- Specified by:
validBaudRates
in interfaceSerialPortAdapter
- Overrides:
validBaudRates
in classAbstractSerialPortController
- Returns:
- array of I18N display strings of port speed settings valid for this serial adapter,
must match order and values from
SerialPortAdapter.validBaudNumbers()
-
validBaudNumbers
public int[] validBaudNumbers()
Get an array of valid baud rate numbers; used to store/load adapter speed option.- Specified by:
validBaudNumbers
in interfaceSerialPortAdapter
- Overrides:
validBaudNumbers
in classAbstractSerialPortController
- Returns:
- integer array of speeds, must match order and values from
SerialPortAdapter.validBaudRates()
-
-