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

**URL:** <https://forum.inductiveautomation.com/t/having-trouble-writing-to-bits-in-schneider-m258-plc-through-modbus-tcp-error-bad/49642>\
**Category:** Ignition\
**Created:** [August 6, 2021, 1:15pm UTC](https://forum.inductiveautomation.com/t/having-trouble-writing-to-bits-in-schneider-m258-plc-through-modbus-tcp-error-bad/49642 "2021-08-06T13:15:51Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [August 6, 2021, 1:35pm UTC](https://forum.inductiveautomation.com/t/having-trouble-writing-to-bits-in-schneider-m258-plc-through-modbus-tcp-error-bad/49642/7 "2021-08-06T13:35:58Z")

</div>

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

The original post, for reference:

> [@Troubles making a Derived Boolean Tag work as a mask for a Short Tag](https://forum.inductiveautomation.com/t/troubles-making-a-derived-boolean-tag-work-as-a-mask-for-a-short-tag/15203/2):
>
> I’ve made it work using the following expressions: Read: (toInt({source}) \>\> N) & 1 Write: if({value}, toInt({source}) | (1 \<\< N), toInt({source}) & ~(1 \<\< N)) Where N will vary based on the bit number (0-15 for a Modbus register). You should also turn on the “OPC Optimistic Writes” flag for the scan class these tags belong to or you’re going to have a race condition if you try to write to multiple bits in the same word too quickly.

---

_[View the full topic](https://forum.inductiveautomation.com/t/having-trouble-writing-to-bits-in-schneider-m258-plc-through-modbus-tcp-error-bad/49642)._
