What's the best way to ensure that external tags are only ever set by PlantSCADA?

Suppose I have an external device (Modbus in this case) which "forgets" all its settings on power cycle.

Therefore if I have a tag "MyTag" on that device, after a device power cycle MyTag will get reset to zero by the device. What I need is that any time the value read back from the tag is not the one last set by PlantSCADA, it gets rewritten by PS to that last value.

Note that zero is valid value that might be written by PS, I can't just assume that 0 means "device reset".

I'm trying to come up with a generic solution which will work for potentially hundreds or thousands of tags.

One idea I had was to rename MyTag as "External_MyTag", and create a new internal MyTag. At the very simple level I could then have some Cicode I run every second:

    IF (MyTag <> ExternalMyTag) THEN ExternalMyTag = MyTag; END

.. repeated for every tag, but I don't really want the 1s latency that this would create, and it's not exactly elegant.

I could also use TagSubscribe to subscribe to both MyTag and ExternalMyTag and do something similar on seeing either tag change. (Does the PollTime passed to TagSubscribe apply when tags are written from withing PS? If it does I still have the latency issue.) Is TagSubscribe suitable for monitoring maybe 1000+ tags?

Is there a better way to create tags which are one-way copies of other tags?

Parents
  • Yes, you can have 10,000's of tags subscribed, depending on the polltime and PLC limitations.

    You could define an Event that triggers if ExternalMyTag=0, and it calls a Cicode function that copies all the internal tags into the external tags, then sets ExternalMyTag to 1, assuming that ExternalMyTag is an unused address in the device that only Citect writes to.

    The problem that I see is when if you read ExternalMyTag and it's good, then the device loses power and restarts. Then, maybe you get a subscription update for multiple other tags before Citect reads ExternalMyTag again. You could end up setting multiple tags to 0 before realizing the device was reset.

    So, you could subscribe to ExternalMyTag at a faster rate than the other tags and copy the current value and value timestamp to Cicode module variables. Then, in the subscription callback for other tag subscriptions, check that ExternalMyTag = 1 and that the timestamp is recent enough that you're confident the device hasn't rebooted. I assume it takes several seconds to restart and re-establish communications. That way, hopefully, the subscriptions will stop copying if the device has rebooted.

  • Thanks Eric.

    Can you confirm whether the poll time applies only to data that Citect has to read from external devices? In other words, it a value is written to a tag within Citect, does that directly trigger the callbacks for any tag subscriptions for that tag, or does it still wait for the next poll?

Reply Children