Author: David Duchamp
Keywords: java model railroad JMRI LogixNG

# JMRI: LogixNG Documentation

## Introduction to LogixNG

For those who have used Logix, it's important to note that LogixNG is similar, but different.

The main building blocks in LogixNG are actions and expressions. An action does something, for example throwing a turnout, set a signal or run a script. An expression asks a question, for example if turnout LT2 is closed, if sensor IS255 is active, or does an expression script return true or false.

The actions and expressions are organized in trees, each tree is a ConditionalNG. The ConditionalNGs are organized in LogixNGs.

An action or expression may have other actions and/or expressions as children, which allows the user to build a complex structure with simple building blocks.

For example, one common root of the tree is the If Then Else action. It has one child expression and two child actions. It evaluates the expression and if the expression is true, the then child action is executed. If the expression is false, the else child action is executed.

LogixNG, short for Logix Next Generation, is a complete rethink of the concepts used by Logix. It's modular, which means it's easy to extend LogixNG with new functionality and it's easy to test each part of LogixNG.

LogixNG have building blocks that are similar to Logix. A LogixNG is the same as a Logix. A ConditionalNG is the same as a Conditional. An expression in LogixNG is similar to a conditional variable in Logix and an action in LogixNG is similar to a conditional action in Logix.

Like the Logix indirect memory reference using @memoryname, LogixNG has references. A reference is an indirect pointer to an item on the layout. For example, if the memory IM1 has the value "IT1", the reference {IM1} points to the turnout IT1. This means that if an action has the command "set turnout {IM1} to thrown", it means that LogixNG reads the memory IM1, which in this example has the value IT1, and then sets the turnout IT1 to thrown.

LogixNG adds tables to JMRI. A table is similar to Memory but has one or two dimensions. Each row and each column in the table may be given a name, which means that a single cell in the table can be referred to with the row name and the column name. Tables are in particular intended to be used together with references, to make it easy to setup complex configurations. A table can be created in a spreadsheet software like Microsoft Excel or LibreOffice Calc and then exported as an CSV file and imported to JMRI.

The LogixNG Module is essentially a ConditionalNG, but there are different types with specific capabilities. This makes it possible to combine common expressions and actions. Modules can accept parameters and return results. When combined with references and tables, modules make it possible to create templates/subroutines/etc., that can be called from ConditionalNGs with the appropriate variables.

## LogixNG Components

The LogixNG tool has three main components. They are accessed via the main PanelPro Tools ⇒ Tables ⇒ LogixNG menu path like other JMRI table items. The three LogixNG tables and related content will be loaded and stored along with all of the other tables and panels. Note: The only content not stored are the CSV files used for tables.

The links in the following section, along with the links in the sidebar, are the task specific help pages that are also referenced using JMRI Help ⇒ Window Help.

### LogixNGs and ConditionalNGs

The LogixNGs menu item displays a list of LogixNGs. When a LogixNG item is selected, the ConditionalNG list is displayed. Clicking on the Edit button will open the ConditionalNG editor. This window contains a tree of the items that have been added to the conditional. The primary items are the expressions which act like if statements and actions to be performed. For details, see the following pages:

- LogixNG Table
- LogixNG Editor
- ConditionalNG Editor

### Modules

The LogixNG Modules menu item displays a list of modules. A module is similar to a ConditionalNG in that it also uses the tree based editor. The major difference is that information can be passed to a module and it can return results. For details, see the following pages:

- Module Table
- Module Editor

### Tables

The LogixNG Tables menu item displays a list of tables. The table feature was described in the introduction. For details, see the following pages:

- Tables Table
- Table Editor

## LogixNG Preferences

LogixNG has settings the can be set in JMRI Preferences ⇒ LogixNG.

Start LogixNGs on load
  If checked, the enabled LogixNG definitions will be active after the completion of the PanelPro xml data file loading. If not checked, the LogixNGs will be inactive until Tools ⇒ LogixNG ⇒ Start LogixNG is selected. The default setting is checked.
Install Debugger
  There is an option in the LogixNG editor list for debugging a CondditionalNG. This has to be enabled during start up to work.
Show system names and user names
  The LogixNG expressions and actions have names. These names are used internally by LogixNG. In certain developer situations, making the names visible can be helpful. The default is unchecked.
Highlight row in ConditionalNG editor
  When this option is enabled, the currently selected row will be highlighted. This can provide visual feedback, such as when the popup menu is open.
Error Handling Options
  LogixNG has robust error handling. The combo box selection provides the default setting. Individual expressions and actions can override the default setting. For details, see Error Handling

Note: LogixNG execution can be stopped using Tools ⇒ LogixNG ⇒ Stop LogixNG.

## LogixNG Tools

LogixNG has four system level tools at Tools ⇒ LogixNG.

Start LogixNG and Stop LogixNG are used to control the processing of LogixNG ConditionalNG defintions. When LogixNG is active , then the enabled LogixNGs will run its ConditionalNGs. Note: The execution of currently running ConditionalNGs doesn't stop immediately when "Stop LogixNG" is selected. The ConditonalNGs will continue to run until they are finished, but they will not be restarted after "Stop LogixNG" is selected.

The LogixNGs included in the LogixNG initialization table are run before the rest of the LogixNGs. This is the similar to the Logix RTXINITIALIZER.

Logix definitions can be be imported into LogixNG using Import Logix.

## Documentation

This document is an introduction and overview of LogixNG. The sidebar contains links to the task specific help files used by JMRI. The detailed documentation is in the reference.

The reference has two sections. The Standard Features section covers the LogixNG components that are similar to Logix. The Advance Features section covers new features that did not exist in Logix or were incomplete.

## Sample

This is a sample layout with LogixNG controlling the turnouts. The turnout sensors toggle the turnout state when clicked, unless the lock sensors are active

The logic uses a table to identify the turnouts, the toggle sensors and the lock sensors.

Each turnout has a ConditionalNG that is triggered when the toggle sensor is Active. A module is called to check the lock state and toggle the turnout. A variable is passed to the module that has the row number.

The module checks the lock sensor based on the row number and if ok, toggles the turnout state.

An initialization LogixNG is used to set the initial sensor and turnout states. This LogixNG is also triggered by the Reset sensor.