I want to check how long a motor is working since the last check up and how many times the motor startet up since then.
#xSekundenzaehler := "Clock_1Hz";
REGION Allgemein
#Betriebszeit_Anlage(CU:="eHauptschuetz" AND #xSekundenzaehler,
R:="Lebensdauer".Allgemein.xResetBetriebszeit,
PV:=0,
CV=>#rSecondsAnlage);
"Lebensdauer".Allgemein.rLaufzeitAnlage := #rSecondsAnlage / 3600;
END_REGION
This is the code i used. Do i have to use another "CTU" again or is there a smarter way to do this in the already existing one that i don't know of?
Usually storing important values on CTU is not recommendable because you have no control on whether TiaPortal may restore the CTU instance.
It is preferable to build a counter by yourself so its value is kept on a non volatile db var:
This is the definition of the DB
Please note that only seconds are remanent, as hours and decihours are calculated on every cycle.
It would be better to store hours and decihours in other DB, so this one is dedicated to remanent values. When you modify the DB variables their values are reset to the start values. Please remember to make a snapshot and copy them to start values prior to any changes.