Page 1 of 1

BadNodeIdUnknown error when trying to write to node

Posted: 30 Oct 2018, 00:05

I’m currently evaluating opc and trying to set up a simple client/server that doesn’t use any ui. I’m starting with the Unified Automation examples and modifying them.
I’m using the lesson3 server, and trying to call the Write() function that writes to a specific node on the node manager. I’m printing out the result in my user callback, and I’m consistently getting a “BadNodeIdUnknown” error. Here’s the callback:

Code: Select all

private void UserWriteCallback(NodeAttributeOperationHandle operationHandle, object callbackData, StatusCode result, bool doNotBlockThread)
            Console.Write("\nthis is the User write callback function. Result:\n");

And here’s the code leading up to the Write(). I’m trying to write to node 8008, which is the ID of the property called Humidity of the AirConditioning block. If I connect a client with a session to this server, I’m able to read and write to this node, instantiating the 8008 node just as I do below (with the same namespace index). I think the only difference is that I’m writing directly to the server in this case, but the callback prints out the BadNodeIdUnknown error. Any ideas? Thanks!

Code: Select all

public void WriteToNode()
            Console.Write("writing to node\n");
            WriteCompleteEventHandler delegateWriteEventHandler = new WriteCompleteEventHandler(UserWriteCallback);
            string userCallbackData = "";
            TransactionHandle transaction = new TransactionHandle(Server.DefaultRequestContext, TransactionType.Write, delegateWriteEventHandler, userCallbackData);

            NodeId nodeId1 = new NodeId(8008, 3);
            NodeAttributeHandle nodeAttributeHandle = new NodeAttributeHandle(this, this, this, nodeId1, Attributes.Value);
            NodeAttributeOperationHandle nodeAttributeOperationHandle = new NodeAttributeOperationHandle(nodeAttributeHandle);

            List<NodeAttributeOperationHandle> operationHandles = new List<NodeAttributeOperationHandle>();

            WriteValue writeValue = new WriteValue();
            writeValue.NodeId = nodeId1;
            writeValue.Value.Value = 15.0;

            List<WriteValue> localSettings = new List<WriteValue>();

            Write(Server.DefaultRequestContext, transaction, operationHandles, localSettings);
            Console.Write("wrote to node\n");
I think the issue has something to do with the UserData field in nodeAttributeOperationHandle. The Write() function casts this to an opc Address, but when I'm running the function the USerData hasn't been set. Is there a function that you're supposed to call on an AttributeOperationHandle that will set the UserData so it has the right address for the Underlying System?