Data exchange between A4 and A5/A6 controllers with CODESYS V2
Apply for CODESYS V2 and affects the data transfer of structures with different elements (for example BOOL, WORD …) between
Different memory alignment
After compiling and transferring plc programms to the controller, variables occupy internal memory of the controller:
Type of variable |
Minimum memory requirement in the internal memory |
---|---|
BOOL |
1 bytes |
BYTE |
1 bytes |
WORD |
2 bytes |
DWORD |
4 bytes |
REAL |
4 bytes |
LREAL 1) |
8 bytes |
1) |
LREAL variables must not be exchanged between |
For structure variables, several variables are combined into data structures. These structures occupy different areas (compiler-dependent) in the internal memory of a controller. The programming software CODESYS uses different compilers for the controllers
The A5/A6 controller compiler stores data in succession in the internal memory, regardless of the data type.
The
- A variable from the WORD type is in an internal memory area whose byte index is divisible by 2 without a remainder.
- A variable from the DWORD type is in an internal memory area whose byte index is divisible by 4 without a remainder.
- A variable from the REAL type is in an internal memory area whose byte index is divisible by 4 without a remainder.
- A variable from the BYTE type is stored in any internal memory.
- A type BOOL variable occupies one byte and behaves like the BYTE type.
Example:
An assumed structure from an A5/A6 controller should be transferred to an
Exemplary assumed structure variable:
Structure content |
Internal memory |
|
---|---|---|
Variable name |
Type of variable |
Memory requirement in the internal memory |
boVar1 |
BOOL |
1 bytes |
dwVar2 |
DWORD |
4 bytes |
byVar3 |
BYTE |
1 bytes |
wVar4 |
WORD |
2 bytes |
Alignment in the internal memory [bytes] |
0 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
---|---|---|---|---|---|---|---|---|---|---|---|---|
A5/A6 controller |
boVar1 |
dwVar2 |
byVar3 |
wVar4 |
||||||||
|
boVar1 |
|
dwVar2 |
byVar3 |
|
wVar4 |
As long as structure variables are not exchanged between different controllers, the internal memory allocation is not relevant for the user.
If data is exchanged between the controllers
Proposals for solutions, shown by example
The data in the transmitter must be arranged so that it can also be correctly assigned in the memory alignment of the receiver.
The structure content in the example must be changed as follows in order to adapt the data alignment to the receiver.
Alignment in the internal memory [bytes] |
0 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
---|---|---|---|---|---|---|---|---|---|---|---|---|
A5/A6 controller (transmitter) |
boVar1 |
byDummy1 |
byDummy2 |
byDummy3 |
dwVar2 |
byVar3 |
byDummy4 |
wVar4 |
||||
|
boVar1 |
|
dwVar2 |
byVar3 |
|
wVar4 |
The exemplary accepted structure variable must be expanded as follows:
Structure content |
Internal memory |
|
---|---|---|
Variable name |
Type of variable |
Memory requirement in the internal memory |
boVar1 |
BOOL |
1 bytes |
byDummy1 |
Byte |
1 byte |
byDummy2 |
Byte |
1 byte |
byDummy3 |
Byte |
1 byte |
dwVar2 |
DWORD |
4 bytes |
byVar3 |
BYTE |
1 bytes |
byDummy4 |
BYTE |
1 bytes |
wVar4 |
WORD |
2 bytes |
The structure expanded with the dummy variables can be correctly transmitted from an A5/A6 controller to an