Tag script help

First time doing a tag script
Vision
Version: 8.1.17
Background: I have AB PLC’s 5, 500 and 5000 that will all need to have the clock synced to within a few seconds. I want the following tag to be a “call” from the PLC’s at first scan then I will run it every hour to keep time.
I can toggle the plc and see the tag go true and I can set numbers in the write tag and see them change in the plc. The Gateway_Seconds tag is showing seconds. Can’t figure out what I am doing wrong or where to look to figure it out.

I have a Bool UDT from a plc with the following script.

def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):
“”"
Fired whenever the current value changes in value or quality.

Arguments:
	tag: The source tag object. A read-only wrapper for obtaining tag
	     properties.
	tagPath: The full path to the tag (String)
	previousValue: The previous value. This is a "qualified value", so it
	               has value, quality, and timestamp properties.
	currentValue: The current value. This is a "qualified value", so it has
	              value, quality, and timestamp properties.
	initialChange: A boolean flag indicating whether this event is due to
	               the first execution or initial subscription.
	missedEvents: A flag indicating that some events have been skipped due
	              to event overflow.
"""
gatesec = system.tag.readBlocking("[default]Gateway_Seconds")[0].value
if currentValue.value == true:
	system.tag.writeBlocking(["[.]Clock Second Write"],["gatesec"])
if currentValue.value == true:
	system.tag.writeBlocking(["[.]Clock Second Write"],["gatesec"])

Get rid of the quotes to reference the variable, otherwise you’re trying to write the string "gatesec".

So like

if currentValue.value == true:
	system.tag.writeBlocking(["[.]Clock Second Write"],[gatesec])

Still a no go. Adding the quotes was my last attempt before asking for help. I am not getting any errors that I see but the udt opc tag Clock Second Write won’t change.

Do you see anything in your gateway logs?

writeBlocking provides a list of result codes back. Try doing this to in your script console to see what is going wrong -

gatesec = system.tag.readBlocking("[default]Gateway_Seconds")[0].value
results = system.tag.writeBlocking(["[.]Clock Second Write"],[gatesec])
for result in results:
    print result.diagnosticMessage

And you should at least what is going wrong here.

Thank you very much. Knowing where to find the errors was the key. This was the answer.

gatesec = system.tag.readBlocking("[default]Gateway_Seconds")[0].value
if currentValue.value == 1:
	system.tag.writeBlocking(["[.]Clock Second Write"],[gatesec])
1 Like

Oh I should have caught that. For python its True/False. true isn’t anything, so you’re script was probably erroring out at the comparison line.