1. The use of software components in functional blocks
1. The use of software components in functional blocks
In user implemented function blocks, in addition to calling function parameters and local variables, software component registers can also be directly used like ladder diagrams.
1.1. 1. Variables of software components
Each software component base address has a corresponding global variable name in the function block. For example, the global variable of a soft component with a base address of M is MBit, and the global variable of a soft component with a base address of D is DWord, both of which are considered pointers. M0 can be represented by MBit [0], D0 can be represented by DWord [0], and so on.
X. The Y component is "octal", but the addresses of variables are decimal, arranged in sequence. For example, X7 is followed by X10, but after the variable XBit [7], XBit [8] represents X10, XBit [9] represents X11, with no interval in between.
The following are the base addresses and corresponding variable names for all software components.
| base address | variable name | type | example |
|---|---|---|---|
| X,Y,M,S,C,T | XBit,YBit,SBit,CBit,TBit | BIT(uint32_t*) | XBit[8]express X10 MBit[800]experess M800 |
| D,CV,TV,AI,AO,V,Z | DWord,CVWord,TVWord,AIWord, AOWord,VWord,ZWord | WORD(int16_t*) | DWord[60]express D60 AIWord[0]express AI0 |
| CV32 | CVDoubleWord | DWORD(int32_t*) | CVDoubleWord[35]express CV235 CVDoubleWord[51]express CV251 |
1.2. 2. Expansion module software components
The base addresses and corresponding variable names of the extension module software components are shown in the following table:
| Base address | variable name | type | example |
|---|---|---|---|
| X,Y | EXBit, EYBit | BIT(uint32_t*) | EXBit[0]表示X1000 EXBit[64] express X1100 ``` EXBit[448]express X1700 |
| AI,AO | EAIWord, EAOWord | WORD(int16_t*) | EAIWord[0]express AI100 EAIWord[10] express AI110 ``` EAI[70]express AI170 |
1.3. 3. Example
For the following ladder diagram program:
图1 LAD program
Similarly, function blocks can also be used to implement:
图2 C language program
The above two programs are logically equivalent.
Note that this is only a demonstration case and does not represent that all ladder diagram programs can be replaced with function blocks
1.4. 4. Simplify usage
You can add a feature [Simplify ("Register")] at the beginning of the function to enable input simplification for software components.
图3 Simplified Effect
Equivalent to the ladder diagram program in the example.
This feature can greatly simplify code according to certain syntax rules, including operations such as variable addressing and type conversion, which can be implemented using concise syntax.
1. Register variable access。 For example, D0V0, if written as DWord [0+VWord [0] in C language code, can be directly written as D0Z0 if simplified features are added.
2. The use of special types of registers。 In C language, it is necessary to go through the complex steps of taking addresses, converting address pointers, and taking values. For example, if D0 is used as a double word, it would originally need to be written as * (WORD) (DWord+0), but with the addition of simplification features, it can be written as DD0, greatly improving programming efficiency.
The following table compares the original code with the simplified code.
| Simplified code | Simplified code |
|---|---|
| DWord[0] | D0 |
| DWord[0+VWord[0]] | D0V0 |
| (DWORD)(DWord+10) | DD10 |
| (FLOAT)(DWord+20) | FD20 |
| (UWORD)(CVWord+5) | UCV5 |
| (UDWORD)(DWord+20+ZWord[2]) | UDD20Z2 |