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] OF WORD;
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.
TYPE REGISTER_DATA :
STRUCT
wLen: WORD; /* %MW0 */
wWidth: WORD; /* %MW1 */
wUnused3: WORD; /* %MW2 */
wUnused4: WORD; /* %MW3 */
wUnused5: WORD; /* %MW4 */
iTest1: INT; /* %MW5 */
iTest2: INT; /* %MW6 */
iUnused3: INT; /* %MW7 */
iUnused4: INT; /* %MW8 */
iUnused5: INT; /* %MW9 */
END_STRUCT
END_TYPE
// define register data variable
regData: REGISTER_DATA;
// usage in program
regData.wLen := 10;
... View more