Page 1 of 1

how to copy a boolean value to a variable

Posted: 14 Jul 2022, 15:52
by mjalas
Hi all
I am trying to change a Boolean variable from false to true in my plc. for changing the Int32 type there is no problem. but for the Boolean it shows the error "BadNotWritable". Any help?
Thanks
nodeToWrite.create(1);
nodeToWrite[0].AttributeId = OpcUa_Attributes_Value;
UaNodeId myNodeId("\"timer5\".Q", 3);
tempValue.setBoolean(OpcUa_True);
tempValue.copyTo(&nodeToWrite[0].Value.Value);

Re: how to copy a boolean value to a variable

Posted: 11 Aug 2022, 15:58
by Support Team
Hi,

inside PLCs the data type of boolean is different than in the world of programmers false/true, 0/1, 0/-1 or 0/anything else but 0. An OPC Server that presents the value as being type "boolean" should also be able to write (and convert) correctly, so that the related PLC understand. On the UA side of the equation (between client and server) it is all clear and standard, no doubt, no interpretation.

However the StatusCode gives you a pretty good hint, this node does not allow you to write on it (which a server ccould decide for every single node individually). Reason could be: It is a read only node. Other reason could be this node allows only to be written completely (but not parts of it) for consistency reason or for internal handling reasons.

Example: a byte can be 8 bits, so you may "read" 8 individual booleans or you can read one byte, however when you write to it, you must write the complete byte, because that is how it is stored internally in the PLC, all the 8 individual booleans will be bad not writable.

Note: carefully read the documentation of the vendor of the device and check if partially writing of booleans is allowed.