GatewayEvenScripting

Hi guys, right now I have a few Tag change event scripts being ran on the Gateway side the following is an example

from java.util import Calendar
cal = Calendar.getInstance()
value = system.tag.read("Press Lines/ChangeOver").value

if value == 1:
	Path = "Press Lines/DateOn"
	system.tag.write(Path, cal.getTime())

if value == 0:
	Path = "Press Lines/DateOff"
	system.tag.write(Path, cal.getTime())

Basically I’m grabbing a t_stamp when the Boolean bit comes on and when it goes off. It works great my only issue is whenever I as anything new to the events or make a change that requires saving every even I have great ran again so most the time with since my Boolean is off the t_stamp gets grabbed again which I don’t want to happen. I basically only want the script that i made change to or added to be ran. I assume I need to work with a tag value change function? Something like only run the script if the value of the Boolean has changed right?
Can someone point me to the right direction? Thanks
I’m using v 7.8.2

[quote=“Mr.K001”]Hi guys, right now I have a few Tag change event scripts being ran on the Gateway side the following is an example

from java.util import Calendar
cal = Calendar.getInstance()
value = system.tag.read("Press Lines/ChangeOver").value

if value == 1:
	Path = "Press Lines/DateOn"
	system.tag.write(Path, cal.getTime())

if value == 0:
	Path = "Press Lines/DateOff"
	system.tag.write(Path, cal.getTime())

Basically I’m grabbing a t_stamp when the Boolean bit comes on and when it goes off. It works great my only issue is whenever I as anything new to the events or make a change that requires saving every even I have great ran again so most the time with since my Boolean is off the t_stamp gets grabbed again which I don’t want to happen. I basically only want the script that i made change to or added to be ran. I assume I need to work with a tag value change function? Something like only run the script if the value of the Boolean has changed right?
Can someone point me to the right direction? Thanks
I’m using v 7.8.2[/quote]

work with the initialChange, if FALSE, then a project save did not trigger the tag script

[attachment=0]2016-04-20 14_50_33-192.168.11.10 - Remote Desktop Connection.png[/attachment]

one issue I have found with gateway tag change scripts, at least in 7.8.1, is that if you use initial change and reboot the server or restart the ignition service, the first change wont be registered. maybe not a big deal, but in my case it was a report I was sending out every day. so if I reboot the server, the next day it wouldnt send. may not be an issue for you, but you may want to test this if it is something critical.

That helped thank you. ended up going with:

if newValue.value == 1:
	if initialChange == 0:
            write to tag 1
if newValue.value == 0:
	if initialChange == 0:
            write to tag 2

seems to be working fine, I tried to add a new script event and save it and nothing changed also restarted the gateway server and nothing changed so I’m happy so far! :thumb_right:

in this case this is fine with me, I don’t want that first change after a server restart as it will show a wrong t_stamp.
why don’t you set your reporting based on an actual time that way you don’t have to worry about server restart?