How to set status, hasStatus, hasValue for a node?

192 views
Skip to first unread message

Grant Edwards

unread,
Dec 19, 2016, 11:45:26 AM12/19/16
to open62541
I can set the value for a node by calling UA_Server_writeValue(server, *node, var) wherre <var> is a UA_Variant.

How do I set the status code for that node?

For example, somebody when somebody disconnects a sensor, I want to set the status to 'notconnected' for all of the nodes that contain data from that sensor.  I might also like to change the hasValue flag for that node from true to false, how would I do that?

Is UA_Server_write(server, wvalue) the correct way to do that?


Stefa...@yahoo.de

unread,
Dec 20, 2016, 5:42:46 AM12/20/16
to open62541
I think you can do in the UA_DataValue object, in the DataSourceRead (Client reads) Callback (only?) . 

Julius Pfrommer

unread,
Dec 21, 2016, 8:38:26 AM12/21/16
to open62541
Yes. UA_Server_write is the right function for that.
UA_Server_writeValue is shorthand for the common case where only the value is changed and not the statuscode.

I added some more examples for this to the repository: https://github.com/open62541/open62541/blob/0.2/examples/server_variable.c#L73

Best regards,
Julius

Grant Edwards

unread,
Dec 21, 2016, 9:35:32 AM12/21/16
to open62541


On Wednesday, December 21, 2016 at 7:38:26 AM UTC-6, Julius Pfrommer wrote:

Yes. UA_Server_write is the right function for that.

Thank you for the confirmation.  I had looked at the source for UA_Server_writeValue() and used that as a basis for my code that needed to set the status and/or the hasValue flag.  It seems to br working as I expected.

Grant Edwards

unread,
Dec 21, 2016, 9:44:36 AM12/21/16
to open62541, Stefa...@yahoo.de


On Tuesday, December 20, 2016 at 4:42:46 AM UTC-6, Stefa...@yahoo.de wrote:

I think you can do in the UA_DataValue object, in the DataSourceRead (Client reads) Callback (only?) . 

The nodes in question do not have datasource callbacks.  These nodes change very infrequently.  Using a datasource callback would impose a lot of extra overhead for  the 99.999% of read operations where the value is unchanged since the previous read.  In situations like that, I use an onread() callback, which appears to impose much less overhead in the case where the value/status hasn't changed.  Ideally, I wouldn't need to use an onread() callback and could just modify the node whenever I an notified that the underlying data has changed. But, the functions used to read/write node values don't appear to be thread-safe unless you enable the multi-threading option when building the library.  That option appears to cause the server itself to use multiple threads, which I don't want.
Reply all
Reply to author
Forward
0 new messages