how to copy a boolean value to a variable

Unified Architecture topics related to OPC UA Specification, compliant behavior and any technical issues of OPC UA, like Security, Information Model, Companion Specs DI, PLCopen, ADI, ...

Moderator: Support Team

Post Reply
Jr. Member
Jr. Member
Posts: 1
Joined: 13 Jul 2022, 09:54

how to copy a boolean value to a variable

Post 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?
nodeToWrite[0].AttributeId = OpcUa_Attributes_Value;
UaNodeId myNodeId("\"timer5\".Q", 3);

User avatar
Support Team
Hero Member
Hero Member
Posts: 2787
Joined: 18 Mar 2011, 15:09

Re: how to copy a boolean value to a variable

Post by Support Team »


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.
Best regards
Unified Automation Support Team

Post Reply