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");
Console.Write(result);
Console.Write("\n\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>();
operationHandles.Add(nodeAttributeOperationHandle);
WriteValue writeValue = new WriteValue();
writeValue.NodeId = nodeId1;
writeValue.Value.Value = 15.0;
List<WriteValue> localSettings = new List<WriteValue>();
localSettings.Add(writeValue);
Write(Server.DefaultRequestContext, transaction, operationHandles, localSettings);
Console.Write("wrote to node\n");
}