我正在尝试使用和将值写入某些OPC UA
节点。为此,我必须知道节点的不同数据类型。每次我尝试读取节点的数据类型时,我都会得到 a而不是. 它是列表中的正确节点,我可以读取所有节点。有人可以帮帮我吗?Qt
open62541
Boolean type
int32
//This is how I add nodes to the server. This is an example with the node DBW0.
//After adding the nodes to the server, each node will be append to the _nodeList.
void OPCConnection::AddNodeToServer()
{
QOpcUaNodeCreationAttributes attributes;
attributes.setDataTypeId(QOpcUa::namespace0Id(QOpcUa::NodeIds::Namespace0::Int16));
attributes.setValueRank(-2); // Scalar or array
attributes.setAccessLevel(QOpcUa::AccessLevelBit::CurrentWrite);
attributes.setUserAccessLevel(QOpcUa::AccessLevelBit::CurrentWrite);
QOpcUaAddNodeItem item;
item.setParentNodeId(QOpcUa::QExpandedNodeId("ns=2;s=PLC1.S7_300.DB120"));
item.setReferenceTypeId(QOpcUa::nodeIdFromReferenceType(QOpcUa::ReferenceTypeId::Organizes));
item.setRequestedNewNodeId(QOpcUa::QExpandedNodeId("ns=2;s=DBW0"));
item.setNodeClass(QOpcUa::NodeClass::Variable);
item.setNodeAttributes(attributes);
_client->addNode(item);
}
//This is how I read the nodes.
void OPCConnection::readNode()
{
if (_client->state() == QOpcUaClient::ClientState::Connected)
{
for (int i = 0; i < _nodeList->count(); i++)
{
_nodeList->at(i)->readAttributes(QOpcUa::NodeAttribute::DataType);
_nodeList->at(i)->readAttributes(QOpcUa::NodeAttribute::Value);
}
}
}
//After reading I want to write.
void OPCConnection::setNodeValue(const QVariant value, const int index)
{
_nodeList->at(index)->writeValueAttribute(value,
_nodeList->at(index)->attribute(QOpcUa::NodeAttribute::DataType).
value<QOpcUa::Types>());
}
我只能将布尔节点写为数据类型,因为每个节点都有一个布尔值作为数据类型。