When does the valueChanged event happen

It doesn’t seem to happen when the value is changed through the opc server updating the value from a device. During testing I had to constantly disable the tag and reenable it to get it to fire, but now it’s time to look at why it doesn’t seem to fire during normal operation. Thanks

So this thing is kicking my ass, I can’t get the valueChanged event to trigger unless I disable and reenable a tag, is this a bug, or is there something I’m missing? I have a folder with a bunch of bools in it. The bools are opc tags getting data from coils. They run a script that will update a historical memory tag on the udt that the bools are on. Thanks

Can you please post your code here?

code in valueChanged:

shared.Master.Faulted(tagPath)

code in shared script:

import re

def Faulted(tag):
tag = re.sub("([).*?(])", “\g<1>\g<2>”, tag)
unit = tag[:tag.index("/")]
path=[]
for fault in range(1,69):
path.append(unit + ‘/Faults/Fault’ + str(fault))
values = system.tag.readAll(path)
lfaults = map(lambda x: str(int(x.value == True)), values)
faults = ‘’.join(lfaults)
raw1 = int(faults[1:64], 2)
raw2 = int(faults[65:68], 2)
val = False
print "jake1: ", raw1
print "jake2: ", raw2
if raw1 & -4395513236498157825 or raw2 & 14:
val = True
system.tag.write(unit + ‘/Faulted’, val)

Thanks

It is hard to tell with the formatting here but with your script the potential is there, depending on indentation, that if your last bit is not faulted your script will always write that there is no fault.

@codersmurf: Please edit your post, select the code and hit the formatting button ["] to display it as code. Without the indentation your code is unreadable.

import re

def Faulted(tag):
tag = re.sub("([).*?(])", "\g<1>\g<2>", tag)
unit = tag[:tag.index("/")]
path=
for fault in range(1,69):
path.append(unit + '/Faults/Fault' + str(fault))
values = system.tag.readAll(path)
lfaults = map(lambda x: str(int(x.value == True)), values)
faults = ''.join(lfaults)
raw1 = int(faults[1:64], 2)
raw2 = int(faults[65:68], 2)
val = False
print "jake1: ", raw1
print "jake2: ", raw2
if raw1 & -4395513236498157825 or raw2 & 14:
val = True
system.tag.write(unit + '/Faulted', val)

import re

def Faulted(tag):
	tag = re.sub("(\[).*?(\])", "\g<1>\g<2>", tag)
	unit = tag[:tag.index("/")]
	path=[]
	for fault in range(1,69):
		path.append(unit + '/Faults/Fault' + str(fault))
	values = system.tag.readAll(path)
	lfaults = map(lambda x: str(int(x.value == True)), values)
	faults = ''.join(lfaults)
	raw1 = int(faults[1:64], 2)
	raw2 = int(faults[65:68], 2)
	val = False
	print "jake1: ", raw1
	print "jake2: ", raw2
	if raw1 & -4395513236498157825 or raw2 & 14:
		val = True
	system.tag.write(unit + '/Faulted', val)

It doesn’t look like a script issue based on this, if you surround your shared.Master.Faulted() function with some logging does it still not dump to the gateway diagnostic log when the value updates?

Example:

system.util.getLogger("TagChange").info("Tag change start: " + tagPath)
system.util.getLogger("TagChange").info("Prev value: " + str(previousValue) + " -- New val:" + str(currentValue))
shared.Master.Faulted(tagPath)
system.util.getLogger("TagChange").info("Tag change complete: " + tagPath)

I haven’t looked at the whole thing, but did notice that these two lines:

	raw1 = int(faults[1:64], 2)
	raw2 = int(faults[65:68], 2)

can’t possibly work as expected:

  • List slicing is zero-based and excludes the end subscript (you miss fault1 and fault65), and
  • Python int() can only do 32 bits.

Got it fixed. So I had to create so many bools linked to coils that I had to write a script to compensate for ignition not supporting reading an array of coils into an array of bools. The script originally had a tab that caused a problem, i removed it and it showed up correctly in the ignition scripting interface. I took out the tab and it showed up correctly in the interface so I figured I was golden, I was too lazy to add an -e to my echo’s in my loop in my bash script. I got it reproduced with a simpler udt and kept screwing around to properly debug it. Interesting though how inconsistent it was, should have failed and printed out syntax errors in the logs, but it silently failed. The interface should also be fixed so that it shows the tabs correctly instead of compensating for the lack of tabs. Thanks for the help everyone.