JMRI Hardware Support - BiDiB
Author: Eckart Meyer
Keywords: BiDiB java model railroad JMRI install

# Hardware Support: BiDiB

(german version here)

- Summary
- Hardware
- Limitations
- Connecting
- JMRI Tools
- Documentation

## Summary

BiDiB® stands for BiDirectional Bus for the digital control of a model train. The term BiDiB® itself refers to the protocol technology, which can be implemented on various physical connections, such as Ethernet, USB or the BiDiBus, which is particularly optimized for the needs of model railroaders and system wiring.

BiDiB is not a commercial product and not connected to any particularly hardware. It is a protocol definition which can be implemented by anyone including commercial manufacturers.

BiDiB started in 2010 and was developed by Wolfgang Kufer (opendcc.de). For more information BiDiB see bidib.org.

BiDiB features:

- Bidirectional data transfer. Thus suitable for controlling locos, accessories and lights as well as for receiving occupancy feedback and other input.
- Binary data transfer secured by a CRC checksum.
- The Interface ("root node") of a BiDiB network is directly connected to JMRI using a serial-over-USB connection with either 9600 Baud, 115200 Baud or 1MBaud.
- A node on the network can implement various functions. One node can be the command station controlling the track-signal (probably DCC).
- Nodes supporting macro functionality can be configured to e.g. implement a complete signal head accepting just the requested aspect.
- BiDiB supports notifying of loco addresses if RailCom® enabled decoders are used (JMRI Reporters).
- BiDiB notifications are event driven. No polling is used.

## Supported Hardware

Any hardware which implements BiDiB. See "Third Party info" below.

## Limitations

BiDiB for JMRI is currently beta stage - some functionality may be missing and there are surely a lot of bugs.

## Connecting

### Wiring

Currently JMRI has support for connection over USB, BiDiB over TCP and there is a BiDiB-Simulator which is configured by a XML file.

Open the Connections tab, select "BiDiB" from the System Manufacturer selection box and choose from the following setups. The system letter for BiDiB connections is "B".
Note that BiDiB supportes hotplugging on the BiDiBus, this is also supported in JMRI-BiDiB. If a node gets lost, all objects which refer to this node are invalidated, but not removed. If a new node was found, all invalid objects are checked if they can be activated again.

#### Serial over USB

To create a new connection either the port name (e.g. ttyUSB0 on linux or COM1 on Windows) can be selected or the root node UID can be typed in directly. Since UIDs are worldwide unique and do never change for a given hardware, the appropriate port can be found automatically by scanning all usable ports. On Windows all ports COMx are scanned, on Linux and macOS a name filter may be used (default is "ttyUSB*"). When the connection is created by selecting a port from the list of available ports, the UID read from the device is displayed and stored - if the device is a BiDiB node. A checkbox (Autoscan) can be activated so that when JMRI starts again, the port can be found by scanning the available ports. Thus, if more than one BiDiB connection is used, the port naming of the USB device does not matter.

#### netBiDiB

netBiDiB allows the transport of the BiDiB protocol over a network connection (TCP). The connection is authorized once through the pairing process, so that a device cannot simply be controlled by someone else. To simplify configuration, BiDiB devices should announce themself in the network (mDNS/Bonjour) and can be selected in a combo box field in the JMRI settings for BiDiB. If this discovery is not available, automatic configuration can be switched off and the IP address of the device entered manually. The standard port number is 62875. JMRI supports a continuous keep-alive test (local ping) so that connection drops are quickly detected. Since not all BiDiB devices support this, it can be configured in the connection settings under "Keep-Alive."

#### BiDiB over TCP

In this case the hardware is not directly connected to JMRI, but JMRI connects to a TCP server which in turn connects to the hardware. This may be usefull if another program is used as the main control program and JMRI is only used as a CV programmer (decoder pro). The parameters are the IP-Address and the port number of the server to which to connect to. The default port number is 62875.

#### Simulator

A BiDiB simulator is provided. This connection type has a field for a XML file with the simulated configuration. The location for this file is the profile directory.

### Settings

Dialog for the serial interface:

Dialog for netBiDiB with discovery (Automatic Configuration):

#### BiDiB Naming

