I'm using node-opcua to create an opc-ua server using node.js.
On the server-side, I register a method that has an 2-Dimensional Array as an input argument. When browsing the server from a client like UaExpert, I see the method with a proper descriptions of the arguments. I can set the argument-values from the client, but calling the method just fails with a BadInvalidArgument
exception.
As soon as I change the dimension of the array to 1 (by setting valueRank
to 1), everything works as expected.
I'm following the minimal sample from node-opcua on server-methods:
const {
OPCUAServer,
DataType,
Variant,VariantArrayType,
StatusCodes,
makeAccessLevelFlag
} = require("node-opcua");
(async () => {
try {
const server = new OPCUAServer({
port: 4334 // the port of the listening socket of the server
});
await server.initialize();
const addressSpace = server.engine.addressSpace;
const namespace = addressSpace.getOwnNamespace();
const myDevice = namespace.addObject({
organizedBy: addressSpace.rootFolder.objects,
browseName: "MyDevice"
});
//_"adding a method on the device object"
const method = namespace.addMethod(myDevice,{
browseName: "Bark",
inputArguments: [
{
name:"nbBarks",
description: { text: "specifies the number of time I should bark" },
dataType: DataType.Int32,
valueRank: 2,
arrayDimensions: [2, 2]
}
],
outputArguments: [{
name:"Barks",
description:{ text: "the generated barks" },
dataType: DataType.UInt32,
valueRank: -1
}]
});
//_"binding the method with your own function"
method.bindMethod((inputArguments,context,callback) => {
const callMethodResult = {
statusCode: StatusCodes.Good,
outputArguments: [{
dataType: DataType.String,
arrayType: VariantArrayType.Array,
value :99
}]
};
callback(null,callMethodResult);
});
await server.start();
console.log("Server is now listening ... ( press CTRL+C to stop)");
const endpointUrl = server.endpoints[0].endpointDescriptions()[0].endpointUrl;
console.log(" the primary server endpoint url is ", endpointUrl );
}
catch(err) {
console.log(err);
}
})();
Here is a screenshot before calling the method from UaExpert:
It seems the client correctly recognizes the argument as an array with the dimension [2x2]. But when calling the method, I just get a BadInvalidArgument
exception on the client-side.
Any hints what I'm doing wrong?
It's probably a bug in the node-opcua stack.