Client Tag change script

Hi, i need to know when i select 2 tags in tag change script how do i access the second tags like
first tag value i will access via
print event.tagPath
print initialChange
print newValue
but how to take new Value of second tag which i have used in tags.
Urgently needed.


These events fire for each tag that changes value in those you specify. When it fires, it fires independently for each tag being monitored changes; you don’t get access to other tags being monitored. You will need to read any other tag by using a static path to them and system.tag.readBlocking. In this respect, the gateway tag change scripts behave very similarly to tag change scripts

i am trying to read the tag but it is not working so can you tell me the exact syntax for read.
I am trying with system.tag.readBlocking("[default]FB_Process/IT02_prodtransfer/Prodtransfer_ctrl").value
but still i ma unable to read that

It returns a list, so you need
system.tag.readBlocking("[default]FB_Process/IT02_prodtransfer/Prodtransfer_ctrl")[0].value

that syntax is not working in script as i have tried. Also want to know what this [0] stands in syntax

When you say it’s not working, what do you mean?

The [] are basic python syntax to read the elements of a list (array). If you’re asking that question though, you really should look at some basic introductory material to the Python language. I think even the IA user manual has some material covering it

https://docs.inductiveautomation.com/display/DOC81/Python+Scripting

yes sure i got the list of array, but still i am facing the same issue i am posting the query and image.
below image is the tag for which i created script.

the tag is timer tag and i am changing the process based on conditions and timer value.
and below is the code for the process.

print event.tagPath
print initialChange
print newValue

if system.tag.readBlocking("[default]FB_Process/IT02_prodtransfer/Prodtransfer_ctrl")[0].value == 1:
system.tag.writeBlocking(["[default]FB_Process/Test_tags/Timer_tag"], [1])
if newValue.value == 1:
system.tag.writeBlocking(["[default]FB_Process/VLV4/Mode"], [1])
system.tag.writeBlocking(["[default]FB_Process/VLV4/Valve_status"], [1])
system.tag.writeBlocking(["[default]FB_Process/VLV7/Mode"], [1])
system.tag.writeBlocking(["[default]FB_Process/VLV7/Valve_status"], [1])
system.tag.writeBlocking(["[default]FB_Process/BL01_Filling/Fill_ctrl"], [1])
system.tag.writeBlocking(["[default]FB_Process/IT02_Empty/Empty_ctrl"], [1])
if newValue.value == 5:
system.tag.writeBlocking(["[default]FB_Process/PU2/Mode"], [1])
system.tag.writeBlocking(["[default]FB_Process/PU2/Pump_status"], [1])
system.tag.writeBlocking(["[default]FB_Process/Test_tags/Timer_tag"], [0])
newValue.value = 6
if newvalue.value == 6 & system.tag.readBlocking("[default]FB_Process/IT02_prodtransfer/Prodtransfer_ctrl")[0].value == 0:
system.tag.writeBlocking(["[default]FB_Process/PU2/Mode"], [0])
system.tag.writeBlocking(["[default]FB_Process/PU2/Pump_status"], [0])
system.tag.writeBlocking(["[default]FB_Process/Test_tags/Timer_tag"], [1])
if newValue.value == 11:
system.tag.writeBlocking(["[default]FB_Process/VLV4/Mode"], [0])
system.tag.writeBlocking(["[default]FB_Process/VLV4/Valve_status"], [0])
system.tag.writeBlocking(["[default]FB_Process/VLV7/Mode"], [0])
system.tag.writeBlocking(["[default]FB_Process/VLV7/Valve_status"], [0])
system.tag.writeBlocking(["[default]FB_Process/BL01_Filling/Fill_ctrl"], [0])
system.tag.writeBlocking(["[default]FB_Process/IT02_Empty/Empty_ctrl"], [0])
system.tag.writeBlocking(["[default]FB_Process/Test_tags/Timer_tag"], [0])

Try this. You had a few typos (like using newvalue instead of newValue), you can’t write to newValue.value, also I converted your individual tag writes into single block writes as this is a lot more efficient in terms of CPU and speed.

print event.tagPath
print initialChange
print newValue
tagPath = str(event.tagPath)

# this will store the tags and their values to write as a list of lists as [[tagPath1, value1], ..., [tagPathN, valueN]]
tags = []

if system.tag.readBlocking("[default]FB_Process/IT02_prodtransfer/Prodtransfer_ctrl")[0].value == 1:
	tags.append(["[default]FB_Process/Test_tags/Timer_tag", 1])

if newValue.value == 1:
    tags.append(["[default]FB_Process/VLV4/Mode", 1])
    tags.append(["[default]FB_Process/VLV4/Valve_status", 1])
    tags.append(["[default]FB_Process/VLV7/Mode", 1])
    tags.append(["[default]FB_Process/VLV7/Valve_status", 1])
    tags.append(["[default]FB_Process/BL01_Filling/Fill_ctrl", 1])
    tags.append(["[default]FB_Process/IT02_Empty/Empty_ctrl", 1])

elif newValue.value == 5:
    tags.append(["[default]FB_Process/PU2/Mode", 1])
    tags.append(["[default]FB_Process/PU2/Pump_status", 1])
    tags.append(["[default]FB_Process/Test_tags/Timer_tag", 1])
    tags.append([tagPath, 6])
    
elif newValue.value == 6 and system.tag.readBlocking("[default]FB_Process/IT02_prodtransfer/Prodtransfer_ctrl")[0].value == 0:
    tags.append(["[default]FB_Process/PU2/Mode", 0])
    tags.append(["[default]FB_Process/PU2/Pump_status", 0])
    tags.append(["[default]FB_Process/Test_tags/Timer_tag", 1])
    
elfif newValue.value == 11:
    tags.append(["[default]FB_Process/VLV4/Mode", 0])
    tags.append(["[default]FB_Process/VLV4/Valve_status", 0])
    tags.append(["[default]FB_Process/VLV7/Mode", 0])
    tags.append(["[default]FB_Process/VLV7/Valve_status", 0])
    tags.append(["[default]FB_Process/BL01_Filling/Fill_ctrl", 0])
    tags.append(["[default]FB_Process/IT02_Empty/Empty_ctrl", 0])
    tags.append(["[default]FB_Process/Test_tags/Timer_tag", 0])

# write the values to the tags. Note the syntax "list(zip(*tags))" effectively produces a list of columns, where element 0 are the tagPaths and element 1 are the values
system.tag.writeBlocking(list(zip(*tags))[0], list(zip(*tags))[1])
1 Like