JMRI System Names generally consist of a system connection prefix Xn where X is the system connection letter and n is either empty or a number for multi-connections, followed by the type letter ("T" for turnout, "L" for lights, "S" for sensors and "R" for reporters (loco address feedback) and the system address.

For BiDiB the system connection letter is "B", the system address is a string with the BiDiB address.

The BiDiB address generally has the form:

`node:address`

A node on the BiDiBus is identified either by its worldwide unique identifier (UID) which is a 40 bit hexadecimal number or by a user name configured into the node (using BiDiBWizard). The hexadecimal UID must start with an "X", usernames must start with a letter (better not to start with "X") and must contain only other letters, numbers, underlines ("_") or dashes ("-"). This is a restriction of JMRI for BiDiB not for BiDiB itself. The node specification is case independent.

The node part of the address may be omitted (including the colon), in this case the interface (root node, i.e. the BiDiB node directly connected to JMRI) is used automatically.

The address on the node may be prefixed by a single letter address type and - for port addresses only - a single letter port type may follow. The number is required and the two letters are optional. If omitted, suitable defaults will be selected depending of the capabilities of the node: only a command station has DCC addresses, Turnouts are preferable accessories and Lights are preferable ports (digital pins of the device). So the general form of an address on a node is:

`xny`

where x is an optional address type, n the numeric address and y is the optional BiDiB port type.

The term "turnouts" in JMRI does not necessarily refer to actual turnouts, but rather to a general hardware I/O port that can have two states, on and off. In BiDiB, switches should not be controlled directly via the ports, but addressed as accessories. This selection is made using the address type letter.

List of address types:

Letter | Description | Default Type for
--- | --- | ---
t | DCC accessory address ("track") | turnouts and sensors if node is a command station (CS). Illegal on non-CS nodes
a | (non-DCC) accessory address | turnouts if node is not a command station and the node supports BiDiB accessories
f | Feedback number | sensors if the node has BiDiB feedbacks. Reporters are only valid for nodes which support feedbacks, so always default
p | port number | lights. For sensors if the node does not support feedbacks

List of BiDiB port types:

Letter | Designation | Description
--- | --- | ---
S | SWITCHPORT | Simple digital output. Either ON or OFF.
L | LIGHTPORT | Control of a digital output with various functions like dimming, blinking, etc. Controlled by a state value (similar then aspects for signals)
V | SERVOPORT | Control of a connected servo. Start- and end position are configured in the node as well as transition time.
U | SOUNDPORT | not supported in JMRI for now
M | MOTORPORT | not supported in JMRI for now
A | ANALOGPORT | not supported in JMRI for now
B | BACKLIGHTPORT | not supported in JMRI for now
P | SWITCHPAIRPORT | not supported in JMRI for now
I | INPUTPORT | Default for sensors. Invalid for others.

Examples (the root node is assumed to be the command station and to have the UID 0d68001234 and "MyNode" is the user name):

System Name | Type | Address Part | resulting Node UID | resulting Address | Notes
--- | --- | --- | --- | --- | ---
BSX0d68001234:20 | Sensor | X0d68001234:20 | 0d68001234 | f20 - feedback 20 | BiDiB feedback 20 of (interface) node 0d68001234
BSMyNode:42 | Sensor | MyNode:42 | 0d68001234 | f42 - feedback 42 | BiDiB feedback 42 of (interface) node 0d68001234 named "MyNode"
BT5 | Turnout | 5 | 0d68001234 | t5 - DCC address 5 | turnout at DCC address 5 of CS node (interface node) 0d68001234
BTN201:22 | Turnout | N201:22 | 0d68006789 | a22 - accessory address 22 | turnout at BiDiB accessory address 22 of non-CS node 0d68006789 named "N201"
B1LLC6:8L | Light | LC6:8 | 0d68004321 | p8L - Port 8 | Light at output port 8 (type based address model) of node 0d68004321 named "LC6" on second BiDiB connection (B1)
BLN201:15 | Light | N201:15 | 0d68006789 | p15L - port 15 | Light at output port 15 (flat address model) of node 0d68006789 named "N201", port has to be configured as LIGHT
BSX0d68006789:3 | Sensor | 0d68006789:3 | 0d68006789 | p3I - port 3 | Sensor at input port 3 (flat address model) of node 0d68006789 (without feedbacks), port has to be configured as INPUT
BR42 | Reporter | 42 | 0d68001234 | f42 - feedback 42 | Railcom-feedback on feedback number 42 of (interface) node 0d68001234

#### Sensors

BiDiB Feedbacks and input ports are mapped to sensors.

#### Turnouts

BiDiB accessories are the equivalent of turnouts. Both signal lamps and actual turnout (track switches) may refer to JMRI turnouts. However, signals should be operated by "signal masts" (see below)

#### Lights

BiDiB Ports are normally mapped to Lights.

BiDiB ports support either a flat addressing model or a type based addressing model. The address model is determined by the firmware of the node. In the flat addressing model all available ports are simply numbered from 0 to the number of ports minus 1. Each port must be configured in the node (e.g. by using the BiDiBWizard) as one of the port types mentioned above which is supported by the hardware itself. In this case the port type letter in the JMRI system address is not neccessary since the type is read from the node.

If the node uses the type based addressing model, port types are hardcoded into the firmware and cannot be changed. Each port type has its own address range starting from 0 up to the number of ports for this type minus 1. In this case the port type is part of the port address and the port type letter is required in the BiDiB address. See the examples above.

#### BiDiB Signal Masts

A Signal Mast type for BiDiB Accessories is provided, where a JMRI ascpect can be directly mapped to a BiDiB accessory aspect. Aspect appearence can be programmed into the BiDiB Node with macros using the BiDiB-Wizard. Other Signal Mast types (e.g. the Matrix type) may map to turnouts.

#### Reporters

Sensors which support loco address feedback report this address to a JMRI reporter. Each reporter address has a feedback address with the same number.

## JMRI BiDiB Tools

When JMRI is connected to a layout via this system, an BiDiB menu is shown:

- Traffic Monitor
- Start/Stop BiDiB over TCP server
  the server listens to port 62875 for incoming clients, forwards all messages from the client to the system connection and sends all response messages comming in from the connection to all connected clients. This is something like the opposite of the "BiDiB over TCP" system connection mentioned above.
- netBiDiB Logon/Logoff (netBiDiB only)
  JMRI is logged on/off on the connected device. Logging off can be useful to allow another program (e.g. the BiDiB Wizard) access to the device. After logging off of the other program, JMRI can be logged on again.

### BiDiB Wizard

BiDiB hardware can usually be configured in many aspects including definition of macros. This is not in the scope of JMRI. Instead there is the BiDiBWizard.

The BiDiBWizard is an external tool - also written in Java and uses the same underlying BiDiB-library (jbidibc - written by Andreas Kuhtz).

This tool is used to configure all node parameters, e.g. node user name, the port configurations and many other parameters. Therefore no other configuration tool is integrated into JMRI. The BiDiBWizard can be connected to the BiDiB over TCP server mentioned above.

## Documentation

### Third Party info

BiDiB home page: english or german

BiDiBWizard: unfortunately currently in german only.

#### BiDiB Manufacturers

The developers of BiDiB sell modules in the Fichtelbahn shop (german only).

There are some other manufacturers - see www.bidib.org/vendors_e.html