So far I have described ways of reading BOOL, BYTE and WORD variables. It is the time to look into reaching structures i.e. variables build of a group of variables.
As a start I define a testStruct type in the ‘Data types’ tab:
TYPE testStruct : STRUCT id : BYTE; state : WORD; name : STRING; data : ARRAY [0..5] OF BYTE; END_STRUCT END_TYPE
In the program I define a variable Structure of testsTruct type:
VAR Structure : testStruct; END_VAR
Then I assing some values to the new variable:
Structure.id:=10; Structure.state:=1000; Structure.name:='testing'; Structure.data:=11; Structure.data:=12;
Additionally I create a visualization ‘test_visu’ where I place 5 rectangles, showing values of the 5 elements of the Structure variable.
After compiling the program, uploading it to the controller I connect via FTP and in the ‘PLC’ directory I find ‘text_visu.xml’, where at the very end I see:
<variable name="PLC_PRG.Structure.id">4,176680,1,2</variable> <variable name="PLC_PRG.Structure.state">4,176682,2,3</variable> <variable name="PLC_PRG.Structure.name">4,176684,11,8</variable> <variable name="PLC_PRG.Structure.data">4,176695,1,2</variable> <variable name="PLC_PRG.Structure.data">4,176696,1,2</variable>
By placing all the elements of the Struct variable in a visualization accessible via web we can get the addresses of all those elements. Structure.id has 176680, Structure.state – 176682, Structure.name – 176684, Structure.data – 176695.
The structure of element addresing stays the same for a given data type. It means that if I define another variable Struct2 : testStruct and place in the visualization its first elementonly only, I can calculate the addresses of the remaining elements:
Let’s try a real example. In my program I use the WAGO Scheduler_02.lib library and store calendar data in variables of typScheduleWeekly type.
In my program I have:
VAR Blind_Salon_Data1 : typScheduleWeekly; END_VAR
In the library exploror (Resources->Library Manager->Data types) I can see that typScheduleWeekly is defined as:
TYPE typScheduleWeekly : STRUCT ON_hour : WORD; ON_minute : WORD; OFF_hour : WORD; OFF_minute : WORD; Weekday : WORD; Active : WORD; END_STRUCT END_TYPE
When in a visualization accessible through the web an element is placed which shows the value of PLC_PRG.Blind_Salon_Data1.ON_hour, after compiling and uploading the program, in the ‘PLC’ directory in ‘visualization-name.xml’ I find:
Knowing the structure of typScheduleWeekly (all elements are WORD) and knowing that the first element element ON_hour has address 3,6232,2,3, I can calculate that:
So, finally – is it possible to read complex variables (type STRUCT)? Yes it is! One needs to place in a visualization the variable's first element, read its address from the xml file, calculate the addresses of the remaining elements and read them one-by-one (how? read the previous article).
If we know the above we can read the values of complex variables via MODBUS and with READPI queries. One would need to find out how the addresses presented in the visualizations (like 3,6232) transfer to the addresses used by MODBUS and the web server replying to READPI requests.
Now is the time to extend my web visualizations with schedulers control :) UPDATE: See this article!