无法使用node-opcua连接到Prosys OPC UA模拟服务器

问题描述 投票:0回答:1

我正在尝试使用node-opcua库构建一个opcua客户端,并且我正在通过尝试让它连接到Prosys OPC UA模拟服务器来测试它。我使用基本客户端示例来尝试连接,但它似乎不起作用,而且我无法理解错误消息。

代码:-

import {
    OPCUAClient,
    MessageSecurityMode,
    SecurityPolicy,
    AttributeIds,
    makeBrowsePath,
    ClientSubscription,
    TimestampsToReturn,
    MonitoringParametersOptions,
    ReadValueIdOptions,
    ClientMonitoredItem,
    DataValue,
} from "node-opcua";

const connectionStrategy = {
    initialDelay: 1000,
    maxRetry: 1
};

const client = OPCUAClient.create({
    applicationName: "MyClient",
    connectionStrategy: connectionStrategy,
    securityMode: MessageSecurityMode.None,
    securityPolicy: SecurityPolicy.None,
    endpointMustExist: false
});

const endpointUrl = "opc.tcp://localhost:53530/OPCUA/SimulationServer"

async function main() {
    try {
        console.log("attempting to connect...");

        // step 1 : connect to
        await client.connect(endpointUrl);
        console.log("connected !");

        // // step 2 : createSession
        // const session = await client.createSession();
        // console.log("session created !");

        // step 3 : browse

        // step 4 : read a variable with readVariableValue

        // step 4' : read a variable with read

        // step 5: install a subscription and install a monitored item for 10 seconds

        // step 6: finding the nodeId of a node by Browse name

        // close session

        // disconnecting
    } catch (err) {
        console.log("An error has occurred : ", err);
    }
}
main();

错误信息:-

attempting to connect...
An error has occurred :  AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:

  (0, assert_1.default)(s.length <= maxLength)

    at parseBitString (C:\Users\binahmad\Documents\SWE\code\1 - Projects\20230717_opcua_Interface_testing_tool\sample-node-opcua-client\node_modules\node-opcua-crypto\source\asn1.ts:91:15)
    at _readBitString (C:\Users\binahmad\Documents\SWE\code\1 - Projects\20230717_opcua_Interface_testing_tool\sample-node-opcua-client\node_modules\node-opcua-crypto\source\asn1.ts:113:16)
    at _readSubjectPublicKeyInfo (C:\Users\binahmad\Documents\SWE\code\1 - Projects\20230717_opcua_Interface_testing_tool\sample-node-opcua-client\node_modules\node-opcua-crypto\source\crypto_explore_certificate.ts:552:44)
    at readTbsCertificate (C:\Users\binahmad\Documents\SWE\code\1 - Projects\20230717_opcua_Interface_testing_tool\sample-node-opcua-client\node_modules\node-opcua-crypto\source\crypto_explore_certificate.ts:665:40)
    at exploreCertificate (C:\Users\binahmad\Documents\SWE\code\1 - Projects\20230717_opcua_Interface_testing_tool\sample-node-opcua-client\node_modules\node-opcua-crypto\source\crypto_explore_certificate.ts:714:29)
    at publicKeyAndPrivateKeyMatches (C:\Users\binahmad\Documents\SWE\code\1 - Projects\20230717_opcua_Interface_testing_tool\sample-node-opcua-client\node_modules\node-opcua-crypto\source\public_private_match.ts:30:33)
    at C:\Users\binahmad\Documents\SWE\code\1 - Projects\20230717_opcua_Interface_testing_tool\sample-node-opcua-client\node_modules\node-opcua-client\source\verify.ts:131:39
    at Generator.next (<anonymous>)
    at C:\Users\binahmad\Documents\SWE\code\1 - Projects\20230717_opcua_Interface_testing_tool\sample-node-opcua-client\node_modules\node-opcua-client\dist\verify.js:8:71 
    at new Promise (<anonymous>) {
  generatedMessage: true,
  code: 'ERR_ASSERTION',
  actual: false,
  expected: true,
  operator: '=='
}

我觉得它应该可以工作,但我的系统或我的节点而不是代码可能有问题。

我尝试使用 UaExpert 连接到服务器并且成功,我还尝试使用 python 脚本连接并且成功。它只是似乎受到影响的节点。

节点版本:v16.15.0

node-opcua版本:^2.108.0

如果有人可以帮助我弄清楚如何简单地连接,那将非常有帮助

javascript node.js typescript opc-ua node-opcua
1个回答
0
投票

在尝试创建模拟服务器时,我在 node-opcua 包中看到了相同的错误。当在使用节点版本 14.16.1 的容器中运行时,此操作会失败,但如果我在节点版本 16.15.1 的系统上运行它,则此操作会起作用。您可以尝试较新版本的node或较旧版本的node-opcua。

我已恢复使用 node-opcua 版本 2.50.0,并且初始化服务器和连接到服务器都正常。

© www.soinside.com 2019 - 2024. All rights reserved.