QOpcUaNode Class
QOpcUaNode 允许与 OPC UA 节点交互。更多
头文件: | #include <QOpcUaNode> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS OpcUa) target_link_libraries(mytarget PRIVATE Qt6::OpcUa) |
qmake: | QT += opcua |
继承: | QObject |
公共类型
公共函数
QVariant | attribute(QOpcUa::NodeAttribute attribute) const |
QOpcUa::UaStatusCode | attributeError(QOpcUa::NodeAttribute attribute) const |
bool | browse(const QOpcUaBrowseRequest &request) |
bool | browseChildren(QOpcUa::ReferenceTypeId referenceType = QOpcUa::ReferenceTypeId::HierarchicalReferences, QOpcUa::NodeClasses nodeClassMask = QOpcUa::NodeClass::Undefined) |
bool | callMethod(const QString &methodNodeId, const QList<QOpcUa::TypedVariant> &args = QList<QOpcUa::TypedVariant>()) |
QOpcUaClient * | client() const |
bool | disableMonitoring(QOpcUa::NodeAttributes attr) |
bool | enableMonitoring(QOpcUa::NodeAttributes attr, const QOpcUaMonitoringParameters &settings) |
bool | modifyDataChangeFilter(QOpcUa::NodeAttribute attr, const QOpcUaMonitoringParameters::DataChangeFilter &filter) |
bool | modifyEventFilter(const QOpcUaMonitoringParameters::EventFilter &eventFilter) |
bool | modifyMonitoring(QOpcUa::NodeAttribute attr, QOpcUaMonitoringParameters::Parameter item, const QVariant &value) |
QOpcUaMonitoringParameters | monitoringStatus(QOpcUa::NodeAttribute attr) |
QString | nodeId() const |
bool | readAttributeRange(QOpcUa::NodeAttribute attribute, const QString &indexRange) |
bool | readAttributes(QOpcUa::NodeAttributes attributes = mandatoryBaseAttributes()) |
(since 6.7) QOpcUaHistoryReadResponse * | readHistoryEvents(const QDateTime &startTime, const QDateTime &endTime, QOpcUaMonitoringParameters::EventFilter &filter, quint32 numValues = 0) |
(since 6.3) QOpcUaHistoryReadResponse * | readHistoryRaw(const QDateTime &startTime, const QDateTime &endTime, quint32 numValues, bool returnBounds) |
(since 6.7) QOpcUaHistoryReadResponse * | readHistoryRaw(const QDateTime &startTime, const QDateTime &endTime, quint32 numValues, bool returnBounds, QOpcUa::TimestampsToReturn timestampsToReturn) |
bool | readValueAttribute() |
bool | resolveBrowsePath(const QList<QOpcUaRelativePathElement> &path) |
QDateTime | serverTimestamp(QOpcUa::NodeAttribute attribute) const |
QDateTime | sourceTimestamp(QOpcUa::NodeAttribute attribute) const |
QVariant | valueAttribute() const |
QOpcUa::UaStatusCode | valueAttributeError() const |
bool | writeAttribute(QOpcUa::NodeAttribute attribute, const QVariant &value, QOpcUa::Types type = QOpcUa::Types::Undefined) |
bool | writeAttributeRange(QOpcUa::NodeAttribute attribute, const QVariant &value, const QString &indexRange, QOpcUa::Types type = QOpcUa::Types::Undefined) |
bool | writeAttributes(const QOpcUaNode::AttributeMap &toWrite, QOpcUa::Types valueAttributeType = QOpcUa::Types::Undefined) |
bool | writeValueAttribute(const QVariant &value, QOpcUa::Types type = QOpcUa::Types::Undefined) |
信号
void | attributeRead(QOpcUa::NodeAttributes attributes) |
void | attributeUpdated(QOpcUa::NodeAttribute attr, QVariant value) |
void | attributeWritten(QOpcUa::NodeAttribute attribute, QOpcUa::UaStatusCode statusCode) |
void | browseFinished(QList<QOpcUaReferenceDescription> children, QOpcUa::UaStatusCode statusCode) |
void | dataChangeOccurred(QOpcUa::NodeAttribute attr, QVariant value) |
void | disableMonitoringFinished(QOpcUa::NodeAttribute attr, QOpcUa::UaStatusCode statusCode) |
void | enableMonitoringFinished(QOpcUa::NodeAttribute attr, QOpcUa::UaStatusCode statusCode) |
void | eventOccurred(QVariantList eventFields) |
void | methodCallFinished(QString methodNodeId, QVariant result, QOpcUa::UaStatusCode statusCode) |
void | monitoringStatusChanged(QOpcUa::NodeAttribute attr, QOpcUaMonitoringParameters::Parameters items, QOpcUa::UaStatusCode statusCode) |
void | resolveBrowsePathFinished(QList<QOpcUaBrowsePathTarget> targets, QList<QOpcUaRelativePathElement> path, QOpcUa::UaStatusCode statusCode) |
(since 6.7) void | valueAttributeUpdated(const QVariant &value) |
静态公共成员
QOpcUa::NodeAttributes | allBaseAttributes() |
QOpcUa::NodeAttributes | mandatoryBaseAttributes() |
详细说明
节点是 OPC UA 地址空间的基本构件。它具有浏览名称、值、相关属性等属性,并可以引用地址空间中的其他节点。节点组织在命名空间中,并具有 ID,例如数字、字符串、命名空间特定格式(不透明)或全局唯一标识符。节点由命名空间 ID 和节点 ID 标识。该标识符通常以字符串形式给出:位于名称空间 0 的节点的标识符为 42,其数字标识符为ns=0;i=42
。使用字符串标识符的节点可通过ns=0;s=myStringIdentifier
进行寻址。
这种类型的对象归用户所有,不再需要时必须删除。只要创建这些对象的QOpcUaClient 存在,它们就有效。
属性的读写
调用readAttributes() 或readAttributeRange() 时,将从服务器读取节点属性。读取结果会缓存在本地,在收到attributeRead 信号后可使用attribute() 进行检索。
如果用户有必要的权限,可以使用writeAttribute() 、writeAttributes() 和writeAttributeRange() 写入属性。写入操作的成功会通过attributeWritten 信号报告。
attributeError()包含一个与属性上最后一次读取或写入操作相关的状态代码。这是 OPC UA 服务返回的低级状态代码。该状态代码可通过QOpcUa::errorCategory() 转换为QOpcUa::ErrorCategory 来简化。
订阅和监控项目
订阅是 OPC UA 中的一个概念,它允许接收数据变化或事件的通知,而不是持续轮询节点的变化。受监控项定义了如何监视节点属性的变化。这些项目被添加到订阅中,它们生成的任何通知都将通过订阅转发给用户。用户可以配置更新的时间间隔以及受监控项和订阅的许多其他选项。
QOpcUaNode 提供了与订阅和受监控项目交互的抽象方法。() 可对一个或多个属性发出数据更改通知。 信号包含新值并更新本地缓存。() 禁用数据更改通知。 信号会通知监控状态的变化,例如手动启用和禁用后或服务器上的状态变化。enableMonitoring dataChangeOccurred disableMonitoring monitoringStatusChanged
事件监控使用相同的 API 进行设置和生命周期管理。必须使用EventFilter 来监控EventNotifier 属性,它可选择所需的事件字段,并根据用户定义的标准过滤报告的事件。事件在eventOccurred() 信号中报告为QVariantList ,其中包含所选事件字段的值。
订阅和受监控项目的设置可在运行时通过modifyMonitoring() 进行修改。
浏览地址空间
OPC UA 地址空间由通过引用连接的节点组成。browseChildren 向前跟踪这些引用,并在browseFinished 信号中返回与QOpcUaNode 实例后面的节点连接的所有节点的属性。browse()与browseChildren()类似,但提供了更多配置浏览调用的选项。
方法调用
OPC UA 在服务器上指定了用户可以调用的方法。QOpcUaNode 通过callMethod 支持这种调用,它接收参数并在methodCallFinished 信号中返回调用结果。
解析浏览路径
为了支持根据类型描述进行编程,OPC UA 支持解析从某个节点开始的浏览名称路径,以获取目标节点的节点 ID。resolveBrowsePath() 方法从被调用的节点开始跟踪路径,并在resolveBrowsePathFinished() 信号中返回结果。
示例
连接客户端到服务器并获取QOpcUaNode 对象,请参见QOpcUaClient 。
节点创建成功后,将从服务器读取根节点的 BrowseName:
QOpcUaNode *rootNode;// 创建之前,请参阅 QOpcUaClient 文档。// 连接到 attributeRead 信号。可以使用 QObjects 的兼容槽来代替 lambda。QObject连接(rootNode, &QOpcUaNode::attributeRead, [rootNode,client](QOpcUa::NodeAttributes attr) {) qDebug() << "Signal for attributes:" << attr; if(rootNode->attributeError(QOpcUa::NodeAttribute::BrowseName)!= QOpcUa::UaStatusCode::Good) { qDebug() << "Failed to read attribute:" << rootNode->attributeError(QOpcUa::NodeAttribute::BrowseName); 客户端->disconnectFromEndpoint(); } qDebug() << "Browse name:" << rootNode->attribute(QOpcUa::NodeAttribute::BrowseName).value<QOpcUaQualifiedName>().name(); }); rootNode->readAttributes(QOpcUa::NodeAttribute::BrowseName);// 开始读取节点的 BrowseName 属性。
成员函数文档
[static constexpr]
QOpcUa::NodeAttributes QOpcUaNode::allBaseAttributes()
包含 OPC UA 基本节点类的所有属性。
QVariant QOpcUaNode::attribute(QOpcUa::NodeAttribute attribute) const
返回attribute 中给出的属性值。
该值只有在attributeRead 信号发出后才有效。如果没有缓存的属性值,则返回空QVariant 。
QOpcUa::UaStatusCode QOpcUaNode::attributeError(QOpcUa::NodeAttribute attribute) const
返回attribute 中给出的属性的错误代码。
错误代码只有在attributeRead 或attributeWritten 信号发出后才有效。
如果属性缓存中没有条目,则返回BadNoEntryExists 。
另请参阅 QOpcUa::errorCategory 。
[signal]
void QOpcUaNode::attributeRead(QOpcUa::NodeAttributes attributes)
该信号在readAttributes() 或readAttributeRange() 操作完成后发出。接收方必须检查attributes 中所含属性的状态代码。
[signal]
void QOpcUaNode::attributeUpdated(QOpcUa::NodeAttribute attr, QVariant value)
value 包含节点属性attr 的新值。
另请参阅 attribute()、attributeError()、serverTimestamp()、sourceTimestamp() 和valueAttributeUpdated() 。
[signal]
void QOpcUaNode::attributeWritten(QOpcUa::NodeAttribute attribute, QOpcUa::UaStatusCode statusCode)
该信号在writeAttribute(),writeAttributes() 或writeAttributeRange() 操作完成后发出。
在该信号发出之前,如果写入操作成功,属性缓存将被更新。在writeAttributes() 中,写入调用中的每个属性都会发出一个信号。statusCode 包含attribute 上写入操作的成功信息。
bool QOpcUaNode::browse(const QOpcUaBrowseRequest &request)
从该节点启动浏览调用。
如果异步调用已成功发出,则返回true
。
与request 中指定的条件相匹配的所有引用都会在browseFinished() 信号中返回。
例如,反向浏览调用可用于查找属性节点的父节点:
QOpcUaBrowseRequest request; request.setBrowseDirection(QOpcUaBrowseRequest::BrowseDirection::Inverse); request.setReferenceTypeId(QOpcUa::ReferenceTypeId::HasProperty); propertyNode->browse(request);
bool QOpcUaNode::browseChildren(QOpcUa::ReferenceTypeId referenceType = QOpcUa::ReferenceTypeId::HierarchicalReferences, QOpcUa::NodeClasses nodeClassMask = QOpcUa::NodeClass::Undefined)
从调用此方法的节点开始执行前向浏览调用。浏览操作会收集与节点相连的子节点的信息,并在browseFinished() 信号中发送结果。
如果异步调用已成功发送,则返回true
。
要只请求通过某种引用类型连接到节点的子节点,必须将referenceType 设置为该引用类型。例如,可以通过HasProperty 传入referenceType ,从而获取节点的所有属性。通过在nodeClassMask 中设置某些节点类别,可以对结果进行过滤,使其只包含具有特定节点类别的节点。
[signal]
void QOpcUaNode::browseFinished(QList<QOpcUaReferenceDescription> children, QOpcUa::UaStatusCode statusCode)
该信号在browseChildren() 或browse() 操作完成后发出。
children browseChildren statusCode 包含浏览操作的服务结果。如果 不是 ,则传递的 向量为空。statusCode Good children
另请参阅 QOpcUaReferenceDescription 。
bool QOpcUaNode::callMethod(const QString &methodNodeId, const QList<QOpcUa::TypedVariant> &args = QList<QOpcUa::TypedVariant>())
使用通过args 给出的参数调用 OPC UA 方法methodNodeId 。结果在methodCallFinished 信号中返回。
如果异步调用调度成功,则返回true
。
QOpcUaClient *QOpcUaNode::client() const
返回指向创建此节点的客户端的指针。
[signal]
void QOpcUaNode::dataChangeOccurred(QOpcUa::NodeAttribute attr, QVariant value)
value 包含节点属性attr 的新值。
另请参阅 attribute()、serverTimestamp() 和sourceTimestamp()。
bool QOpcUaNode::disableMonitoring(QOpcUa::NodeAttributes attr)
该方法会关闭对attr 中所给属性的监控。
如果异步调用已成功发出,则返回true
。
调用完成后,将发出disableMonitoringFinished 信号,monitoringStatus 返回一个默认构造值,状态代码为 BadMonitoredItemIdIinvalid,用于attr 。
[signal]
void QOpcUaNode::disableMonitoringFinished(QOpcUa::NodeAttribute attr, QOpcUa::UaStatusCode statusCode)
disableMonitoring statusCode 包含操作生成的状态代码。该信号发出后, 返回一个默认构造值,状态代码为 BadMonitoredItemIdIinvalid,用于 。monitoringStatus attr
bool QOpcUaNode::enableMonitoring(QOpcUa::NodeAttributes attr, const QOpcUaMonitoringParameters &settings)
该方法为attr 中给出的每个属性创建一个受监控项。settings 中的设置将用于创建受监控项目和订阅。
如果异步调用调度成功,则返回true
。
调用完成后,将发出enableMonitoringFinished 信号。有多种错误情况会生成不良状态代码:settings 中指定订阅 id 的订阅不存在、服务器上不存在节点、节点不具有请求的属性或达到服务器受监控项目的最大数量。
同样的方法也可用于启用事件监控。事件是 OPC UA 地址空间中的特殊对象,包含已发生事件的相关信息。如果服务器上触发了事件,事件监控项就会收集事件对象及其子节点的节点属性的选定值。每个有事件源的节点都可以被事件监控。要对节点进行事件监控,必须使用 EventFilter 对属性EventNotifier 进行监控,EventFilter 包含用户所需的事件字段,还可选择使用 where 子句按条件过滤事件(更多详情,请参阅QOpcUaMonitoringParameters::EventFilter )。
[signal]
void QOpcUaNode::enableMonitoringFinished(QOpcUa::NodeAttribute attr, QOpcUa::UaStatusCode statusCode)
对enableMonitoring() 的异步调用结束后会发出该信号。该信号发出后,monitoringStatus() 将返回attr 的有效信息。statusCode 包含操作的状态代码。
[signal]
void QOpcUaNode::eventOccurred(QVariantList eventFields)
该信号在收到新事件后发出。
eventFields 包含事件字段的值,其顺序在事件过滤器的 子句中指定。select
[static constexpr]
QOpcUa::NodeAttributes QOpcUaNode::mandatoryBaseAttributes()
包含 OPC UA 基本节点类的所有强制属性。
[signal]
void QOpcUaNode::methodCallFinished(QString methodNodeId, QVariant result, QOpcUa::UaStatusCode statusCode)
methodNodeId statusCode 包含方法调用的状态代码, 包含方法的输出参数。如果方法没有输出参数, 为空,或者 不是 。如果只有一个输出参数,则 变体为单一值;如果调用的函数返回多个输出参数,则 变体包含一个变体列表。result result statusCode Good result
if (result.canConvert<QVariantList>()) { // handle list type } else { // handle value type }
bool QOpcUaNode::modifyDataChangeFilter(QOpcUa::NodeAttribute attr, const QOpcUaMonitoringParameters::DataChangeFilter &filter)
修改现有的数据更改监控,将filter 用作数据更改过滤器。
如果过滤器修改请求已成功发送到后台,则返回true
。
monitoringStatusChanged 在操作完成后, 。attr
bool QOpcUaNode::modifyEventFilter(const QOpcUaMonitoringParameters::EventFilter &eventFilter)
修改现有事件监控,将eventFilter 用作事件过滤器。
如果过滤器修改请求已成功发送到后台,则返回true
。
monitoringStatusChanged 在操作完成后, 。EventNotifier
bool QOpcUaNode::modifyMonitoring(QOpcUa::NodeAttribute attr, QOpcUaMonitoringParameters::Parameter item, const QVariant &value)
此方法可修改受监控项目或订阅的设置。与attr 相关联的受监控项目或订阅的参数item 会被尝试设置为value 。
如果异步调用已成功发出,则返回true
。
调用完成后,将发出monitoringStatusChanged 信号。该信号包含修改后的参数和状态代码。如果没有与请求的属性相关联的受监控项,或修改请求的参数未被执行,或服务器拒绝了请求的值,则会生成不良状态代码。
QOpcUaMonitoringParameters QOpcUaNode::monitoringStatus(QOpcUa::NodeAttribute attr)
返回与属性attr 相关的监控参数。这可用于检查enableMonitoring() 是否成功或参数是否已修改。返回值只有在enableMonitoringFinished 或monitoringStatusChanged 发送attr 后才有效。如果在发出信号之前查询状态,QOpcUaMonitoringParameters::statusCode() 将返回BadNoEntryExists 。
[signal]
void QOpcUaNode::monitoringStatusChanged(QOpcUa::NodeAttribute attr, QOpcUaMonitoringParameters::Parameters items, QOpcUa::UaStatusCode statusCode)
该信号在异步调用modifyMonitoring() 完成后发出。请求操作的节点属性将在attr 中返回。items 包含已修改的参数。statusCode 包含服务器上修改操作的结果。
QString QOpcUaNode::nodeId() const
返回 OPC UA 节点的 ID。
bool QOpcUaNode::readAttributeRange(QOpcUa::NodeAttribute attribute, const QString &indexRange)
启动对节点属性attribute 的异步读取操作。indexRange 是一个字符串,可用于选择数组的一部分。它在 OPC UA 1.05 第 4 部分 7.27 中定义。数组中的第一个元素为 0,"1 "返回第二个元素,"0:9 "返回前 10 个元素,"0,1 "返回二维数组中第一行的第二个元素。
如果异步调用已成功发送,则返回true
。
属性值只包含attributeRead 信号发出后的有效信息。
bool QOpcUaNode::readAttributes(QOpcUa::NodeAttributes attributes = mandatoryBaseAttributes())
开始对attributes 中的节点属性进行异步读取操作。
如果异步调用调度成功,则返回true
。
属性值只包含attributeRead 信号发出后的有效信息。
[since 6.7]
QOpcUaHistoryReadResponse *QOpcUaNode::readHistoryEvents(const QDateTime &startTime, const QDateTime &endTime, QOpcUaMonitoringParameters::EventFilter &filter, quint32 numValues = 0)
使用参数startTime,endTime,filter 和numValues 开始读取该节点的事件历史记录请求。服务器使用filter 来确定应返回哪些事件及其字段集。
如果异步请求已成功发送,则返回一个QOpcUaHistoryReadResponse ,其中包含请求的状态。结果在QOpcUaHistoryReadResponse::readHistoryEventsFinished(const QList<QOpcUaHistoryEvent> &results, QOpcUa::UaStatusCode serviceResult) 信号中返回。
下面的示例检索了过去两天的历史事件。每次最多返回 10 个事件。如果有更多事件符合过滤器和提供的时间范围,hasMoreData()
将为 true,并且可以通过readMoreData() 获取更多事件。
QScopedPointer<QOpcUaNode>node(opcuaClient->node("ns=2;s=EventHistorian")); QVERIFY(node!=nullptr);QOpcUaMonitoringParameters::EventFilter filter; filter<<QOpcUaSimpleAttributeOperand("Message"); filter<<QOpcUaSimpleAttributeOperand("时间");const autoresponse= node->readHistoryEvents(QDateTime::currentDateTime().addDays(-2)、 QDateTime::currentDateTime(),filter, 10);QObject::connect(response, &QOpcUaHistoryReadResponse::readHistoryEventsFinished, this, [response](constQList<QOpcUaHistoryEvent> &results, QOpcUa::UaStatusCode serviceResult) {if(serviceResult!= QOpcUa::UaStatusCode::Good) { qDebug() << "Service call failed with" << serviceResult; return; }// Print what we got so far for(const auto &result: response->events()) { qDebug() << "Results for" << result.nodeId() << result.statusCode(); for(const auto &event: result.events()) qDebug() << " Event:" << event; }if(response->hasMoreData()) response->readMoreData(); });
此函数在 Qt 6.7 中引入。
[since 6.3]
QOpcUaHistoryReadResponse *QOpcUaNode::readHistoryRaw(const QDateTime &startTime, const QDateTime &endTime, quint32 numValues, bool returnBounds)
启动该节点的历史读取请求。这是 OPC UA ReadHistory 服务的Qt OPC UA 表示法,用于读取OPC UA 1.05 第 4 部分 5.10.3 中定义的原始历史数据。它基于startTime,endTime,numValues, 和returnBounds 这几个参数读取历史数据。
如果异步请求已成功发送,则返回一个包含请求状态的QOpcUaHistoryReadResponse 。结果在QOpcUaHistoryReadResponse::readHistoryDataFinished(const QList<QOpcUaHistoryData> &results, QOpcUa::UaStatusCode serviceResult) 信号中返回。
在下面的示例中,将请求并打印一个节点最近两天的历史数据。结果限制为每个节点十个值。
QOpcUaHistoryReadResponse*response = node->readHistoryRaw(QDateTime::currentDateTime()、 QDateTime::currentDateTime().addDays(-2), 10, true);if(response) { QObject::connect(response123, &QOpcUaHistoryReadResponse::readHistoryDataFinished, [](QList<QOpcUaHistoryData>results, QOpcUa::UaStatusCode serviceResult) {if(serviceResult!= QOpcUa::UaStatusCode::Good) { qWarning() << "Fetching historical data failed with:" << serviceResult; }else{for(const auto&result : results) { qInfo() << "NodeId:" << result.nodeId(); for(const auto &dataValue: result.result()) qInfo() << "Value:" << dataValue.value(); } }); }
此函数在 Qt 6.3 中引入。
[since 6.7]
QOpcUaHistoryReadResponse *QOpcUaNode::readHistoryRaw(const QDateTime &startTime, const QDateTime &endTime, quint32 numValues, bool returnBounds, QOpcUa::TimestampsToReturn timestampsToReturn)
开始读取此节点的历史记录请求。附加的timestampsToReturn 参数决定了每个值将返回哪些时间戳。
此函数在 Qt 6.7 中引入。
bool QOpcUaNode::readValueAttribute()
开始对节点的 Value 属性进行异步读取操作。
如果异步调用已成功发送,则返回true
。
另请参阅 readAttributes().
bool QOpcUaNode::resolveBrowsePath(const QList<QOpcUaRelativePathElement> &path)
使用 OPC UA 1.05 第 4 部分 5.8.4 中指定的 TranslateBrowsePathsToNodeIds 服务,将浏览路径path 转换为从该节点开始的一个或多个节点 ID。
如果异步调用调度成功,则返回true
。
TranslateBrowsePathsToNodeIds 主要用于针对类型定义而不是 OPC UA 地址空间中的具体节点集进行编程。例如,机器模型的类型定义可以由一个浏览名为 "Machine"(机器)的起始节点组成,该节点有一个浏览名为 "Fan"(风扇)的组件。风扇有一个浏览名为 "RPM "的组件,它是一个变量节点,保存着风扇当前的转速值。这种类型的机器有多台,每台机器都作为机器类型的对象映射到 OPC UA 地址空间中。对于每个机器对象,从机器节点到 "RPM "节点的路径都是相同的。如果客户端要读取当前 RPM 值,则需要调用 resolveBrowsePath(),将机器节点作为起始节点,并调用从机器到 "RPM "节点的浏览路径:
QScopedPointer<QOpcUaNode> node(opcuaClient->node("ns=1;s=machine1")); QList<QOpcUaRelativePathElement> path; path.append(QOpcUaRelativePathElement(QOpcUaQualifiedName(1, "Fan"), QOpcUa::ReferenceTypeId::HasComponent)); path.append(QOpcUaRelativePathElement(QOpcUaQualifiedName(1, "RPM"), QOpcUa::ReferenceTypeId::HasComponent)); node->resolveBrowsePath(path);
resolveBrowsePathFinished() 中返回的结果包含 "RPM "节点的节点 ID,可用于访问该节点的属性:
if(!results.size()) { qWarning() << "Browse path resolution failed"; return; }if(results.at(0).isFullyResolved()) {QOpcUaNode *rpmNode = client->node(results.at(0).targetId());if(!rpmNode) {QOpcUaNode *rpmNode =client->node(results.at(0).targetId());if(!rpmNode) qWarning() << "Failed to create node"; return; }// 连接插槽,调用方法}else{ qWarning() << "Browse path could not be fully resolved, the target node is on another server"; return; }
[signal]
void QOpcUaNode::resolveBrowsePathFinished(QList<QOpcUaBrowsePathTarget> targets, QList<QOpcUaRelativePathElement> path, QOpcUa::UaStatusCode statusCode)
该信号在resolveBrowsePath() 调用结束后发出。
QOpcUaBrowsePathTarget targets 该信号包含匹配信息,statusCode 是操作的状态代码。如果statusCode 不是Good ,则targets 为空。浏览路径path 是来自请求的浏览路径。它可用于将结果与请求关联起来。
QDateTime QOpcUaNode::serverTimestamp(QOpcUa::NodeAttribute attribute) const
返回attribute 最后一次读取或数据更改时的服务器时间戳。在发出至少一个attributeRead 或dataChangeOccurred 信号之前,返回空日期时间。
QDateTime QOpcUaNode::sourceTimestamp(QOpcUa::NodeAttribute attribute) const
返回attribute 最后一次读取或数据更改的源时间戳。在至少一个attributeRead 或dataChangeOccurred 信号发出之前,返回空日期时间。
QVariant QOpcUaNode::valueAttribute() const
返回节点 Value 属性的值。
返回值只有在 Value 属性被成功读取或写入后,或在监控数据更改更新了属性缓存后才有效。状态代码为Good 的attributeRead() 或attributeWritten() 信号,或状态代码为dataChangeOccurred() 的 Value 属性信号,都表明了这一点。
如果属性缓存中没有值,则会返回无效的QVariant 。
另请参见 readValueAttribute()、writeValueAttribute() 和valueAttributeError()。
QOpcUa::UaStatusCode QOpcUaNode::valueAttributeError() const
返回节点 Value 属性的错误代码。状态代码Good 表示valueAttribute() 的返回值有效。如果属性缓存中没有条目,则返回BadNoEntryExists 。
[signal, since 6.7]
void QOpcUaNode::valueAttributeUpdated(const QVariant &value)
该信号在属性缓存中的 value 属性被来自服务器的数据更改通知、读取或写入操作更新后发出。value 包含 value 属性的新值。
此函数在 Qt 6.7 中引入。
另请参阅 attribute()、attributeError()、serverTimestamp()、sourceTimestamp() 和attributeUpdated()。
bool QOpcUaNode::writeAttribute(QOpcUa::NodeAttribute attribute, const QVariant &value, QOpcUa::Types type = QOpcUa::Types::Undefined)
使用type 中的类型信息将value 写入attribute 中给出的属性。如果异步调用已成功发送,则返回true
。
如果省略了type 参数,后台会尝试查找正确的类型。默认类型如下:
Qt 元类型 | OPC UA 类型 |
---|---|
布尔类型 | 布尔型 |
UChar | 字节 |
字符 | 字节 |
短 UShort | UInt16 |
短 | Int16 |
英特 | Int32 |
UInt | UInt32 |
超长 | UInt64 |
长 | Int64 |
双 | 双 |
浮点数 | 浮点数 |
QString | 字符串 |
QDateTime | 日期时间 |
QByteArray | 字节字符串 |
QUuid | 引导符 |
bool QOpcUaNode::writeAttributeRange(QOpcUa::NodeAttribute attribute, const QVariant &value, const QString &indexRange, QOpcUa::Types type = QOpcUa::Types::Undefined)
使用type 中的类型信息,将value 写入attribute 中给出的属性。有关indexRange ,请参阅readAttributeRange() 。
如果异步调用已成功派发,则返回true
。
bool QOpcUaNode::writeAttributes(const QOpcUaNode::AttributeMap &toWrite, QOpcUa::Types valueAttributeType = QOpcUa::Types::Undefined)
对toWrite 中指定的属性和值执行写操作。
如果异步调用调度成功,则返回true
。
valueAttributeType 参数可用于提供值属性的类型信息。所有其他属性都有已知类型。
另请参阅 writeAttribute() 。
bool QOpcUaNode::writeValueAttribute(const QVariant &value, QOpcUa::Types type = QOpcUa::Types::Undefined)
使用type 中的类型信息将value 写入节点的 Value 属性。
如果异步调用已成功派发,则返回true
。
另请参阅 writeAttribute() 。
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.