Scheduled group and clearing PLC


We would like to set up FactorySQL following. We need downloaded data from PLC at 6:00, 14:00 and 22:00. In this time we wold like save this value to the database and after this action we would like to set up PLC to value 0. Please send us informaion, how can we set up it. Thanks.

Here are the considerations when doing that:

  1. Set up a FactorySQL group to log the data

  2. Trigger that group when the time range changes

  3. Reset the data

  4. Your FactorySQL group should be set to: OPC->DB, “Insert New Record”. Drag all PLC tags that you wish to log.

  5. 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).:

    WHEN (CURRENT_TIME > '14:00:00' AND CURRENT_TIME <= '22:00:00')  THEN 2
    ELSE 3

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).

  1. 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.

I try your guide to download data from PLC to DB at 6:00, 14:00, 22:00 All is O.K. But I can’t clear plc after download data. In table I have about 10 articles. After download from PLC to DB I nedd clear them - it’s material statistic for shift. There is error:

Error writing to OPC

and also this error

Group Execution error
Group execution aborted.

Please send us guide, how we can delete PLC.



Hello Andrej,

Perhaps you could describe your situation a little more:

-What version of FSQL are you using?
-What OPC server/PLC are you using?
-How are you currently attempting to clear the data? Is there just 1 bit that triggers the PLC to clear all 10 tags, or are you trying to write a 0 to each one?

I have a few ideas as to what might be wrong, but without knowing more about your setup it would be hard to guess. A couple initial ideas: 1) Perhaps 1 or more tags are setup as read-only in your OPC server
2) Perhaps 1 or more are trying to write a NULL from the database, instead of a 0

I hope this helps a bit,

Here are ways to clear the PLC registers:

  1. The easiest is to have the PLC clear them based when a certain register, the clear register, goes high. On the group’s “trigger” tab, check “Uses handshake”. Drag the clear OPC item into your group. Double click it and set the “read only” property so that it doesn’t get stored in the database. FactorySQL will set the handshake bit after the group triggers and the PLC can reset all values to default.

  2. Another approach uses a separate FactorySQL DB->OPC reset group that is somehow triggered after the main group runs. reset will read “default values” from the SQL database and write them to the PLC when it runs. Set the trigger to a PLC register or a flag in the SQL database (using an SQL query based action item as the trigger).

I would recommend the first option.