JMRI Hardware Support: MERGCBUS - Naming

This page describes how JMRI uses System Names to access MERGCBUS-attached resources.

Event Name and Numbering

Event Conventions

Suggestion from Mike Bolton :
His club has adopted the convention of 1 to 9999 for turnouts and 10000 upwards for sensors.
This prevents the possibility of sending sensor events from their CANCABs (9999 max)
but they tie any relevant sensors to the turnout numbers e.g.
TO_1 is +1 and the feedback from this is +10001 for one way and +11001 for the other way.
Using short events (or device numbers) this way makes life very simple with JMRI.
They control the turnouts from the CANCABs as well (also Smartphone throttles), this is reflected in the JMRI panel and works a treat!
Their layout control panel is on a touchscreen monitor connected to a RPi 3B running JMRI, with additional control panels through JMRI Web Server.

Another use of event segmentation could be for modular club layouts, where various club members building a section at home, then bringing it together into 1 big super layout.
Module 1 would have events 1,000 > 1,999 Module 2 would have 2,000 > 2,999 etc.

Event Polarity

You can invert the polarity of ON and OFF events

Start of Day Events

When JMRI is started, it doesn't presume that all sensors, turnouts and lights are active or inactive, they have an unknown status.

The vast majority of MERG module kits can send the current status of their inputs or outputs in response to a SOD event taught to that module.

JMRI can store cross-session information such as Memory Variables and Block Values ( Train Describer value )
The block will need to be occupied ( active sensor ) on panel startup for a TD to cross-session.

Sensors - JMRI Automatic Creation

JMRI automatically attempts to create Sensor objects from the traffic that it hears on the MERGCBUS network.

When JMRI hears an ON or OFF event, it creates a Sensor using the corresponding event ID.

This automatically-created sensor defaults to the ON event setting the Sensor ACTIVE and the OFF event setting INACTIVE.

Because events are not intrinsically associated with specific hardware objects, and because people can use event IDs in many ways, this doesn't do what's desired.

When it doesn't, you can manually create the proper Sensors using the Add... button on the Sensor Table.

Note that there's a MERGCBUS Event Capture Tool.

System Names

When adding an item to your JMRI Sensors Table, Turnouts Table or Lights Table, a JMRI system name is automatically created from the hardware address you input.

JMRI internally associates MERGCBUS events with individual JMRI objects (Sensors, Turnouts, Lights, etc.) via the JMRI System Names.

Depending on which MERGCBUS event IDs are used on a particular layout, these system names can get very long, in which case the "user names" are much more useful.

The 1st letter of a sensor, turnout or light system name is the JMRI system letter, generally "M" for MERG connections.

Summary of MERGCBUS events

In/Out Entered as Hardware Address Meaning makes System Name Mask Equivalent Min. Max. Notes
both 18 event 18 On;
event 18 Off
MT+18 integer +18;-18 01 65535 SLiM Short Events ASON / ASOF
both +N2E18;-N2E18 Node 2 Event 18; On Event = Active;
Off Event = Inactive
MT+N2E18;-N2E18 N1E1;
N 65535 E 65535 ;
N 65535 E 65535
FLiM Long Events ACON / ACOF
both 18;21 event 18 On;
event 21 On
MT18;21 integer;integer +18;+21 1 ; 1 65535; 65535
both +18;-21 event 18 On;
event21 Off
MT+18;-21 idem signed +18;-21
in 200018M07 listen to Events 18 .. 1F MS200018M07 + M + hex mask N/A
both X90002D002E;X91FFFFFFFE hex CAN frame msg. Active;
hex CAN frame msg. Inactive
MTX90002D002E;X91FFFFFFFE hex;hex N/A Depends on Opscode In eg. Thrown sends Long Event N 45 E 46
Closed sends Long Event N 65535 E 65534
both +18 event 18 On;
event 18 Off
MT+18 +18;-18
both 018 event 18 On;
event 18 Off
MT+018 +18;-18
both 200018 Node 2 Event 18; On Event = Active;
Off Event = Inactive
MS200018 node + (5 digits) N2E18 100001 6553565535 Current max. that can be entered (JMRI 4.12) is 2147483647
both N2E18 Node 2 Event 18; On Event = Active;
Off Event = Inactive
MTN2E18 N + number + E + number 2000018 NOT WORKING
See if able to add / edit logic as mix of 2 top table rows?

65,536 nodes and 65,535 events gives approx 4,294,901,760 event combinations.

65,535 is unrealistic for events within a node but does allow for useful segmentation of event ranges.

MERG module kits can use the whole CBUS range of event numbers, on a reset startup operating in SLiM short event mode.
A MERG CANLED kit can support up to 255 taught events

Event Naming Specification

A Sensor is defined by two events: The one that sets it ACTIVE, and the one that sets it INACTIVE.
If these are mapped to ON and OFF frames with the same event ID number, respectively, only the event ID number need be specified:
MS18 The number is decimal.

