我正在使用node-opcua编写一个布尔值来设置一个重置标记。下面是我的代码:
var nodesToWrite = new Array();
nodesToWrite.push({
nodeId: 'ns=2;s=Paint.PLC.Reset_Auto_Blocked_Time',
attributeId: opcua.AttributeIds.Value,
indexRange: null,
value: {
value: {
dataType: opcua.DataType.Boolean,
value: true
}
}
});
self.uaSession.write(nodesToWrite, function (err, statusCode, diagnosticInfo) {
if (!err) {
console.log(" write ok");
console.log(statusCode);
console.log(diagnosticInfo);
} else {
console.log(" write err = ", err);
}
})它实际上不会调用"err“,因为控制台记录如下:
[{ [Number: 2155085824
value: 2155085824,
description: 'The value supplied for the attribute is not of the same type as the attribute\'s value.',
name: 'BadTypeMidmatch' }]
[]然而,这显然是一个错误,写入永远不会完成。标记在KEPServer中设置为布尔值,可以很好地工作。我不知道为什么它说这是不匹配的。有什么帮助吗?
发布于 2018-08-31 00:53:02
看起来opcua.DataType.Boolean不是预期的类型。
我将首先读取该变量,以验证dataType的设置:
var nodeToRead = {
nodeId: 'ns=2;s=Paint.PLC.Reset_Auto_Blocked_Time',
attributeId: opcua.AttributeIds.Value,
};
self.uaSession.read(nodeToRead , function (err, dataValue) {
if (!err) {
console.log(" read ok");
console.log(dataValue.toString());
} else {
console.log(" read err = ", err);
}
});发布于 2019-08-21 10:32:28
只需在value.value.dataType中使用"Boolean“
例如:
nodesToWrite.push({
nodeId: 'ns=2;s=Paint.PLC.Reset_Auto_Blocked_Time',
attributeId: opcua.AttributeIds.Value,
indexRange: null,
value: {
value: {
dataType: "Boolean",
value: true
}
}
});发布于 2019-08-25 05:36:41
有一个选项可以读取节点的builtInType
const nodeToRead = {
nodeId: 'ns=2;s=Paint.PLC.Reset_Auto_Blocked_Time',
attributeId: opcua.AttributeIds.DataType,
};
const dataValue = await self.uaSession.read(nodeToRead);
// check IdentifierType(Numeric) and identifierNumeric(1 to 25) of dataType
// E.g: Boolean - 1, String - 12, Int16 - 4 , etc
// Fill nodesToWrite depending on the builtInType
const nodesToWrite = [];
nodesToWrite.push({
nodeId: 'ns=2;s=Paint.PLC.Reset_Auto_Blocked_Time',
attributeId: opcua.AttributeIds.Value,
indexRange: null,
// check builtInType-type and fill nodesToWrite
});
await self.uaSession.write(nodesToWrite);https://stackoverflow.com/questions/52098819
复制相似问题