-1

Hiii,有人知道我如何在 kepserver 中编写 Uint16Array 我得到了一些错误:

ConstantStatusCode {
_value: 2147483648,
_description: 'The value is bad but no specific reason is known.',
_name: 'Bad' } ]

我试试这个:

var valor = new Uint16Array([ 2, 23, 23, 12, 24, 3, 25, 3, 26, 3, 27, 3, 28, 1, 43690, 1, 1261, 0, 0, 0, 0, 0, 0, 0, 65535, 11 ])

nodeToWrite[0] = {
nodeId: resolveNodeId("ns=2;s=" + endereco[0].ADDRESS),
attributeId: opcua.AttributeIds.Value,

value: /new DataValue(/{ value: {/ Variant /
dataType: 5,
arrayType: 1,
value: valor,
}
}
}
4

1 回答 1

0
const {AttributeIds, OPCUAClient, DataType, VariantArrayType} = require("node-opcua");

const endpointUrl = "opc.tcp://localhost:48010";
(async () => {

    const client = OPCUAClient.create({ endpoint_must_exist: false});

    await client.withSessionAsync(endpointUrl, async (session) => { 

        const arrayOfvalues = new Uint16Array([ 2, 23, 23, 12, 24, 3, 25, 3, 26, 3, 27, 3, 28, 1, 43690, 1, 1261, 0, 0, 0, 0, 0, 0, 0, 65535, 11 ]);
        const nodeToWrite = {
            nodeId: "ns=2;s=Demo.Static.Arrays.UInt16",
            attributeId: AttributeIds.Value,
            value: { 
                value: {
                    dataType: DataType.UInt16,
                    arrayType: VariantArrayType.Array,
                    value: arrayOfvalues,
                }
            }
        }
        const statusCode = await session.write(nodeToWrite);        
        console.log("write statusCode = ",statusCode.toString());
    });
})();

在此处输入图像描述

如上所示,当从 Unified Automation 寻址 UAServerCPP 的节点 ns=2;s=Demo.Static.Arrays.UInt16 时,可以编写 Uint16 数组。

我会联系 Kepware 寻求支持。

于 2019-08-21T23:16:01.107 回答