LogixNG Tutorial

# LogixNG Tutorial This tutorial has an example profile. This tutorial has a number of chapters, there each chapter demonstrates some feature of LogixNG. Each chapter has its own ConditionalNG in the example profile, and this ConditionalNG has the end result of each chapter. The sensors, turnouts, and so on, that's used in this tutorial has system names like IS_3_5, there the first number is the chapter it's used in. Some chapters has a panel and the panels has names like "Chapter 1", that tells which chapter this panel is used for. Chapter 0 - Setting up the profile Chapter 1 - A simple LogixNG Chapter 2 - The clipboard Chapter 3 - Basic actions and expressions Chapter 4 - Working with timers Chapter 5 - Controlling an engine Chapter 6 - Formula Chapter 7 - Sequence - controlling a crane and a loco Chapter 8 - Local variables Chapter 9 - References Chapter 10 - Tables Chapter 11 - Modules Chapter 12 - Scripts Chapter 13 - Threads Chapter 14 - The debugger Chapter 15 - Error handling Chapter 16 - Preferences Chapter 19 - Some examples ## Notes for developers The rest of the chapters are aimed at developers of JMRI. These chapters explains the internals of LogixNG and how to use LogixNG from other parts of JMRI. Chapter 21 - Adding a new action or expression Chapter 22 - The future of LogixNG - Expanding it further Chapter 23 - Using LogixNG in other parts of JMRI or by third party software If you are developing some tool, for example something similat to SSL or SSM, and you want to use LogixNG as the engine, there are some things that's good to know. Chapter 99 - Note to reviewers of JMRI. When to merge LogixNG? Chapter 99 - Note to reviewers of JMRI. When to merge LogixNG? Menu choice "Tools / Tables / LogixNG" has a sub menu with three tables: LogixNG LogixNG Modules LogixNG Tables Select "Tools / Tables / LogixNG / LogixNG" to open the table with the LogixNGs. The other two tables, "LogixNG Modules" and "LogixNG Tables", are described later in this tutorial. On the "Meny" column, select "Edit" for the "Tutorial LogixNG". This brings up a table of ConditionalNGs that are owned by this LogixNG. Each ConditionalNG in this tutorial has a user name starting with a number and a short description. These user names are used as headers in this tutorial and demonstrates different things in LogixNG. ## 1. Basics Create a LogixNG Create a ConditionalNG Create an action: ActionTurnout Remove the action and add the action IfThenElse. Add ExpressionSensor and ActionTurnout Lets add a new IfThenAction with a ExpressionSensor and a ActionTurnout. To do this, we need to add the action Many. We can do this by cutting the IfThenElse expression so it's moved to the clip board, then add the Many action and then paste the IfThenElse action back. ## 00. Trigger once Something may need to be done once to initialize things. For this purpose, there is the TriggerOnce expression that returns true once and never more. This expression can be used to initialize things. ## 10. Working with timers Logix has a feature there a turnout or a sensor can be set delayed. This feature is not yet implemented in LogixNG, except that you can use timers to do this in LogixNG. The reason for this not beeing implemented yet is that I'm not sure how to implement this the best way. It's definitely possible to implement this the same way as in Logix, but since LogixNG works somewhat different, it may be better to implement it different in LogixNG than in Logix. When the IS_10_1 sensor is active, the timer is started/reset. But as long as this sensor is active, the timer is hold in the start condition. What if we want the sensor to only trigger a start, instead of holding it in the start condition? We can do that by using the "Trigger Once" expression. It returns true the first time its child expression returns true, but when returns false until its child expression has returned false. ## 11. Controlling an engine An exhibition has a model railroad that children can run. An adult presses a button and then a child can control the layout by using a potentiometer and a switch for controlling the speed and direction of the engine. After five minutes, the layout stops and the next child in queue will get to run the layout. The adult presses the button and the layout works for five more minutes. Sensor IS1 - The button the adult presses to run the layout. Memory IM1 - For this example, we use a memory, but in real world we would use an AnalogIO, for example a Meter. Sensor IS2 - Sensor for controlling the direction of the engine. Memory IM2 - The loco address. Memory IM3 - Flag if the layout is running or not. We use an ActionTimer to let the child run the layout for five minutes. We use an ActionThrottle to control the engine.