Timer (from threading) doesn't write tag after a certain time (delay)


in practice, i would need to write an output flag (Done) to True after a certain time (delay) that the input flag (Trigger) has gone to True:

The input flag (Trigger) is reset but the second one (Done, the delayed one) is not set. From the logs you can see that both functions are executed.. but actually only one of the two tags is written (the firts one, Trigger).
See wrapper.log:


So, the script works but the output tag (Done) is not set to True.. as if the gateway ignored the writing..

  • Why this behavior?
  • How can i fix it?

Thanks in advance.

The tag path that you are feeding the write function does not look correct. Try copying the full tag path to the "Done" flag value from the tag browser and pasting it on line 10 in place of "[.]Done"

To simplify this problem you could also test writing to the tag with the script console with a much simpler script

I try to do as you suggested.. and great, it works:

	if currentValue.value != previousValue.value and not initialChange and currentValue.value:
		from threading import Timer
		from system.tag import read, write

		def wrapper():
			write("[default]_TEST/Do_Test/Done", True)
			print "stop t1"
		def reset():
			write(tagPath, False)
			print "stop t2"	
		d = read("[.]Delay").value
		t1 = Timer(d, wrapper)
		t2 = Timer(1.0, reset)
		print "start t1, t2"

I think that once you run the write function in a separate thread, it needs a full path (provider + tag path) to work properly.
If you remove the provider the write function no longer works.

Thanks :+1: