MBLogic for an open world in automation
The purpose of a soft logic system is to run programs written in programming languages used by PLCs. The following describes the format and structure of these programs.
PLC programs are typically displayed in either ladder (LAD) or instruction list (IL). However what, a PLC or soft logic system actually executes is actually IL (or something close to it). Ladder is simply a graphical means of displaying IL. This system therefore works directly with IL. Displaying as ladder is the responsibility of the programming software, not the soft logic system.
The file format used is plain ASCII text files. These may be created using any text editor capable of creating plain text files.
Program source files must be in plain ASCII text with one instruction per line. Each line must be separated by a newline character.
Although the soft logic system generates intermediate forms of the program before executing, these are not stored permanently. Only the plain source format is kept and used each time the system is started or the program reloaded.
The name of the file used to store the soft logic program source code is defined in the soft logic configuration system. See the documentation on that feature for more details on this subject.
A complete program must be in a single file, and this file must contain all subroutines referenced by the program.
The following defines some general rules which must be followed when writing soft logic programs.
Comments are defined by the comment symbol "//". The comment symbol must be followed by a space. Comments must start at the beginning of a line. Anything following a comment symbol on the same line is ignored.
// This is a comment. // And this is another comment.
PLC programs are normally separated into "rungs" or (in IEC terminology) "networks". In this soft logic system, a rung symbol is an instruction and executes code which prepares the system to execute the IL code contained in the rung and also stores diagnostic information.
Rungs are normally numbered, although the rung numbers used can be arbitrary and in any order. They may even be duplicated. However, since the system stores the rung numbers to provide diagnostic information in the event of an error, it is normally advantageous to use unique, ordered rung numbers in a program. Empty rungs are permitted.
// This is a rung. NETWORK 14 STR X1 AND C2 OUT Y33 // This rung is empty. NETWORK 15 // And this is another rung. NETWORK 16 STR X14 OUT Y12
Anything which is not a comment is treated as an instruction (including the start of rungs or networks). Instructions must follow these rules:
Each instruction must either have a unique symbol or be able to be uniquely identified by its parameter types. It must not rely on the context of other adjacent instructions to identify it. When an instruction is capable of accepting multiple incompatible parmeter types, each varient is considered to be a different instruction. When loading a soft logic program, the soft logic system will search its list of valid instructions for the first one which matches both the instruction symbol and the parameter types. If no match is found, it is considered to be an unknown instruction.
// This is just an example and may not match any particular PLC. // This is an instruction using a boolean variable. AND X1 // This is a different instruction using a word variable. AND V10000 // This is a different instruction using a pointer variable. AND P10000 // This is a different instruction using a constant. AND K1234 // This is an invalid instruction as the parmeter type does not match. AND R10.5
The soft logic system treats all data table addresses as "labels". An address label is considered to be an arbitrary name with no significance other than as a unique identifier. This means that the soft logic system does not attempt to infer relationships between addresses based on any numbers contained in the address label. This allows the system to deal with different address formats without having to "understand" them.
This also means however that addresses which may have the same "numerical" value but which are written differently are treated as differnt addresses. For example, "X1" and "X01" are considered to be different addresses. Therefore, programs must be written to a single form of each address.
// This instruction is using a valid address. STR X1 // The address used with this instruction is not recognised. STR X01
When the system starts to read in a soft logic program source file, the first instructions encountered are considered to be part of the "main" routine. If no subroutine instruction is encountered, then the entire program is considered to be a single "main" routine.
The start of a subroutine is indicated by the "instruction" which defines the start of a subroutine. All code following a subroutine instruction is considered to be part of that subroutine until either a new subroutine instruction is encountered, or until the end of the source file.
This means that all subroutines must be at the end of a file, and that subroutines may not be nested (you may not define a subroutine inside another subroutine).
// This is the start of the main routine. NETWORK 1 STR X1 OUT Y1 // This calls a subroutine. NETWORK 2 STR X31 CALL Sub1 // The program scan ends here. NETWORK 3 END // ################################ // This is a subroutine. SBR Sub1 NETWORK 1 STR Y1 AND Y2 OUT C16 RT // This is the end of the program.
The following shows a simple program.
Example:
// Demo program for soft logic. // This is a counter. NETWORK 1 STR X1 STR SC1 CNTU CT100 50 // This is a timer NETWORK 2 STR SC1 TMR T5 329 ms STR T5 OUT Y367 // This calls a subroutine. NETWORK 3 STR T5 CALL Sub1 // This just executes some ladder logic. NETWORK 4 STR SC1 ORN C2 AND X17 OUT Y1 END // This is a subroutine. SBR Sub1 NETWORK 1 STR SC1 MATHDEC DS100 0 SQRT(DD1 + 25) STRGE DS100 1 OUT C50 RT