I download node-opcua sample server, and I try to add some opc ua nodes, in order to test the server. I was able to create object and variable:
const namespace = addressSpace.getOwnNamespace();
const myDevices = namespace.addFolder(rootFolder.objects, { browseName: "TestFolder" });
const testObj = namespace.addObject({
organizedBy: myDevices,
browseName: "TestObj",
nodeId: "s=TestObj"
});
const testVariable = namespace.addVariable({
componentOf: testObj,
browseName: "TestVar",
nodeId: "ns=1;s=TestVar",
dataType: "Double",
value: new Variant({ dataType: DataType.Double, value: 1000.0 })
});
but I was not able to create Struct (ExtensionObject). I tried something like this:
const testParams = {
firstField: 0,
secondField : 0
};
const structure = addressSpace.findDataType("Structure");
const dataType = namespace.createDataType({
browseName: "TestStuct",
isAbstract: false,
subtypeOf: structure.nodeId
});
const inner_options = {
componentOf: testObj,
browseName: "TestStuctVar",
dataType: dataType.nodeId,
value: testParams
};
const strucVar = namespace.addVariable(inner_options);
but connecting with UA Expert, I got "Null" dataType:
so it seems the server did not add the dataType I created.
With another server, when I add a struct datatype, UA Expert understand the dataType correctly: