Class MarklinTurnout

All Implemented Interfaces:
PropertyChangeListener, Comparable<NamedBean>, EventListener, PropertyChangeProvider, DigitalIO, AbstractMRListener, MarklinListener, NamedBean, Turnout, VariableControlSpanBean

public class MarklinTurnout extends AbstractTurnout implements MarklinListener
Implement a Turnout via Marklin communications.

This object doesn't listen to the Marklin communications for protocol auto-detection; protocol is determined at construction from the system name prefix. More than one Turnout object pointing to a single device is not allowed.

The system name encodes protocol and address:

  • MTDCC45 — DCC accessory address 45, wire = DCCACCSTART + 44
  • MTMM123 — MM/MM2 accessory address 123, wire = MM1ACCSTART + 122
  • MTCAN200 — raw CAN wire address 200, used verbatim
  • MT45 — legacy unprefixed, treated as DCC

Based on work by Bob Jacobsen

  • Field Details

  • Constructor Details

    • MarklinTurnout

      public MarklinTurnout(String systemName, String prefix, MarklinTrafficController tc)
      Create a MarklinTurnout from its full system name.
      Parameters:
      systemName - full system name, e.g. MTDCC45 or MT123
      prefix - system prefix, e.g. M
      tc - traffic controller
  • Method Details

    • forwardCommandChangeToLayout

      protected void forwardCommandChangeToLayout(int newState)
      Handle a request to change state, typically by sending a message to the layout in some child class. Public version (used by TurnoutOperator) sends the current commanded state without changing it. Implementing classes will typically check the value of s and send a system specific sendMessage command.
      Specified by:
      forwardCommandChangeToLayout in class AbstractTurnout
      Parameters:
      newState - new state value
    • getCANAddress

      Return the wire address for the accessory command.
      • DCC: _number + DCCACCSTART - 1
      • MM: _number + MM1ACCSTART - 1
      • CAN: _number verbatim (raw CAN address)
    • sendMessage

      protected void sendMessage(boolean newstate)
    • sendOffMessage

      protected void sendOffMessage(int state)
    • reply

      public void reply(MarklinReply m)
      Specified by:
      reply in interface MarklinListener
    • message

      public void message(MarklinMessage m)
      Specified by:
      message in interface MarklinListener
    • turnoutPushbuttonLockout

      public void turnoutPushbuttonLockout(boolean b)
      Specified by:
      turnoutPushbuttonLockout in class AbstractTurnout
    • canInvert

      public boolean canInvert()
      Marklin turnouts can be inverted.
      Specified by:
      canInvert in interface Turnout
      Overrides:
      canInvert in class AbstractTurnout
      Returns:
      invert supported
    • setCommandedStateFromCS

      void setCommandedStateFromCS(int state)
      Set the turnout known state to reflect what's been observed from the command station messages. A change there means that somebody commanded a state change (by using a throttle), and that command has already taken effect. Hence we use "newCommandedState" to indicate it's taken place. Must be followed by "newKnownState" to complete the turnout action.
      Parameters:
      state - Observed state, updated state from command station
    • setKnownStateFromCS

      void setKnownStateFromCS(int state)
      Set the turnout known state to reflect what's been observed from the command station messages. A change there means that somebody commanded a state change (by using a throttle), and that command has already taken effect. Hence we use "newKnownState" to indicate it's taken place.
      Parameters:
      state - Observed state, updated state from command station
    • dispose

      public void dispose()
      Description copied from class: AbstractTurnout
      Deactivate this object, so that it releases as many resources as possible and no longer effects others.

      For example, if this object has listeners, after a call to this method it should no longer notify those listeners. Any native or system-wide resources it maintains should be released, including threads, files, etc.

      It is an error to invoke any other methods on this object once dispose() has been called. Note, however, that there is no guarantee about behavior in that case.

      Afterwards, references to this object may still exist elsewhere, preventing its garbage collection. But it's formally dead, and shouldn't be keeping any other objects alive. Therefore, this method should null out any references to other objects that this NamedBean contained.

      Specified by:
      dispose in interface NamedBean
      Overrides:
      dispose in class AbstractTurnout