Writing a bit, integer tag

I’m trying to write to a bit (bit #6) of an integer tag with no luck.

Following this
https://www.inductiveuniversity.com/videos/addressing-bits/7.9

I copied my tag int_read1 (copy became int_read2), changed the OPC Item path to int_read1.5.
I can read the bit by writing to int_read1
image

image

but if I try to write to it I get an error.
image

I’m using 8.0.0 (b2019040718).
Full read/write gateway communications are allowed.
The tag has Read/Write access writes.

What am I missing?
Thanks

Are you getting that error when toggling the checkbox right in the tag browser? Or just in a piece of code?

Error occurs when toggling the checkbox in tag browser.

What OPC Server / Driver is this tag coming from?

I’m using the Modbus TCP driver
Ignition OPC-UA Server

I’m using Productivity 2000 PLCs from Automation Direct

Check the gateway logs for errors.

Your device probably doesn’t support the MaskWriteRegister request, which is required for writing to individual bits within a word.

You mean something like this…

That stinks!!

In spite of that, I happen to be a fan of those processors… they have built-in support for Ethernet/IP I/O devices, as both scanner and adapter. And my I/O driver does have support for bit-level reads and writes within its buffers. (-:

So it turns out the P2K line of PLCs does not accept the ‘MaskWriteRegisterRequest’ from the driver as Kevin had guessed.

In case anyone else is trying to do the same, this is the sudo script I wrote to accomplish flipping a single bit to a 1.

	currentTag = system.tag.readBlocking(["Path/to/tag"])
	setBit = 8 #Bit position to set
	newValue = 1 << setBit #set bit in correct position
	system.tag.writeAsync(["Path/to/tag"],[newValue | currentTag[0].value]) # OR new value to current tag value
1 Like

Just be careful and aware of the race condition - if some other process writes to the value, or the PLC changes the value, in between your read and write you’ll clobber that value.

1 Like

I’m writing to HR100.Bit from Ignition but it returns the illegal function code error in gateway log.
From PLC document, it supports the function code x16.

Any idea how to fix this?

If I’m not mistaken. My memory is that the you need the PLC to support the ‘Mask Write Register’ function which I believe is function code 22.

I think function code 16 is for write multiple.

Thank you. Seems, I have to go with the script to do this. :smiley: