Time Synch

I’d like to synch. time on PLC’s using SQL Bridge. My idea was to use expression tags to get the time from the server computer and putting these in and OPC item to be written to the PLC. I’d do this periodically, say every 12 hours. Now for my concern: It looks to me like the items sent to the PLC reflect the last execution of the expressions. Is this true and if so, how can I get what I wan? Thanks ahead.

Which PLC brand are you looking at? Some of them have a free tool for clock sync that may help you out. And you can (usually) run them as a service. so that’s not bad either. If you’re running Linux, though, you’re hosed for that route… :laughing:

Through Ignotion, I’d evaluate a time expression and use that as a trigger if you want it to happen at a specific time. If not, then you can set your transaction group to be triggerless and evaluate every twelve hours.

As an aside, it probably wouldn’t hurt to keep the OPC tags with the time evaluating on a regular (1-5 sec.) interval, and then then turning on a “sync” bit to process the clock update.

Just as a aside, 12 hours may not be often enough. My experience has shown me that many devices have varying degrees of time maintenance. I’ve even had watches lose minutes in a day.

You will have to play around for a bit to ensure that you are syncing often enough. Don’t be afraid of syncing once (or more) an hour. Just try not to sync on the hour. It’s normal to run reports on the hour and you don’t want to miss a report run or cause it to run twice because you bumped the time. :laughing:

Hi,

I’m not sure I understood your original question. However, I’ll quickly outline how most people do time sync:

  1. Make a new group, and drag in the opc items representing the different portions of the time.
  2. Make all of those items “read only”, that is- change their targets to not write to the database. In this situation, there’s no need to go to the database.
  3. Make a new expression item for each part of the time. For each part, do the following:
    i) Set the expression mode to “expression” and use an expression like:
dateExtract(now(),"hour")

(see the user manual for all of the possibilities)
ii) On the main panel of the expression item, set its writeback target to the corresponding plc tag.
4) On the action tab of the group, set the rate you want to sync at. Unselect “store timestamp”. Set the group to “update first row”. You actually won’t be touching the db, but in case you accidentally left something pointed to it, you won’t insert unnecessary rows.

That’s it, start the group and you’ll be up and running. There are a few things that might throw off beginners:

  1. The role of the database - the db is not being used in this case. But, groups currently require the db settings. In the next version of the SQLBridge module there will be groups that allow this item-to-item mapping with no db, but for now, as long as nothing is mapped to the db, no queries are executed.
  2. The group mode- people think that “opc-to-db” means that you can’t write to the opc items. This isn’t true- irregardless of the group mode, if you have an expression set to write to an opc item, it will be written. That mode is used for db interaction, which doesn’t apply here.

Hope this helps,

1 Like

Thanks for the replys. Originally I was refreshing the time every 12 hours. However, the data sent to the PLC was the last refreshs’ data. The expressions must be evaluated after the data transmission. As suggested I used a trigger formed from an expression to be true when my minute value = 30 (once per hour). Also, I set the update rate at 1 second and put all expressions in the run-always area. Even though I have a trigger, data is still sent to the PLC based on the refresh value. If I put anything in the run always section, that data is sent to the PLC periodically. Anything in the triggered expression area gets ‘late’ data in the PLC.

I’ve attached a copy of the group.
TimeSynch.xml (23.2 KB)

That’s interesting- I think you’re seeing a potential bug that has been reported elsewhere here. We haven’t been able to replicate it yet, but I’ll try mocking up something like this and see where it goes. What you described is NOT how it should work, it should always write the values from the most recent execution.

Regards,

I just mocked this up and noticed something interesting… the values that get written seem to be fine, but the OPC values in the group are displaying older values. So, are you sure that the values being written are old, or are you just looking at the values in the group? The problem is that the opc values are “locked in” when the group runs, after execution, you’ll see the values as they were before the write. They won’t update until the next exec.

Check the actual values either with PLC software, or by bringing the same datapoints into SQLTags. By default the tags will run at a one second rate, so the value will be much more “live” than in the group.

After doing this, let me know if it still appears to be writing the old value.

(on a side note, we know that this type of value display in the group is a bit misleading, and intend to improve the value display soon)

Regards,

You are quite right: The value in the PLC seems to follow the displayed expression values not the OPC displayed valued. I’ll leave it at that and do updates based on the update rate. Thanks.