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 A4 and A5/A6 controller via TCP/IP, UDP or CODESYS network functions.

 

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 A4 and A5/A6. The variable type LREAL is not supported in A4. Siehe 'PLC projects from A5/A6 used on A4 controllers'.

 

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 A4 and A5/A6, which results that the structure variables being stored differently in the internal memory.

 

The A5/A6 controller compiler stores data in succession in the internal memory, regardless of the data type.

The A4 controller compiler works according to the following rules:

 

Example:

An assumed structure from an A5/A6 controller should be transferred to an A4.

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

       

A4 controller

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 A4 and A5/A6, the transmitted data in the receiver's internal memory is stored as it was sent. However, the receiver's compiler expects the data in the above-illustrated arrangement, which causes the transmitted data in the receiver to be incorrectly assigned to the structure variables. In the previous example, only the variable 'boVar1' in the receiver unit would be assigned the correct content.

 

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

A4 controller (receiver)

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 A4 controller and be correctly assigned to the structure variables by the A4 compiler. The transmission of data from an A4 to an A5/A6 controller also works with the expanded structure variable.