What we added to JMRI

JMRI (Java Model Railroad Interface) is the software that runs the layout; CATS (Crandic Automated Traffic System) runs on top of it as the dispatcher's desk. Parked since the helix-join release (November 2026): Entry/Exit, the Dispatcher System and the USS CTC (Centralized Traffic Control) machine are not in the active panel, and their data is kept in jmri/layouts/hart/parked/. Signal masts, Signal Mast Logic and the CATS desks stay live. JMRI and CATS run here as stock installs. This page covers what we added on top: seven scripts, the files deployed into the JMRI profile, and how the signal hand-over and the status lamps work.

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.

ScriptHow it startsWhat it does
signal_coordinator.pyStart 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.pyStart 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.pyWhen 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.pyWhen 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.pyStart 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.pyStart Up; copied to the Pi and the MacCopies 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.pyStart Up; copied to the Pi onlyPublishes 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 profileWhat it is
tables.xmlThe 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.xmlThe 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 entriesKept 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.jpgThe 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.xmlThe 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.xmlDispatcher data, not code: the options and the traininfo files that stock Stage 1 writes. Parked; not shipped to the hosts.
web/servlet/home/Home.htmlThe 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.

Who drives the lamps in each mode Three rows, each with JMRI on the left, the field masts' lamps in the middle and the field electronics on the right. With signals on, a solid arrow runs from JMRI to the lamps and the field electronics are idle. With signals off, a solid arrow runs from the field electronics to the lamps and a dashed arrow carries status back to JMRI. With one pair unchecked, the same as off, for one mast. In each row the CATS desks reach the lamps only with a dashed Hold arrow. Signals ON JMRIdecides Mast lamps Field logicidle CATS desks Hold only Signals OFF JMRImirrors Mast lamps Field logicdecides status mirrored CATS desks Hold only One pair unchecked The same as OFF, for that one mast only. Every other mast keeps following JMRI. one mast, field-driven
Who drives the lamps in each mode. The filled box decides. Dashed arrows carry status or a Hold, never a signal aspect.

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:

  1. Hold the field masts.
  2. Wait about three seconds.
  3. Tick the pairs.
  4. Release the holds.
  5. Announce that JMRI is in control.
  6. Push the current colours out.

Switching it off:

  1. Hold the masts.
  2. Wait about three seconds.
  3. Untick the pairs.
  4. Release the heads to the field.
  5. Drop the holds.
  6. 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.

What happens when a session crashes A stale enabled status is found by the bridge, which challenges it. If a live session answers, the challenge is cancelled and nothing changes. If nobody answers, the bridge sets the signals to red, waits about three seconds, and releases them to the field logic. A stale "enabled" is found The bridge challenges it answered no answer A live session replieschallenge cancelled Signals set to red Wait about 3 seconds Released to the field
The crash path. If a live session answers, nothing changes. Red, then release, happens only when nobody answers.

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.

TopicDirectionWhat it does
track/bridge/sml_modeBoth waysThe 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 fieldWith 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 JMRIWhat 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/stateJMRI to bridgeJMRI's own online status. An offline report sets off the crash check.
track/bridge/statusBridge to allWhether the bridge program is online or offline. Retained.
track/bridge/cmdJMRI to bridgeBridge requests. Clicking the LCOS lamp sends RESUBSCRIBE here.
track/sensor/<n>Field to JMRIOccupancy 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 JMRIThe reported position of a switch. The LCOS mimic page can publish test values here too.
track/cmd/turnout/<n>JMRI to fieldA 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.

LampGreenRedAmberClick
LCOSBridge link establishedNot establishedClick 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.
TurnoutsAll two-sensor switches use feedbackAll in direct modeMixed, or a click pendingFlips all 40 between feedback and direct. From mixed, goes to feedback.
SignalsSignals onOff, or this session does not own themHand-off under waySame as the button. A watcher clears a stuck amber within about 20 seconds.
Track PowerOnOffPendingToggles 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