To increase versatility, it's possible to use different event ID numbers for the ACTIVE transition (by default, an ON frame) and INACTIVE transition (by default, an OFF frame):

The ON and OFF coding of MERGCBUS is not entirely consistent with the event model,
it may be useful to connect the ACTIVE or INACTIVE transition of a JMRI Sensor to an OFF or ON MERGCBUS frame respectively.
Leading "+" and "-" characters can do this. For example,
defines a sensor that goes ACTIVE when an OFF frame with ID number 18 is received,
and goes INACTIVE when an ON frame with ID number 21 is received.

MERGCBUS event numbers (usually) contain a node number in their most-significant bytes.
You can specify the node number either by using a full 5 decimal digits for the event number itself, preceded by the node number:
or by using the letters "N" and "E" to specify the separate parts:

You can mask off part of the MERGCBUS packet, so any values in the masked part will still match, using the "M" format letter.
"M" indicates the start of a hexadecimal mask that will be applied, where 1 bits in the mask will be zero bits in the resulting value.
In the example above, "18" through "1F" will match.
This is particularly useful for matching e.g. MERGCBUS short events, where parts of the packet include the node number which should (usually) be ignored.

Sending hex strings

Hexadcimal numbering is based on the power of 16, using 0-9, then A-F.

MERGCBUS modules communicate by messages with a fixed format: One byte of command and length information, followed optionally by additional data bytes.

In it's most simple form, this is used to send identifiable "events". In turn, events come in two types: "ON" and "OFF", with two forms, short ( SLiM ), and long ( FiLM ).

These are actually sent across a MERGCBUS network in the form of an Opscode, the command information.

There are 255 ops codes, the length of the data string following the Opscode changes depending on which Opscode is used.

There are multiple Opscodes for events, Controlling and programming DCC devices, DCC consisting, Programming nodes with Node Variables, Programming nodes with events, Fast clock and temperature information, RfID reader data, and many more.

Four of these are the common Opscodes for events :

Ops Code Name
( MERG console log )
ASON 152 98 Short Event On
ASOF 153 99 Short Event Off
ACON 144 90 Long Event On
ACOF 145 91 Long Event Off

It's possible to connect a Sensor to arbitrary CAN frames by specifying their data content as a hex string, indicated by "X".

This allows a Sensor or Turnout to disregard any intrinsic meaning to "ON" and "OFF" events, and allows it to respond to, or emit any frame on the layout.

These particular event Opscodes use a Hex string 4 digits long, split into High then Low :

merg cbus add new turnout hexadecimal hex
Entered as Hex Ops Code Remaining Hex Node Decimal Event Decimal
X9900000013 ASOF 00 00 00 13 0 19
X980000002D ASON 00 00 00 2D 0 45
X980000BD2A ASON 00 00 BD 2A 0 48426
X990000FFFF ASOF 00 00 FF FF 0 65535
X9100130013 ACOF 00 14 00 13 20 19
X90002D002E ACON 00 2D 00 2E 45 46
X90BD2BBD2A ACON BD 2B BD 2A 48427 48426
merg cbus server

Ensure you use the right opscode, eg if you include Nodes for a FiLM address, use ACON instead of ASON.

For system development, you may prefer to view the actual full packet in an application such as MERG CBUS SERVER.

The JMRI MERGCBUS Console Tool can be very useful in seeing what is being sent across the network by the hardware addresses you create.
The console is intended to be a tool to help users monitor packets using short and long events, and may attempt to beautify the output.

The CAN frames can send MERGCBUS opscodes in the hex form of the code you require.
eg, to set up a sensor to send ( DCC emergency stop / Track power on ) opscodes over MERG CBUS,
you could use a hardware address of X0A;X05

Entered as Hex Viewed in JMRI MERG CONSOLE Viewed in CBUS SERVER Ops Code
X0A [x[7f]0A] S0FE0N0A; (RESTP) Request Emergency Stop ALL trains
A MERG CANCMD confirms request with an ESTOP 06 Opscode.
X05 [x[7f]05] S0FE0N05; (TON) Track Power On, normally broadcast from a command station

All of these Opscode messages are sent with the Standard CAN event frame, however the protocol also allows for access to extended CAN frames.
These frames enable bootloading of modules ( firmware updates ), while future uses of this may also be for local media streaming ( eg. transferring pictures of trains or sound files between modules. )
The extended frames do not interfere with the standard frames, hence modules can be targetted for boatloading by module number, without affecting Standard CAN event frames.

Although module firmware updates are not currently available within JMRI, full support for this is available via 3rd party software ( FCU - FLiM Configuration Utility ), available free for MERG members to download.

Check the MERGCBUS wiki and developers guide for more info and absolute specification.


Main JMRI MERGCBUS Support page.

JMRI Scripting for CAN frames with

MERGCBUS 3rd Party Links See link for the MERGCBUS Developers Guide