The JMRI features we use
Basic signal masts, Signal Mast Logic (SML) with its Discover tool, the Layout Editor, the web server, the MQTT (Message Queuing Telemetry Transport) connection, LogixNG and the green and red lamp icons. CATS, the open-source CTC desk, runs alongside. Entry/Exit, the Dispatcher System and the CTC tool are parked (see the note above).
The story of how the software came together is told in Bringing the Railroad Together.
The scripts
Seven Jython scripts run inside JMRI. The first five handle the signals, the panel, the CATS desk windows, the three level panels and the remote-run hook; the last two connect the traffic simulator and the LCOS mimic page. The first two are explained further down: the signal coordinator under Who drives the mast lamps, and the panel helper under Four lamps.
| Script | How it starts | What it does |
|---|---|---|
signal_coordinator.py | Start Up; copied to every host (the Pi, Windows and the Mac) | Decides whether JMRI or the field electronics drive the mast lamps, hands control over between them, and recovers if a JMRI session crashes. It owns the "SML Enabled" button. Seven modules beside it hold the rest of its code and are deployed with it: sml_lcos.py, sml_beans.py, sml_quit.py, sml_ui.py, sml_claims.py, sml_handoff.py and sml_events.py. See Who drives the mast lamps. |
panel_status.py | Start Up; copied to every host (the Pi, Windows and the Mac) | Makes the four status lamps clickable and keeps them up to date. It never throws a switch. (It also lit the yard-ladder triangle lamps until they were retired on 17 November 2026.) Two modules beside it hold the rest of its code and are deployed with it: panel_status_clicks.py and panel_status_turnouts.py. See Four lamps. |
hide_cats_desk_windows.py | When the tables load (see The LogixNGs); copied to every host (the Pi, Windows and the Mac) | Under CATS, hides the HART Railroad panel and adds Help and Quit buttons to the button strip at the bottom of the CTC Panel. In plain PanelPro it does nothing. |
hide_band_panels.py | When the tables load (see The LogixNGs); copied to every host (the Pi, Windows and the Mac) | Hides the three level panels (Staging Level, Main Level, Upper Level), copies of the track diagram kept for reference. It checks every half second until all three windows are open, since they open after the tables load. |
jmri_cmd_watcher.py | Start Up on the Pi; copied to every host (the Pi, Windows and the Mac) | The remote-run hook, described under this table. |
sts_car_sync.py | Start Up; copied to the Pi and the Mac | Copies car positions, loads and final destinations from the traffic simulator (STS) into Operations Pro. The stock JSON server can move a car but cannot set its load or destination, so STS writes a batch into a Memory and this script applies it. It never touches turnouts, signals or MQTT. |
mimic_relay.py | Start Up; copied to the Pi only | Publishes fake LCOS feedback for the mimic page, a test tool served by JMRI's web server. The page writes a request into the Memory IMHART_MIMIC and the script publishes it, retained, through JMRI's own MQTT connection. It only sends occupancy and switch position reports, never a switch command, so it cannot move a motor. |
Deploying copies each host's scripts into the jython folder of the JMRI user files and points the profile's Start Up entries
at them, adding the entries for the last two where they are installed, and JMRI finds them through its own preference:jython/ path. Many other
scripts exist, but they run offline to build the tables, not inside JMRI.
jmri_cmd_watcher.py has nothing to do with running trains. It
is a remote-run hook: a small watcher that starts with JMRI and gives us, and the AI agents we
work with, a live way to query a running session. Twice a second it looks for a command file in
a fixed local place. When one appears, it runs that file as a script inside JMRI and writes back
the result or the error.
Whatever is dropped there runs with JMRI's full access, so it can do anything JMRI can do, including move a turnout. The watcher opens no network service of its own, so reaching it takes a login on that machine. The project's rules on commanding the field apply to anything sent through it, and the AI agents are blocked from the remote login that would reach it.
The LogixNGs
Two LogixNGs in the tables file run when the tables load, under PanelPro or CATS.
"Hide windows on start" hides the WiThrottle window and runs hide_cats_desk_windows.py and hide_band_panels.py.
"Main and upper block sensors clear on start" sets the internal block sensors of the main and upper
levels to clear, because a signal does not clear into a block whose state is unknown, and sets their
internal turnouts to normal, except Switches 227 and 229, which start thrown so the main runs round
the peninsula loop. Those levels have no field detectors or switch machines in JMRI yet. Both are
built from stock actions; see The LogixNGs for the details.
What goes into the profile
A JMRI profile is the set of user files and settings that a JMRI install loads at startup. Here is everything we deploy into one. It all lives in the project repository, and
deploying copies it into the JMRI user files and profiles. JMRI finds each piece through its own
preference: paths, so none of it touches the JMRI program folder.
| In the profile | What it is |
|---|---|
tables.xml | The one tables file: blocks, turnouts, sensors, masts, Signal Mast Logic, LogixNG and the panel, including the status lamps. PanelPro loads it at startup. The main and upper levels have no reviewed field wiring yet, so they run on internal turnouts, block sensors and signal heads, each named after its switch, block or mast (block 101-103's sensor is IS:HART:C3:B:101-103). The block sensors are set clear when the tables load. A file in the repository, the device map, links each one to its planned field device, so a real device goes in by changing the map. More on the tables file. |
roster/ and roster.xml | The DecoderPro roster: one file per locomotive and the index that names them, with the roster photos. The repository holds the master copy. Deploy installs it on every host and keeps a backup of what it replaces. A programming session on the main layout host is pulled back into the repository before the next deploy. |
jython/ | The scripts above that the host runs. |
| Start Up entries | Kept in the profile, so JMRI loads the tables and runs the scripts at launch. Deploy repoints the script entries and adds the two for the traffic simulator and the mimic. |
resources/buttons/ | Button images: the 16-pixel triangle lamps of the retired yard-ladder buttons, and lamps used by the parked lever machine. |
resources/icons/USS/sensor/ | Lamp icons used on the panels: our yellow pair. The amber icon is JMRI's own. |
resources/misc/hart_panel_bg_plain.jpg | The backdrop of the HART Railroad panel, 1900 by 600 pixels. It sits behind the track as a label on the panel, at the top left. |
ctc/icons/ and ctc/GUIObjects.xml | The USS CTC machine: 70 generated track icons and the panel layout, as custom cells for the stock CTC tool. Parked; not shipped to the hosts. |
dispatcher/traininfo/ and dispatcheroptions.xml | Dispatcher data, not code: the options and the traininfo files that stock Stage 1 writes. Parked; not shipped to the hosts. |
web/servlet/home/Home.html | The web home page: a copy of JMRI 5.16's stock page with two links added, to the traffic simulator and the LCOS mimic. JMRI serves this copy before its own, so it is brought up to the new stock page at each JMRI upgrade. |
web/mimic/ | The LCOS mimic page, on the main layout host only. It reads the layout through JMRI's stock JSON WebSocket and fakes field feedback through mimic_relay.py, for testing without the field electronics. |
Who drives the mast lamps
The device master plans 96 signal masts: 68 on the main and upper levels and 28 in staging. 67 of them get lamps; the other 29 are hidden staging masts that only JMRI sees. The lamps are driven by small field electronics (the nodes described on LCOS and the Arduino bridge, and listed in the device viewer). Those electronics have signal logic of their own, and JMRI has Signal Mast Logic (SML). If both drove one lamp, they could disagree. And if a JMRI session crashed while it drove the lamps, they could freeze on whatever colour they last showed.
So one switch decides whether JMRI's logic or the field logic is in charge. It ticks or unticks the stock Enabled checkbox that each source-to-destination pair in SML already has. Today one mast in the tables is wired to field heads, with one destination, all moved together. The other 66 sources, with 165 destinations, have no field heads yet. They stay enabled. The set of field masts is not hard-coded: the script finds it in the tables, as the masts whose heads are LCOS heads, so each mast joins as its node is wired.
The join between the two worlds is JMRI's virtual signal heads. SML sets the mast and its heads, and a script listens to the heads. A head only sends a colour once the field has reported that head, so a node that has never reported is not sent a command. The sessions also share one small status word, kept on the broker so a newly started session can read it, that says whether JMRI currently has control.
- Signals ON. JMRI's logic decides every aspect and the script sends each virtual head's colour out to the field. The CATS desks only hold or release masts.
- Signals OFF. The field logic decides. The script lets go of the heads and copies the field's status back onto the heads and masts, so the panels show what the lamps are really doing.
- One pair unchecked. The same let-go and mirror, for that one mast only.
How the hand-over works
The hand-over is a short routine that holds the masts while control changes, so no lamp changes colour under an approaching train. Switching on or off takes about four seconds.
Switching JMRI on:
- Hold the field masts.
- Wait about three seconds.
- Tick the pairs.
- Release the holds.
- Announce that JMRI is in control.
- Push the current colours out.
Switching it off:
- Hold the masts.
- Wait about three seconds.
- Untick the pairs.
- Release the heads to the field.
- Drop the holds.
- Announce that JMRI is out.
Boot
Normally every pair is forced off when JMRI starts. The script then listens for a second. If nobody has control, this session takes it. If another session already has it, this one stays off and disturbs nothing. If the pairs were stored as enabled, a warning appears and the script takes over instead of trusting them. Deploy also ships the field pairs switched off, because Discover writes them on. If an operator turns signals on while another session owns them, the script probes first and then asks "Force override?" before doing anything.
Quit
Closing JMRI runs a short switch-off: hold, wait, release, announce that JMRI is out. It is hooked in through a stock shutdown task, so a normal exit never leaves the lamps frozen.
Crash
After a crash nothing gets to clean up. The LCOS bridge program sees a status that still says "enabled" and challenges it. A live session answers and the challenge is cancelled. With no answer, the bridge sets the signals to red, waits about three seconds and releases them to the field logic, which carries on.
The operator's handle on all of this is a button on the main JMRI window strip, "SML Enabled" or "SML Disabled" depending on state. It stays available under CATS, on the CTC Panel, where the other windows are tucked away.
The topics behind the logic
All of this runs over MQTT, a lightweight message system (see LCOS and the Arduino bridge). JMRI, the bridge and the scripts share the topics below. The number at the end of a topic identifies one device.
| Topic | Direction | What it does |
|---|---|---|
track/bridge/sml_mode | Both ways | The shared status word. It is retained, so a new session can read it. Values: enabled, enabling, aborting, aborted, disabling, disabled, and query (not retained), which asks whether anyone is in control. |
track/signalhead/<n> | JMRI to field | With Signals ON, the colour for one head, such as Red, Yellow or Green. Releasing a head back to the field goes this way too. |
track/signalmast/<n> | Field to JMRI | What a signal is showing, such as Stop; Lit; Unheld. This is how a head gets enrolled, and with Signals OFF it is what the panels mirror. |
track/state | JMRI to bridge | JMRI's own online status. An offline report sets off the crash check. |
track/bridge/status | Bridge to all | Whether the bridge program is online or offline. Retained. |
track/bridge/cmd | JMRI to bridge | Bridge requests. Clicking the LCOS lamp sends RESUBSCRIBE here. |
track/sensor/<n> | Field to JMRI | Occupancy and feedback sensors. One reserved sensor reports the health of the LCOS link and drives the LCOS lamp. For testing, the LCOS mimic page can publish here too (see mimic_relay.py in the scripts above). |
track/turnout/<n> | Field to JMRI | The reported position of a switch. The LCOS mimic page can publish test values here too. |
track/cmd/turnout/<n> | JMRI to field | A command to move a switch. Keeping commands on their own topic is what lets the lamps and scripts read state without ever moving anything. |
Boot, quit and crash mostly work through track/bridge/sml_mode. A session announces what it is doing, the others react, and the bridge sends query when a session seems to have gone.
Four lamps
Four lamps at the bottom left of the HART Railroad panel show whether the bridge is up, whether the switches use feedback, who drives the signals, and whether the track is powered. They are stock icons on a stock Layout Editor panel; the only thing we added is a script that makes them clickable. Amber means a change is under way. Under CATS the lamps are hidden, but the signals button remains.
| Lamp | Green | Red | Amber | Click |
|---|---|---|---|---|
| LCOS | Bridge link established | Not established | Click pending, or no report from the bridge yet (shown as "?") | Asks the bridge to sign up with the nodes again. If nothing arrives, the old colour returns after 2 seconds. |
| Turnouts | All two-sensor switches use feedback | All in direct mode | Mixed, or a click pending | Flips all 40 between feedback and direct. From mixed, goes to feedback. |
| Signals | Signals on | Off, or this session does not own them | Hand-off under way | Same as the button. A watcher clears a stuck amber within about 20 seconds. |
| Track Power | On | Off | Pending | Toggles the stock power manager; a listener keeps the lamp true. |
Upgrading JMRI
The web home page copy is the one file to redo at a JMRI upgrade. It is brought up to the new stock page.
More: How the signals work · LCOS and the Arduino bridge · Dispatcher guides · Device viewer