How to know if a tag has been written or something goes wrong?

Hello guys, I have a new discussion regarding the confirmation of writing tags.

This come because of the process of a client that includes the activation of bit that change the status of an integer tag from ignition to start an order, this bit also make an update of the warehouse and the information of the recipe is copied to the PLC.

After the PLC executes this, it changes the status of this integer tag and in the ignition because of the tag change executes an script that process the data and send the info to a database.

However sometimes this bit isn't written for any reason, maybe the scan time between the PLC and the ignition. So the idea is to use the following script to know if this tag is really written.

paths = ["[default]testBit"]
values = [0]

def myCallback(asyncReturn):
    for result in asyncReturn:
        # Do something if a bad qualified value was returned
        if not result.good:
        	print "The result is " + str(result)
        else:
        	print "The result is " + str(result)
system.tag.writeAsync(paths, values, myCallback)

The thing with this code is that I want to specify a path in the function "myCallback", this would mean 2 arguments for this function, however the manual says it must be only one argument that it is surely the result of that write asynchronous.

So I wonder how to use the result of this function at the moment of the writing to write another tag in ignition to know if something goes wrong with the writing to the OPC tag. This last part is a little confusing but I hope you can understand it.

Any ideas?

What is writing to the PLC boolean bit? The PLC itself, a HMI or Ignition?

If it's Ignition then I think the correct procedure would be to use system.tag.writeBlocking | Ignition User Manual. The program will pause until the function finishes. You can then follow that with system.tag.readBlocking | Ignition User Manual if you want to double-check.

It sounds like you are writing to this tag from both Ignition and within the PLC. This is inherently racy for all but the simplest fire-and-forget uses.

Use separate handshakes where Ignition both sets and resets its signal to the PLC, and the PLC sets and resets an acknowledgement signal. (Separate tags.)

1 Like