Here are the considerations when doing that:
Set up a FactorySQL group to log the data
Trigger that group when the time range changes
Reset the data
Your FactorySQL group should be set to: OPC->DB, “Insert New Record”. Drag all PLC tags that you wish to log.
Create an Action item, “shift_trigger”. Set the “Item Mode” to SQL Query and use the following query (I’m assuming MySQL here, specify if you’re using a different DB).:
SELECT CASE WHEN (CURRENT_TIME > '06:00:00' AND CURRENT_TIME <= '14:00:00') THEN 1
WHEN (CURRENT_TIME > '14:00:00' AND CURRENT_TIME <= '22:00:00') THEN 2
The above query cycles between 1-3 as the time of day changes. Now, go to the group trigger tab, set “use trigger”, select “shift_trigger”, Select “only execute group once when trigger is active” (we only want 1 record logged per trigger change). Now select “Active on Value Change” radio button for trigger condition (We want to log data during any shift change).
- The easiest way to reset the values is to have the PLC do it. Drag the PLC register (OPC tag) that you wish to use to request the PLC to clear data. Double click this and make it “Read only” (We don’t want to log this value with the others). Under the trigger tab, select “Uses Handshake”. Choose the read only tag for the handshake and set the value to 1. The PLC should clear the necessary registers when it reads a 1 there, then reset this bit to 0.
Alternatively, if you don’t want to use PLC logic to clear the PLC registers. You can use a second DB->OPC FactorySQL group to do so. It needs to run (triggered) after the first group executes. This can be set up using a flag in the database or a spare PLC register with the handshake option, similar to what was described above.
Let me know if you have any questions. It’s not as complicated as it sounds.