我遇到了一个节点-opcua库的问题。我们使用库来设置一个客户端,该客户端在Kepware Server (v6)上匿名连接。
应用程序在调试和各种服务器的生产中运行良好,但似乎无法在我们试图安装的特定服务器上创建会话。
让我觉得这是一个互操作性问题的是,当我们第一次在服务器上安装这个应用程序时,它制作了另一个应用程序(Cimplicity),它为Kepware server提供了崩溃的信息。
该应用程序是一个电子应用程序使用节点-opcua最新。“问题服务器”是一个带有Microsoft 2019的VM。
这里是我的opcua服务代码:
const opcua = require("node-opcua");
const path = require("path");
let conf = global.conf;
const { ipcMain } = require("electron");
const log = require("electron-log");
const options = {
applicationName: "Ganex OPC UA Server",
connectionStrategy: opcua.connectionStrategy,
securityMode: opcua.MessageSecurityMode.None,
securityPolicy: opcua.SecurityPolicy.None,
endpoint_must_exist: false,
};
class OPCUAService {
eventEmitter;
static setEventEmitter(eventEmitterObj) {
this.eventEmitter = eventEmitterObj;
this.eventEmitter.on("updatedAuthentication", () => {
// config = require("../config/configUrl");//in theory should get the new config from file if its updated
console.log("Updated Conf?", conf.get("auth:opcUrl"));
});
}
static async readData(addressArray) {
const client = opcua.OPCUAClient.create();
const endpointUrl = conf.get("auth:opcUrl");
const opcUserName = conf.get("auth:opcServerUserName");
const opcPassword = conf.get("auth:opcServerPassword");
client.on("backoff", () => {
console.log("backoff");
globalThis.connected = false;
log.info("Error connecting to OPC Server", "Can't access the OPC Server");
});
client.on("connected", () => (globalThis.connected = true));
if (globalThis.connected) {
log.info("OPC Server is accessible? ", globalThis.connected);
}
try {
console.log("Start!");
log.info("Connecting to OPC");
//var userIdentityInfo = new usr
await client.connect(endpointUrl);
//const session = await client.createSession({});
//const session = await client.createSession({userName: opcUserName, password: opcPassword});
/* const session = await client.createSession({}, (err) => {
if (err) {
log.info("Error at session creation", err);
} else {
log.info("Session successfully created", err);
}
}); */
const session = await client.createSession({});
log.info("Session created? ", session? "true" : "false");
log.info ("Session Content", addressArray);
console.log("Session Content", addressArray);
for (let count = 0; count < addressArray.length; count++) {
const readResult = await session.read({
nodeId: addressArray[count].address,
attributeId: opcua.AttributeIds.Value,
});
addressArray[count].value = parseFloat(
readResult.value.toString().replace(/[^\d.-]/g, "")
).toFixed(addressArray[count].precision);
}
await session.close();
log.info("Disconnected from OPC");
await client.disconnect();
return addressArray;
} catch (err) {
log.info("Error connecting to OPC Server", err);
log.error(err.toString());
console.log("Err =", err);
}
}
}
module.exports = OPCUAService;问题似乎是在会话创建级别。下面是来自工作服务器的日志摘录:
[2021-12-20 08:03:00.004] [info] @@@ running processSolarFacilityMetData Task every 1 minute(s)
[2021-12-20 08:03:00.111] [info] OPC Server is accessible? true
[2021-12-20 08:03:00.144] [info] Connecting to OPC
[2021-12-20 08:03:00.174] [info] @@@ running processPowerData Task every 1 minute(s)
[2021-12-20 08:03:00.191] [info] OPC Server is accessible? true
[2021-12-20 08:03:00.236] [info] Connecting to OPC
[2021-12-20 08:03:00.605] [info] Session created? true
[2021-12-20 08:03:00.608] [info] Session Content [object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[2021-12-20 08:03:00.627] [info] Session created? true
[2021-12-20 08:03:00.637] [info] Session Content [object Object],[object Object]
[2021-12-20 08:03:00.765] [info] Disconnected from OPC
[2021-12-20 08:03:01.381] [info] Disconnected from OPC和一个来自问题服务器的
Starting up application @ C:\Program Files\Forecast Compliance...
[2021-12-20 06:31:12.280] [info]
[2021-12-20 06:31:14.814] [info] solarFacilityData: undefined
[2021-12-20 06:32:00.001] [info] @@@ running processPowerData Task every 1 minute(s)
[2021-12-20 06:32:00.011] [info] Connecting to OPC
[2021-12-20 06:32:00.020] [info] @@@ running processSolarFacilityMetData Task every 1 minute(s)
[2021-12-20 06:32:00.022] [info] Connecting to OPC
[2021-12-20 06:33:00.006] [info] @@@ running processPowerData Task every 1 minute(s)
[2021-12-20 06:33:00.013] [info] Connecting to OPC
[2021-12-20 06:33:00.017] [info] @@@ running processSolarFacilityMetData Task every 1 minute(s)
[2021-12-20 06:33:00.019] [info] Connecting to OPC
[2021-12-20 06:34:00.002] [info] @@@ running processSolarFacilityMetData Task every 1 minute(s)
[2021-12-20 06:34:00.003] [info] Connecting to OPC
[2021-12-20 06:34:00.005] [info] @@@ running processPowerData Task every 1 minute(s)有没有人知道如何解决这类问题?
提前感谢!
发布于 2021-12-20 17:52:09
看来连接方法没有返回。
await client.connect(endpointUrl);在无法到达的服务器上,我们期望定期引发退避事件,以指示connect函数正在重新尝试失败的连接。我们没有这个。
另外,您有一个try/catch块,没有错误消息,这导致我认为在套接字或服务器端发生了一些事情。
这个案子需要更深入的调查。我建议与节点-opcua支持小组联系(更多信息见网站)。
免责声明,我是节点-opcua库的作者.
https://stackoverflow.com/questions/70423972
复制相似问题