LogixNG Tutorial - Chapter 10

# LogixNG Tutorial - Chapter 10 ## Tables - working with templates The panel "Chapter 10 - Tables" has four yards: North yard West yard East yard South yard The first three yards are identical and the forth yard has an extra siding. Each track has a sensor that detects if the track is occupied or not and each turnout has a signal mast. The rules for these yards are: If the track that the turnout is pointing to is occupied, the mast should show "Stop". If the track that the turnout is pointing to is the main line, the mast should show "Slow Clear". If the track that the turnout is pointing to is not the main line, the mast should show "Slow Approach". These rules and the placement of the signals may be not be prototypical, but the purpose of this example is to show how to setup the rules in LogixNG. ## How to create one ConditionalNG that controls all four yards? Lets create an imaginary template yard. It will have three turnouts, three signals and three sensors. First we need to give the named beans on the template yard unique names. In this example, we have these names for the named beans in the template yard. Track 1 is the main track. Left turnout Middle turnout (only used for the South yard) Right turnout Left mast Middle mast (only used for the South yard) Right mast Sensor track 1 Sensor track 2 Sensor track 3 (only used for the South yard) LogixNG has support for CSV tables, comma separated tables, but LogixNG needs the tables to be TAB-separated. These files can created by a spreadsheet software, for example Open Office or MicroSoft Excel, and then exported as a CSV file. We can create a CSV file with a table of the yards and their named beans. For example, you can let each column represent each yard and let each row represent each named bean.
| North yard | West yard | East yard | South yard
Left turnout | IT_10_1 | IT_10_3 | IT_10_5 | IT_10_7
Middle turnout |  |  |  | IT_10_9
Right turnout | IT_10_2 | IT_10_4 | IT_10_6 | IT_10_8
Left mast | Mast_10_1 | Mast_10_3 | Mast_10_5 | Mast_10_7
Middle mast |  |  |  | Mast_10_9
Right mast | Mast_10_2 | Mast_10_4 | Mast_10_6 | Mast_10_8
Sensor track 1 | IS_10_1 | IS_10_3 | IS_10_5 | IT_10_7
Sensor track 2 | IS_10_2 | IS_10_4 | IS_10_6 | IT_10_8
Sensor track 3 |  |  |  | IT_10_9
#### Important The first row in the table has special meaning. Leave the first row empty for now. The second row has the headers for the columns. The first column has the headers for the rows. The CSV files LogixNG uses must be separated with tab, not comma. In OpenOffice Calc, select {Tab} as the field delimiter. You must not use single or double quotes in the CSV table. OpenOffice Calc uses different single quote characters at the beginning of a word and at the end of a word, and if you store a csv file with these, you might end up with non readable characters in the csv file. OpenOffice Calc also writes non readable characters for double qoute characters to the csv file. Also, don't use backspace in the csv file. It might later be supported to quote other characters so it's reserved for now. ### Using the "Table: For each" action aa aa ### Using the "Listen on beans" action References can not listen on beans, simply because LogixNG can not know in advance which bean a reference will point at. So how do LogixNG knows when the turnouts and sensors change state? For that, we must explicity tell LogixNG to listen on these turnouts and sensors. For this purpose, there is a very special action, "Listen on beans". It doesn't do any action, but it listen on some beans and triggers execution of the ConditionalNG when one of the beans it listens to changes state. To make it easy to use "Listen on beans", you can tell "Listen on beans" to listen on every bean in a row or column of a table. So in this example, we tell "Listen on beans" to listen on all beans in the rows "Left turnout", "Middle turnout", "Right turnout", "Sensor track 1", "Sensor track 2" and "Sensor track 3". ### Using comments in the table It's useful to be able to add comments in the table, especially for large tables. Therefore LogixNG has a simple way to add comments to tables. If the header of a row or column is empty, LogixNG treats that row or column as a comment. So if you want to add a comment on a row, leave the first column on that row empty. And if you want to add a comment on a column, leave the first row on that column empty. If the first cell on a row or column is empty, the action "Table: For each" will skip that row or column entirely. Example:
| North yard | West yard | East yard | South yard
| We have a couple of turnouts |  |
Left turnout | IT_10_1 | IT_10_3 | IT_10_5 | IT_10_7
Middle turnout |  |  |  | IT_10_7
Right turnout | IT_10_2 | IT_10_4 | IT_10_6 | IT_10_8
| And we have a couple of signal masts |
Left mast | Mast_10_1 | Mast_10_3 | Mast_10_5 | Mast_10_7
Middle mast |  |  |  | Mast_10_9
Right mast | Mast_10_2 | Mast_10_4 | Mast_10_6 | Mast_10_8
| And also some sensors |  |
Sensor track 1 | IS_10_1 | IS_10_3 | IS_10_5 | IT_10_7
Sensor track 2 | IS_10_2 | IS_10_4 | IS_10_6 | IT_10_8
Sensor track 3 |  |  |  | IT_10_9
In this example, we have comments before the turnouts, before the signal masts, and before the sensors. And to make the table easier to read, we have added empty lines above the comments as well. Both the actions "Table: For each" and "Listen on beans" will skip both the empty lines and the comment lines, since the first cell on these rows are empty. ### Using the Reference expression One problem remains. In our example, we have a turnout, a mast and a sensor that only exists in one of the four yards. In some cases, this may cause problems. Therefore, there is a special expression in LogixNG, "Reference", that can evaluate the reference itself. By using "Reference", we can check if a reference is valid and do something only then. In this case, we use "Reference" to check if "Middle turnout" is a valid turnout and only then controls the track 3 with "Middle turnout", "Middle mast" and "Sensor track 3". ### Note Note that a reference can point to another reference that points to a bean. This means that we can have a table that points to another table that points to the bean.