I have a gateway script which basically checks three tags (Fault, Acknowledge, AcknowledgeCounter). I had no problems running the script and it worked perfectly.
PLC_ACK = system.tag.read("PLC Heartbeats/Test/Ack")
PLC_AckCounter = system.tag.read("PLC Heartbeats/Test/AckCounter")
PLC_Fault = system.tag.read("PLC Heartbeats/Test/Fault")
if PLC_Fault.value == 1:
if PLC_ACK.value == 1 and PLC_AckCounter.value < 179: ##changes every 3 hrs
count = PLC_AckCounter.value + 1
system.tag.write("PLC Heartbeats/Test/AckCounter",count)
elif PLC_ACK.value == 1 and PLC_AckCounter.value == 179: ##changes every 3 hrs
value = 0
system.tag.write("PLC Heartbeats/Test/AckCounter",value)
system.tag.write("PLC Heartbeats/Test/Ack",value)
elif PLC_ACK.value == 0:
system.tag.write("PLC Heartbeats/Test/AckCounter",0)
elif PLC_Fault.value == 0:
system.tag.write("PLC Heartbeats/Test/AckCounter",0)
system.tag.write("PLC Heartbeats/Test/Ack",0)
The above code deals with one device (Test). I need to implement this for multiple devices. Hence, I tried to wrap this code in a function and then call out the function but to no avail.
Here’s what I tried to do
def tagFunction(AckTag,AckCounterTag,FaultTag):
import system
PLC_Ack = system.tag.read(AckTag)
PLC_AckCounter = system.tag.read(AckCounterTag)
PLC_Fault= system.tag.read(FaultTag)
if PLC_Fault.value == 1:
if PLC_Ack.value == 1 and PLC_AckCounter.value <180:
count = PLC_AckCounter.value + 1
system.tag.write(PLC_AckCounter,count)
elif PLC_Ack.value == 1 and PLC_AckCounter.value == 180:
value = 0
system.tag.write(PLC_Ack,value)
system.tag.write(PLC_AckCounter,value)
elif PLC_Ack.value == 0:
system.tag.write(PLC_AckCounter,0)
elif PLC_Fault.value == 0: ## if PLC_Fault == 0
system.tag.write(PLC_Ack,0)
system.tag.write(PLC_AckCounter,0)
tagFunction("PLC Heartbeats/Test/Ack","PLC Heartbeats/Test/AckCounter","PLC Heartbeats/Test/Fault")
##tagFunction("PLC Heartbeats/CMP2VC/Ack","PLC Heartbeats/CMP2VC/AckCounter","PLC Heartbeats/CMP2VC/Fault")
I am new to programming so I presumed this is the correct way to implement it. Is it an issue with the format with which I am providing the arguments?
Thank You!