Having trouble writing to bits in Schneider M258 PLC through Modbus TCP. Error :Bad

My client has given me an exchange table with this M258 PLC. The connection is Modbus TCP.

I am able to read bits, integers and strings from addresses that are meant for me to read. I have selected Zero Based Addressing and Reverse String Byte Order in the Modbus TCP driver configuration.

However, I am unable to write to bits of other addresses that they have specified for incoming communication. The error shown when I try to change the Boolean bit to high is:

Error writing to TestTag1: Bad

My OPC item path is [M258PLC]HR503.0 and I changed the bit high by clicking the checkbox in the tag browser.

Is there an error in the gateway logs when you attempt this?

Unfortunately it’s common for Modbus devices to not support the Mask Write Register function, which is required to safely write to bits within a register.

Yes, i think it is the mask write register function.

MaskWriteRegisterRequest Received response with ExceptionCode: 0x01 (IllegalFunction).

Im getting a lot of log messages , hopefully this is the error caused by the write.

Yes, this is caused by the write and it’s the PLC telling you it doesn’t support that function.

You’re going to have to resort to doing read/modify/write via scripting, or if you’re using Ignition 8 it might be possible with derived tags, in order to new write register values with whatever bits you’re interested in modifying.

Okay, i am using Ignition 8.1.3

I found one of your posts on using expressions. May I know if this is correct to write to HR503.0 ?


if({1}, 
	toInt({tag path of the modbus tag with entire HR503 word }) | (1 << 0), 
	toInt({tag path of the modbus tag with entire HR503 word}) & ~(1 << 0))

Yeah, for the Write Expression of a Derived Tag that seems right-ish.

The original post, for reference:

It worked!! Thank you so much!!

If you’re going to use this strategy with multiple bits in the same register you need to make sure that Optimistic Writes is enabled for the Tag Group these tags all belong to.