Calling a function issue

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!

This seems fine. What is the problem? Do you see any exceptions in the “Status -> Gateway Scripts” Gateway webpage?

I don’t see anything obviously out of place on first blush either.

One thing I do see is the possibility of PLC_AckCounter.value being greater than 180. consider changing it to:

elif PLC_Ack.value == 1 and PLC_AckCounter.value >= 180:

That will help ensure a reset, even if it accidentally goes above your reset point.

It works fine now! I had forgotten the "import system" step in the actual gateway script! Turned out to be quite a silly thing in the end!! Thanks for helping me troubleshoot and find the actual fault!

[quote=“JordanCClark”]I don’t see anything obviously out of place on first blush either.

One thing I do see is the possibility of PLC_AckCounter.value being greater than 180. consider changing it to:

elif PLC_Ack.value == 1 and PLC_AckCounter.value >= 180:

That will help ensure a reset, even if it accidentally goes above your reset point.[/quote]

Yes, I have changed it! Thank You!