WriteBlocking to BoolArray successfull BUT tag not showing updates

Hi Guys,

Maker edition 8.1.7

TLDR: Using the writeBlocking script function to update an array memory tag does work but an expression tag dependent on that array does not update. Additionally the tag browser does not show the updated array values in designer. I can force the expression and the tag browser to update by right clicking on the array tag and selecting "Restart Tag".
Manually toggling the array bits on and off in the the designers tag browser updates the expression tag every time as expected.

More details here

I am using a python script (writeBlocking function) to write to a memory tag of type BoolArray with 9 elements, I am writing the whole array at once.

In the script if I read back the tag and print it to the wrapper log it shows the new values, as expected so far so good. But the tag browser in the designer does not the update the array elements when the writeBlocking occurs and is stuck on the old values.

My major issue here is an expression tag which is dependent on the array elements which does not update when the writeBlocking to the array occurs. However if I "Restart Tag" the array tag in the designer everything will then update and work, additionally the writeBlocking and dependent expression will work one more time, but then stop working for all future writeBlocking executions until I restart it again. :rage:

If I manually toggle the bits on/off in the designer the expression works, so this does not appear to be an issue with the expression tag specifically but how I am updating the array.

The following describes how the writeBlocking is used in context, hopefully this makes scenes:
In my application user interacts with a multi-state dropdown box, a memory tag of type "Document" is bidirectionally linked to the value of the dropdown box. When the value changes the below python scrip runs to map the selected values to a boolean array in a UDT:

	# read in the selectedSwitches bool array. Mainly for the length of the array
	# as this may change in the future. All other values will be 
	# overwritten
	currentSwitches = system.tag.readBlocking(["[.]SelectedSwitches"])[0].value
	optionsLength = len(currentSwitches)
	
	#Debugging, Print origional array 
	print("****Valued changed")
	print("Oritional:")
	print(currentSwitches)
	
	# Blank the existing values
	for i in range(optionsLength):
		currentSwitches[i] = False
	
	# Read in the new list from the multi-state dropdown box. 
	# This is a list of indexs that need to be True in the Bool array
	newSwitchList = currentValue.value
	
	# iterate through the list and select each bool swtich (only if it contains something)
	if newSwitchList is not None:
		for item in newSwitchList:
			currentSwitches[item] = True
	
	# Finally write the results bak to the bool array
	system.tag.writeBlocking(["[.]SelectedSwitches"],[currentSwitches])
	
	# Debugging, Read back the tag value now to verify succssfull write
	currentSwitches = system.tag.readBlocking(["[.]SelectedSwitches"])[0].value
	print("Read Back:")
	print(currentSwitches)

Here is the output:

INFO | jvm 1 | 2021/09/27 13:39:39 | ****Valued changed
INFO | jvm 1 | 2021/09/27 13:39:39 | Oritional:
INFO | jvm 1 | 2021/09/27 13:39:39 | array(java.lang.Boolean, [True, False, True, False, False, False, False, False, False])
INFO | jvm 1 | 2021/09/27 13:39:39 | Read Back:
INFO | jvm 1 | 2021/09/27 13:39:39 | array(java.lang.Boolean, [True, True, True, False, False, False, False, False, False])

Here is the Tag Browser showing the same tag with element 1 as OFF:
image

Here is the same tag after I select 'restart tag':
image

This appears to be an issue with how I am using WriteBlocking to update the bool array but as there are no errors and its kinda working I am not sure where to go. :confused:

Any Idea's??
Is this a Bug or what am I doing wrong?

Thanks :+1:

Look at the return value(s) from writeBlocking(). Errors are returned as bad qualities. It might not actually be working.

Thanks pturmel for the reply.

I forgot to include in my first post that I ran the script in the script console (some minor modifications required as “currentValue” is out of scope) looking for any issues that might explain this.
When I do this writeBlocking returns “[Good]” in the output.

writeBlocking is working (mostly) because when I read back the values in the script the new values are shown (see script output in the first post) also if at any point I select “restart tag” the new values are shown.

If I figure this out I will update this topic

Any other suggestions are welcome?

I am going to try writing to the each bit using writeBlocking latter rather than the whole array at once. Maybe I have more success doing this?

It appears that writing to the whole BoolArray in one hit or at least the way I was doing it is either wrong or causes a bug where ignition does not fire the associated “update” events that normally occur on writing. This only appears to be an issue with the script when run on a tag change event with relative UDT tag paths, running the same code in the script console using full tag paths work just fine.

I found that by writing to each bit in the array (multiple tag paths and values) rather than the whole array in one hit (single path and value) all the associated update events trigger as expected.

Working code:

	try:
		# read in the switch values. Mainly for the length of the array
		# as this may change in the future, all other values will be 
		# overwritten
		currentSwitches = system.tag.readBlocking(["[.]SelectedSwitches"])[0].value
		optionsLength = len(currentSwitches)
		
		#define lists to store values for writebloking function
		paths = []
		values = []
		
		# Blank the existing values
		for i in range(optionsLength):
			values.append(False)
			paths.append("[.]SelectedSwitches[" + str(i) +"]")
	
		# Read in the new list. 
		# This is a list of indexs that need to be True in the Bool array
		newSwitchList = currentValue.value
		
		# if the switchList is not null then 
		# iterate through the list and set each bool switch to true if found
		if newSwitchList is not None:
			for item in newSwitchList:
				values[item] = True
			
		# Finally write the results bak to the bool array
		result = system.tag.writeBlocking(paths,values)
	
	except: 
		print("Error in Value change Script " + tagPath)