Package jmri.jmrit.automat
Class SampleAutomaton
java.lang.Object
jmri.jmrit.automat.AbstractAutomaton
jmri.jmrit.automat.SampleAutomaton
- All Implemented Interfaces:
Runnable
This sample Automaton watches a Sensor, and adjusts the state of a Turnout so
that it matches the Sensor's state.
The sensor and turnout id's are hardcoded, as this is an example of just the Automaton function. Adding a GUI to configure these would be straight-forward. The values could be passed via the constructor, or the constructor (which can run in any required thread) could invoke a dialog.
For test purposes, one of these objects can be created and invoked by a SampleAutomatonAction.
For more information on JMRI support for automation classes, please see the JMRI Layout Automation in Java page.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class jmri.jmrit.automat.AbstractAutomaton
AbstractAutomaton.MsgFrame -
Field Summary
FieldsModifier and TypeFieldDescription(package private) int(package private) SensorReferences the sensor to be monitored(package private) StringBy default, monitors sensor "31"(package private) TurnoutReferences the turnout to be controlled(package private) StringBy default, controls turnout "26".Fields inherited from class jmri.jmrit.automat.AbstractAutomaton
debugWaitFrame, message, messageFrame, promptOnWait, waitChangePrecheckBeans, waitChangePrecheckStates, waitChangeQueue -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanhandle()Watch "sensor", and when it changes adjust "turnout" to match.protected voidinit()This also sets the turnout to the current (initial) state to make sure everything is consistent at the start.(package private) voidsetTurnout(int now) Set "turnout" to match the sensor stateMethods inherited from class jmri.jmrit.automat.AbstractAutomaton
defaultName, done, getCount, getName, getThrottle, getThrottle, getThrottle, getThrottle, isRunning, isWaiting, readServiceModeCV, run, setName, setTurnouts, start, stop, wait, waitChange, waitChange, waitChangePrecheck, waitMsec, waitSensorActive, waitSensorActive, waitSensorChange, waitSensorChange, waitSensorInactive, waitSensorInactive, waitSensorState, waitSensorState, waitSignalHeadState, waitSignalMastState, waitTurnoutConsistent, waitWarrantBlock, waitWarrantBlockChange, waitWarrantRunState, writeOpsModeCV, writeServiceModeCV
-
Field Details
-
turnout
References the turnout to be controlled -
sensor
References the sensor to be monitored -
sensorName
By default, monitors sensor "31" -
turnoutName
By default, controls turnout "26". -
now
int now
-
-
Constructor Details
-
SampleAutomaton
public SampleAutomaton()
-
-
Method Details
-
init
This also sets the turnout to the current (initial) state to make sure everything is consistent at the start.- Overrides:
initin classAbstractAutomaton
-
handle
Watch "sensor", and when it changes adjust "turnout" to match.- Overrides:
handlein classAbstractAutomaton- Returns:
- Always returns true to continue operation
-
setTurnout
Set "turnout" to match the sensor state- Parameters:
now- The current value of the sensor state.
-