Issues writing to tag boolean value

I have button which triggers an event on double click.

Essentially, I am reading the tag for its True/False Value. So far so good using:-
tagLineRead = system.tag.readBlocking([self.view.params.TagLineRead])[0].value

I am basically toggling the value... so I flip it...
tagLineWrite = not tagLineRead # False is now True... or True is now False

However, when I try to write the value... nothing is happening. I have tried replacing True/False with 1/0 respectively and, again.. nothing.

This is the code I am using:-

writePaths = [self.view.params.TagLineWrite]
writeValues = [tagLineWrite]
system.tag.writeBlocking(writePaths, writeValues)

I created a popup so I can confirm the tagLineRead is a boolean, and that tagLineWrite is correctly set to the opposite value.

I also wrapped the code around a Try-Except... and there is no exception error (which would have created a popup)

I can only assume the issue is related to sending to boolean tags ????

All examples I see for writeBlocking send text and numbers.. but not boolean.

I came across similar queries but does not solve my problem--

The tag I am using to write to -- looks fine. Others have verified this also in team. If I can attach screen shots, I will be happy to provide anything (on request)

If I can be any further help with this query -- please let me know.

Thanks.

Could you supply the full code of the onDoubleClick Event so that we can verify there are no other potential issues preventing the latter code from executing?

Have you already checked your Gateway logs to verify the code is not encountering an issue when executed?

Could you provide a screenshot of the actual Event configuration dialog? I'd like to verify you have this in the onDoubleClick Event, and not on the Click event, which would just be cancelling itself out when performing a double-click.

self.view.params.TagLineRead and self.view.params.TagLineWrite are not tag paths?? So, if these properties are tag bindings, there is no need to tag read and write. Make the bindings bi-directional and you can just set the property to update the tag source.

I just tried this with the following code and it worked as expected:

    tagPath = "[default]Experimentation/New Tag"
	tagLineRead = system.tag.readBlocking([tagPath])[0].value
	tagLineWrite = not tagLineRead
	system.tag.writeBlocking([tagPath], [tagLineWrite])

Thank you both for taking the time to respond.

