I need a bit of help with pointers in S7. I am a AB and Omron person who has done some simple S7 programming before (but I have avoided STL altogether).
I wanted to implement a simple fault logging code in a S7-300 PLC but did not realise how hard it was going to be!
What I want to achieve is simple.
- Define a 'fault_event' UDT which has a 'faultcode', 'date' and 'time' properties.
- Define an array of 50 'fault_event' UDTs to make up my 'fault_log'.
- Every time there is a new fault I want to write to the 'i' location in my 'fault_log' then increment 'i' (unless it greater than 50 in which case I reset it to 0).
Just goes to show now little I know about S7. I thought I could simply do a move/copy of the current faultcode, date and time to any element in the fault array defined by the index 'i'. Thought it would be something like this:
IF (i < 0) OR (i > 50) THEN
i := 0;
END_IF;
IF new_fault THEN
FaultLog.FaultCode := CurrentFaultCode;
FaultLog.FaultDate := CurrentDate;
FaultLog.FaultTime := CurrentTime;
i := i+1;
END_IF;
(Note, I was intending to implement the above in ladder but only expressed it in structured text so it is easier to post).
After diving into it and attempting to implement the above code in ladder (and failing miserably).
I now realise I need to use STL and instructions such as AR1 and P# etc. But I can not find any examples of indirect addressing related to arrays of UDT.
Anyone out there have sample code I can look at?
I wanted to implement a simple fault logging code in a S7-300 PLC but did not realise how hard it was going to be!
What I want to achieve is simple.
- Define a 'fault_event' UDT which has a 'faultcode', 'date' and 'time' properties.
- Define an array of 50 'fault_event' UDTs to make up my 'fault_log'.
- Every time there is a new fault I want to write to the 'i' location in my 'fault_log' then increment 'i' (unless it greater than 50 in which case I reset it to 0).
Just goes to show now little I know about S7. I thought I could simply do a move/copy of the current faultcode, date and time to any element in the fault array defined by the index 'i'. Thought it would be something like this:
IF (i < 0) OR (i > 50) THEN
i := 0;
END_IF;
IF new_fault THEN
FaultLog.FaultCode := CurrentFaultCode;
FaultLog.FaultDate := CurrentDate;
FaultLog.FaultTime := CurrentTime;
i := i+1;
END_IF;
(Note, I was intending to implement the above in ladder but only expressed it in structured text so it is easier to post).
After diving into it and attempting to implement the above code in ladder (and failing miserably).
I now realise I need to use STL and instructions such as AR1 and P# etc. But I can not find any examples of indirect addressing related to arrays of UDT.
Anyone out there have sample code I can look at?
Last edited: