Nodejs OPCUA在一个订阅对象中监视多个项目



我需要订阅子ripiton对象上的多个监控项。我在nodejs中构建了以下代码并正在工作。

const itemToMonitor = {
nodeId: resolveNodeId("ns=2;s=Channel1.Device1.temprature"),
attributeId: AttributeIds.Value
};
const itemToMonitor2 = {
nodeId: resolveNodeId("ns=2;s=Channel1.Device1.altitude"),
attributeId: AttributeIds.Value
};
const monitoringParamaters = {
samplingInterval: 1000,
discardOldest: true
};
the_subscription.monitor(itemToMonitor, monitoringParamaters, TimestampsToReturn.Both, (err, monitoredItem) => {
monitoredItem.on("changed", function (dataValue) {
console.log("monitored item changed:  temprature = ", dataValue.value.value);
});
});
the_subscription.monitor(itemToMonitor2, monitoringParamaters, TimestampsToReturn.Both, (err, monitoredItem) => {
monitoredItem.on("changed", function (dataValue) {
console.log("monitored item changed:  altitude = ", dataValue.value.value);
});
});

但我需要这样的东西:

the_subscription.monitor({itemToMonitor,itemToMonitor2}, monitoringParamaters, TimestampsToReturn.Both, (err, monitoredItem) => {
monitoredItem.on("changed", function (datavalues) {
datavalues.each(){
//
}
});
});

有可能吗?我在.net核心中做了类似的事情:

.net核心代码(我想要的示例(

_subscription.AddItems(_nodes);
_subscription.FastDataChangeCallback = new FastDataChangeNotificationEventHandler(DataChanged);
_session.AddSubscription(_subscription);
_subscription.Create();
private void DataChanged(Subscription subscription, DataChangeNotification notification, IList<string> stringTable)
{
//
}

我已解决;

它错了;

the_subscription.monitor({itemToMonitor,itemToMonitor2}, monitoringParamaters, TimestampsToReturn.Both, (err, monitoredItem) => {
monitoredItem.on("changed", function (datavalues) {
});
});

其真正的

//monitoredNodes is an monitoredItem list
the_subscription.monitorItems(monitoredNodes, monitoringParamaters, TimestampsToReturn.Both, (err, monitoredItems) => {
monitoredItems.on("changed", function (items,data) {
console.log("Node ID: ", items.itemToMonitor.nodeId.value);
console.log("Node value: ", data.value.value);
});
});

文件:https://node-opcua.github.io/api_doc/2.32.0/classes/node_opcua.clientsubscription.html#monitoritems

相关内容

  • 没有找到相关文章

最新更新