(I could not 'At' you both, as it wouldn't allow me for being a new user)

It is appreciated. Please see my reply which should cover both your queries.

The...
self.view.param.TagLineRead
...and...
self.view.param.TagLineWrite
...are parameters I have created, as you can create them in a View (at least in perspective.. not sure about Vision)

I am making use of these to simplify my project. This view is being used in multiple places, each using different tags for reading and writing to.

It is best to see TagLineRead and TagLineWrite with these values:-

"[default]L1_to_4_Ignition_Read/L1_to_4_Ignition_Read_0_[0]"
"[default]L1_to_4_Ignition_WriteV1/L1_to_4_Ignition_WriteV1_0_[0]"

Also note there is another self.view.param I use which holds a tag that write integer values - and this is working. This is why I believe the issue could related to boolean values.

I will be attaching a screenshot of the Event Configuration...
I know the code on dbl click triggers because I included a popup view to help debug.
Here is the double click code with additional comments. It is essentially the line-by-line in the original post.

def runAction(self, event):
	"""
	Method that will run whenever the selected event fires.
        ...Snipped... to shorten
	"""
	try:
		tagLineRead = system.tag.readBlocking([self.view.params.TagLineRead])[0].value
		tagLineWrite = not tagLineRead

                # The commented codes was used for popup debugging information
                # It was there to prove:-
                # 1) tagLineRead returned True or False from the tag (this worked)
                # 2) tagLineWrite will store the opposite value (this is ok)
                # 3) I cover what I am writing to - self.view.params.TagLineWrite, which in this case is..
                #     "[default]L1_to_4_Ignition_WriteV1/L1_to_4_Ignition_WriteV1_0_[0]"

		#msg = "current value: " + str(tagLineRead) + ", new value: " + str(tagLineWrite) + " ...To Tag: " + self.view.params.TagLineWrite		
		#system.perspective.openPopup("specialid", "Popups/Alert", params = {'title': 'Change trigger', 'message': msg})

		writePaths = [self.view.params.TagLineWrite]
		writeValues = [tagLineWrite]
		system.tag.writeBlocking(writePaths, writeValues)
	except Exception as e:
		system.perspective.openPopup("specialid", "Popups/Alert", params = {'title': 'Error', 'message': str(e)})

Was this tested with boolean value?
I can get this to work for Integer.

Thanks.

I just edited my main reply and after 'Save and Close' (to fixing some mistakes) -- but it has disappeared. Very frustrated.
I am hoping it will return.


Unrelated, but before you get too far down the rabbit hole, I would strongly recommend you write a project function to handle opening this error popup. Calling that openPopup function everywhere will get old very quickly, and also mean you can't easily change it if you need to add additional functionality to it. Also, you can use

import traceback
traceback.format_exc()

to get the error info

Hi and thank you for the tip.

This popup was purely created to help aid/resolve this problem. Once sorted and back on track I will be handling these types of things much better.

The idea of of a project function and using traceback has been noted. Thank you.

Where are you testing in? The designer? Do you have gateway write option enabled?

I am using the designer. There is a Play button but I am mostly doing "Tools->Launch Perspective->Launch Session" for testing. I save changes beforehand.

As for Gateway Write Open -- I am not familiar with this.

My first reply has been hidden (I edited it to correct something) -- which is under review. Kinda repeating what is in that reply...

One thing to note... I can get writeBlocking to work for integer values. There is another tag I use to send a number, and this is working. It just doesn't work for boolean. I am bringing this up because I don't know if this means that Gateway Write is enabled.

Cheers

1 Like

Ok, if you can write other values then the option is set to read/write. It's in the top left in the toolbar. 3 icons: no comms, read only, and read write

What is the result from the write function? Just wrap the write call inside system.perspective.print
A failed write is not an exception, and you have to catch these using the return value from the write

Again -- thanks for helping.

I have updated to code to get the response from writeBlocking, send dumped in perspective.print.

I am getting an error - but I need to speak to engineering on this. I will get back ASAP with any errors printed once I confirmed all other parts are fully operational.

Hi -- update on the situation.

Apologies in the delay - I have just spoken with an engineer and, after tests, it appears it works when I setup a tag directly to an index.

I will provide screenshots to help with my (poor) explanation. Maybe the original way can still be done?

So.. a tag originally was created as a Boolean Array.
When I try to tick the first index, or any of the indexes for that matter, it pops up this error:-
"Error writing to L1_to_4_Ignition_WriteV1_0_[0].value: Error_Exception("Error writing to tag '[default]L1_to_4_Ignition_WriteV1/L1_to_4_Ignition_WriteV1_0_': null")"
ticking_from_bool_array

However, when I created a tag for the first index, it works when I toggle the value. SUCCESS
ticking_from_boolean_index0

So I have figured out how to "fix" the issue.
The downside to this approach is I have to create a tag for each index (16 of them)

Can I still create a tag as a Boolean Array? This would make life easier. Perhaps we are doing something wrong. Maybe the screens will help with this.

Thanks.

No, not for that PLC. Whether an array is writable and/or writable by element is very dependent on PLC and driver support. Your test showed it wasn't supported.

That you all for taking the time to help me resolve the issue.

We got there in the end.

Overall, I was not doing anything wrong - generally - except trying to write to an index/element of a boolean array.

When I created a tag directly to index[0] - it worked.

Looks like I will have to create a tag for each index. Not the end of the world.

Again - thank you all.

I wonder how writing to a boolean array appears in the audit log? This, tag security, and the potential complexity of pathing to the tags would be my biggest turn offs to using boolean arrays. Especially considering (from my understanding) that you're not gaining any efficiencies in comms by doing it that way instead of using multiple bool tags. I think it would also make pages with bindings to its bits update more frequently and unnecessarily due to the change of any of the bools in the array triggering change events on all of the bools (unless I'm misunderstanding them)