如何在不知道端口的情况下通过 node.js 连接到 "In-Sight OPC Server"?

How can I connect to the "In-Sight OPC Server" through node.js without knowing the Port?

这就是我试图创造的,这对我来说是全新的。我希望有人能帮助我。

//this is the part I cannot figure out, maby anyone knows a tool how to find this port
const endpointUrl = "opc.tcp://145.49.49.3:???";

const opcua = require("node-opcua");
const AttributeIds = opcua.AttributeIds;
const OPCUAClient = opcua.OPCUAClient;

(async function main(){

    const client = new OPCUAClient({});
    await client.connect(endpointUrl);
    const session = await client.createSession({userName: "admin", password: ""});

    const dataValue = await session.read({nodeId: "ns=1;s=AcquisitionCount",attributeId: AttributeIds.Value});
    console.log(`Count is ${dataValue.value.value.toPrecision(3)}°C.`);

    await client.closeSession(session,true);
    await client.disconnect();

})();

默认端口是 4840,但您将不得不以一种或另一种方式解决它。

通常您要连接的服务器具有完整的端点 URL、包含的端口、记录的或在某处的某些配置中列出的。