首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法使用节点操作(BadTypeMismatch)写入标记

无法使用节点操作(BadTypeMismatch)写入标记
EN

Stack Overflow用户
提问于 2018-08-30 21:53:51
回答 3查看 660关注 0票数 0

我正在使用node-opcua编写一个布尔值来设置一个重置标记。下面是我的代码:

代码语言:javascript
复制
    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“,因为控制台记录如下:

代码语言:javascript
复制
[{ [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中设置为布尔值,可以很好地工作。我不知道为什么它说这是不匹配的。有什么帮助吗?

EN

回答 3

Stack Overflow用户

发布于 2018-08-31 00:53:02

看起来opcua.DataType.Boolean不是预期的类型。

我将首先读取该变量,以验证dataType的设置:

代码语言:javascript
复制
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);
    }
});
票数 0
EN

Stack Overflow用户

发布于 2019-08-21 10:32:28

只需在value.value.dataType中使用"Boolean“

例如:

代码语言:javascript
复制
   nodesToWrite.push({
        nodeId: 'ns=2;s=Paint.PLC.Reset_Auto_Blocked_Time',
        attributeId: opcua.AttributeIds.Value,
        indexRange: null,
        value: {
            value: {
                dataType: "Boolean",
                value: true
            }
        }
    });
票数 0
EN

Stack Overflow用户

发布于 2019-08-25 05:36:41

有一个选项可以读取节点的builtInType

代码语言:javascript
复制
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);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52098819

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档