You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Node-OPCUA对接Codesys PLC时报警确认报“Acknowledge Method Not Found”错误

Node-OPCUA调用报警确认方法报错:cannot find Acknowledge Method(对接Codesys PLC)

环境与目标

  • OPC UA客户端:Node-OPCUA v2.115.0,Node.js v20.10.0
  • 操作系统:Windows 11 Pro(版本10.0.22631 Build 22631)
  • 设备:华硕灵耀(ASUS ZenBook)笔记本
  • 对接目标:CODESYS Control Win V3 x64(版本3.5.19.3)的OPC UA服务器,实现报警确认功能

当前问题

已成功连接本地Codesys PLC,可正常读写数值、查看报警状态,但调用acknowledgeCondition或confirmCondition函数确认报警时,触发错误:Error: cannot find Acknowledge Method。传入的ConditionId和EventId均来自EventMonitor.on()的返回值,而UAExpert可正常完成报警确认操作,推测问题出在Node-OPCUA客户端实现上。

预期行为

调用报警确认方法后,报警状态应同步更新到Codesys PLC中,标记为已确认。

相关代码

import express from "express";
import { createServer } from 'node:http';
import { AttributeIds, OPCUAClient, TimestampsToReturn, constructEventFilter, ObjectIds } from "node-opcua";
                                                                                            
const app = express();
const server = createServer(app);

const URL = "opc.tcp://ADRIAN-ASUS:4840";

(async () => {
    try {
        const client = OPCUAClient.create();
        client.on("backoff", (retry, delay) => {
            console.log("Retying to connect to ", URL, " attempt ", retry);
        });
   
        console.log("connecting to ", URL);
        await client.connect(URL);
        console.log("connected to ", URL);

        const session = await client.createSession();
        console.log("session initialized");

        const subscripcion = await session.createSubscription2({
            requestedPublishingInterval: 50,
            requestedMaxKeepAliveCount: 20,
            publishingEnabled: true,
        });

        const fields = [
            "EventId",
            "AckedState",
            "AckedState.Id",
            "ConfirmedState",
            "ConfirmedState.Id",
            "ConditionId",
        ];

        const eventFilter = constructEventFilter(fields);

        const itemToMonitor = {
            nodeId: ObjectIds.Server,
            attributeId: AttributeIds.EventNotifier,
        };

        const parameters = {
            filter: eventFilter,
            discardOldest: true,
            queueSize: 100,
        };

        const EventMonitor = await subscripcion.monitor(
            itemToMonitor,
            parameters,
            TimestampsToReturn.Both
        )

        const alarmData = {};

        EventMonitor.on("changed", (events) => {
            for (let i = 0; i < events.length; i++) {
                alarmData[fields[i]] = events[i].value;
            }
        });

        setTimeout(async () => {
            try {
                const comment = 'Comment random';
                console.log({conditionId: alarmData.ConditionId, eventId: alarmData.EventId});
                session.acknowledgeCondition(alarmData.ConditionId, alarmData.EventId, comment, (err) => {
                    console.log({ err });
                }); 
            } catch (error) {
                console.log(error);
            }
        }, 5000);

        let running = true;
        process.on("SIGINT", async () => {
            if (!running) return;
            console.log("shutting down client");
            running = false;
            await subscripcion.terminate();
            await session.close();
            await client.disconnect();
            console.log("Done");
            process.exit(0);
        });
    } catch (error) {
        console.log("ERROR: ", error.message);
        console.log(error);
    }

    server.listen(4000, () => {
        console.log('server running at http://localhost:4000');
    });
})();

错误与日志

  • 报警确认触发的错误:Error: cannot find Acknowledge Method
  • conditionId和eventId控制台输出:
    { 
      conditionId: { dataType: 'NodeId', value: 'ns=4;s=|var|CODESYS Control Win V3 x64.Application.GVL.AlarmTest' }, 
      eventId: { dataType: 'ByteString', value: <Buffer 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00> } 
    }
    
  • 调试发现translateBrowsePath回调返回状态码:
    statusCode: BadNodeIdUnknown (0x80340000) {
         _description: 'The node id refers to a node that does not exist in the server address space.',
         _name: 'BadNodeIdUnknown',
         _value: 2150891520,
    }
    

补充信息

  • Node-OPCUA通过npm安装
  • UAExpert可正常查看并完成报警确认,排除服务器端问题
  • 尝试更换多个Node.js版本,问题未解决

内容的提问来源于stack exchange,提问作者Adrian Acurero

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.05 09:35:05