[Tag Event Script] Writing value from one UDT member (OPC) to another (Memory) using value change of Boolean tag

End Goal: Accurately log fault occurences.

I have a UDT for powerflex 525s. I'm using the tag historian to store fault data by logging the string value for the ActiveFaultDesc UDT member. Sample Mode is set to "On Change". Originally the value on ActiveFaultDesc changed based upon the integer value of FaultCode which is tied to the ":I.Fault1Code" tag from the PF525.

Most who are very familiar with the PF525 VFDs know that the ":I.Fault1Code" tag serves as both the "active fault code", while the VFD is in a faulted condition and also the "most recent fault code", once the VFD is out of the faulted condition.

One of the problems that I ran into is that if the VFD experienced the same fault twice or more in a row, the FaultCode int value would not change leading to the ActiveFaultDesc value not changing either, resulting in those occurrences not being logged. If a different fault code occurred, then it would be logged.

I then added a UDT member, int memory tag ActiveFaultInt. Configured an event script on the Sts_DriveFault boolean tag so that when it goes True, the value from FaultCode gets moved into ActiveFaultInt. Once Sts_DriveFault goes False, a default value of 0 gets moved back into ActiveFaultInt. It works, but again, only when the value of FaultCode has changed since the last fault occurrence :upside_down_face:. It's as if the script won't run.

I added the time.sleep() because there is a slight delay between the time Sts_DriveFault goes True and the new fault's int value is updated in the FaultCode tag. Without some kind of delay there would be even more inaccuracies in the stored fault data. If there is a better way to delay the script I'm open to ELI5 suggestions.

Please bear with me, I'm still new to scripting.

	import time
	path = "[.]ActiveFaultInt"
	
	if currentValue.value == True:
		time.sleep(.5)
		FaultCode = system.tag.readBlocking("[.]FaultCode")
		ActFltInt = system.tag.readBlocking("[.]ActiveFaultInt")
		
		if ActFltInt != FaultCode:
			system.tag.writeBlocking(path, FaultCode)
		
	elif currentValue.value == False: 
		system.tag.writeBlocking(path, 0)
		ActFltInt = 0
		FaultCode = 0	

image

Don't subscribe to FaultCode. (Subscriptions do not guarantee deliver order or timing.) Use a direct OPC read after the fault trigger occurs. Do this in a gateway tag change event (project), not a tag valueChange event, as an OPC read can run for many seconds if there is a comms break at the wrong time.

Don't ever use any kind of sleep, or delay of any kind, in a tag event (on the tag).

1 Like