Package jmri.jmrix

Class AbstractSerialPortController

    • Field Detail

      • mPort

        protected java.lang.String mPort
      • mBaudRate

        protected java.lang.String mBaudRate
    • Method Detail

      • handlePortBusy

        public java.lang.String handlePortBusy​(purejavacomm.PortInUseException p,
                                               java.lang.String portName,
                                               org.slf4j.Logger log)
        Standard error handling for port-busy case.
        Specified by:
        handlePortBusy in interface SerialPortAdapter
        Parameters:
        p - the exception being handled, if additional information from it is desired
        portName - name of the port being accessed
        log - where to log a status message
        Returns:
        Localized message, in case separate presentation to user is desired
        See Also:
        AbstractSerialPortController
      • handlePortNotFound

        public java.lang.String handlePortNotFound​(purejavacomm.NoSuchPortException p,
                                                   java.lang.String portName,
                                                   org.slf4j.Logger log)
        Standard error handling for port-not-found case.
        Parameters:
        p - no such port exception.
        portName - port name.
        log - system log.
        Returns:
        human readable string with error detail.
      • connect

        public void connect()
                     throws java.io.IOException
        Open the connection.
        Specified by:
        connect in interface PortAdapter
        Throws:
        java.io.IOException - if unable to connect
      • setPort

        public void setPort​(java.lang.String port)
        Remember the associated port name.
        Specified by:
        setPort in interface SerialPortAdapter
        Parameters:
        port - name of the port
      • configureLeadsAndFlowControl

        protected void configureLeadsAndFlowControl​(purejavacomm.SerialPort serialPort,
                                                    int flow,
                                                    boolean rts,
                                                    boolean dtr)
        Set the control leads and flow control. This handles any necessary ordering.
        Parameters:
        serialPort - Port to be updated
        flow - flow control mode from (@link purejavacomm.SerialPort}
        rts - set RTS active if true
        dtr - set DTR active if true
      • configureLeadsAndFlowControl

        protected void configureLeadsAndFlowControl​(purejavacomm.SerialPort serialPort,
                                                    int flow)
        Set the flow control, while also setting RTS and DTR to active.
        Parameters:
        serialPort - Port to be updated
        flow - flow control mode from (@link purejavacomm.SerialPort}
      • configureBaudRate

        public void configureBaudRate​(java.lang.String rate)
        Set the baud rate description by port speed description.

        Only to be used after construction, but before the openPort call.

        Specified by:
        configureBaudRate in interface SerialPortAdapter
        Parameters:
        rate - the baud rate as I18N description, eg. "28,800 baud"
      • configureBaudRateFromNumber

        public void configureBaudRateFromNumber​(java.lang.String indexString)
        Set the baud rate description by port speed number (as a string) from validBaudRates[].

        Only to be used after construction, but before the openPort call.

        Specified by:
        configureBaudRateFromNumber in interface SerialPortAdapter
        Parameters:
        indexString - the port speed as unformatted number string, eg. "28800"
      • defaultBaudIndex

        public int defaultBaudIndex()
        Description copied from interface: SerialPortAdapter
        Get the index of the default port speed for this adapter from the validSpeeds and validRates arrays.
        Specified by:
        defaultBaudIndex in interface SerialPortAdapter
        Returns:
        -1 to indicate not supported, unless overridden in adapter
      • currentBaudNumber

        public int currentBaudNumber​(java.lang.String currentBaudRate)
        Convert a baud rate I18N String to an int number, e.g. "9,600 baud" to 9600.

        Uses the validBaudNumbers() and validBaudRates() methods to do this.

        Parameters:
        currentBaudRate - a rate from validBaudRates()
        Returns:
        baudrate as integer if available and matching first digits in currentBaudRate, 0 if baudrate not supported by this adapter, -1 if no match (configuration system should prevent this)
      • setPortEventLogging

        protected void setPortEventLogging​(purejavacomm.SerialPort port)
        Set event logging.
        Parameters:
        port - Serial port to configure
      • getPortNames

        public java.util.Vector<java.lang.String> getPortNames()
        Provide a vector of valid port names, each a String.
        Specified by:
        getPortNames in interface SerialPortAdapter
        Returns:
        port names.
      • closeConnection

        protected void closeConnection()
        Abstract class for controllers to close the connection. Called prior to any re-connection attempts. Each serial port adapter should handle this and it should be abstract.
        Overrides:
        closeConnection in class AbstractPortController
      • resetupConnection

        protected void resetupConnection()
        Re-setup the connection. Called when the physical connection has reconnected and can be linked to this connection. Each port adapter should handle this and it should be abstract.
        Overrides:
        resetupConnection in class AbstractPortController
      • reconnectFromLoop

        protected void reconnectFromLoop​(int retryNum)
        Abstract class for ports to attempt a single re-connection attempt. Called from within main reconnect thread. Attempts a re-connection to the serial port from the main reconnect thread.
        Overrides:
        reconnectFromLoop in class AbstractPortController
        Parameters:
        retryNum - Reconnection attempt number.