Property change executes when running project

Hey All,

My little snippet below executes when a label changes shifts. In other words when the ‘text’ property changes from a ‘1’ to a ‘2’ it will clear out OEE storage tags for the upcoming shift.

That works fine but it also sees this property change when starting the project on the client. So when you first run the project, it fires this property change event and clears out all of those tags.

Is there some way around this? Any help would be greatly appreciated!

if event.propertyName == ‘text’:

if event.source.text =="1":
	system.tag.write("DanielsDesk/OEE_Storage_1_7_", 0)
	system.tag.write("DanielsDesk/OEE_Storage_1_8_", 0)
	system.tag.write("DanielsDesk/OEE_Storage_1_9_", 0)
	system.tag.write("DanielsDesk/OEE_Storage_1_10_", 0)
	system.tag.write("DanielsDesk/OEE_Storage_1_11_", 0)
	system.tag.write("DanielsDesk/OEE_Storage_1_12_", 0)
	system.tag.write("DanielsDesk/OEE_Storage_1_13_", 0)
	system.tag.write("DanielsDesk/OEE_Storage_1_14_", 0)

If this is intended to be a system-wide operation, it really needs to be a gateway event script, not a client script. Even if you “fix” this to not fire on client open, you’ll still have a problem if no client is running at shift change, or more than one client has this window open, or someone is running a strange time zone and the label changes an hour early, etc, etc, etc.
Use a timer script running often (once a minute, perhaps), and use a datetime memory tag to hold the last time you reset everything. Every time the script runs, check the current time against the tag value, if in a new shift, update that tag and then write all your zeros. Very, very reliable. Even if you restart the gateway, it’ll work correctly.

2 Likes

Very helpful. Thank you. I’m working my way through the scripting for this now.

Thanks again.

As I’m working though this I want to make sure I’m clear. This should be a timer script on the gateway, correct? I’m stumbling my way through the python scripting but learning a little more everyday.

I would actually back up a step and take a look at what changes the label from shift 1 to shift 2. Is it a tag? Then I would put it in a tag event script.

Edit: You should also be aware that you can compare oldValue to newValue in your propertyChange scripts to prevent the issue you described when starting the project. In a tag event script the equivalents are previousValue and currentValue. Also take a look at the initialChange argument.