I just configured Modbus on my ctrlx and was wondering if there is a way of creating alias for array elements. Like in the I/O mapping of the data layer, is there a way of saying, for exemple, the variable "start_button" points to the first element of the holdingRegister array.
I could probably do it in a routine with pointers, but I'm sure there is a simpler way to do it as it is usually a base feature in most PLC.
Thanks in advance for your replies
Best reply by HmiGuide
Hello
I expect that you use the library CXA_ModbusTCP, with the example included in the library.
I did it a little bit different than the example. Here is my idea behind.
The example uses a WORD array for all different data types.
arRegister:ARRAY[0..9]OFWORD;
 I use a structure instead, with arrays for all all data types I need:
Â
TYPE REGISTER_DATA :
STRUCT
arWord : ARRAY[0..20] OF WORD; (* %MW0000 - %MW0019 *)
arInt : ARRAY[0..10] OF INT; (* %MW0020 - %MW0029 *)
arUint : ARRAY[0..10] OF UINT; (* %MW0030 - %MW0039 *)
arDint : ARRAY[0..5] OF DINT; (* %MW0040 - %MW0049 *)
arUdint : ARRAY[0..5] OF UDINT; (* %MW0050 - %MW0059 *)
arReal : ARRAY[0..5] OF REAL; (* %MW0060 - %MW0069 *)
arString : ARRAY[0..10] OF STRING[19]; (* %MW0070 - %MW0169 *)
END_STRUCT
END_TYPE
// define register data variable
regData: REGISTER_DATA;
Â
For easy usage in the program I define enumerations for all arrays like:Â
Â
ENUM EN_arWord
enLength = 0;
enWidth = 1;
END ENUM
Â
 Which means that my program is easy to read.
Â
regData.arWord[enLength] := 10;
Â
Attached you find an Excel document which supports you to create the necessary PLC code. The generated code is displayed in notepad for copy & paste. See Excel sheet "Docu" how to use it. You have to enable the macros included in Excel.
Alternatively you can use a structure with single variables. But this means, that you have to calculate the addresses for the Modbus partner by yourself. Or you adapt the Excel program to the single variables in the strucure.