以下是将以上接口封装在类中的示例代码:
”`cpp
#include
class UAClient { public:
UAClient() : client(UA_Client_new()) {
config = UA_Client_getConfig(client);
}
~UAClient() {
UA_Client_disconnect(client);
UA_Client_delete(client);
}
bool connect() {
return UA_Client_connect(client, config) == UA_STATUSCODE_GOOD;
}
void connectAsync(UA_ConnectAsyncCallback callback, void* userdata) {
UA_Client_connectAsync(client, config, callback, userdata);
}
void disconnect() {
UA_Client_disconnect(client);
}
void disconnectAsync(UA_DisconnectAsyncCallback callback, void* userdata) {
UA_Client_disconnectAsync(client, callback, userdata);
}
UA_EndpointDescription* getEndpoints(const char* discoveryUrl) {
return UA_Client_getEndpoints(client, discoveryUrl);
}
bool readValueAttribute(UA_NodeId nodeId, UA_Variant* value) {
return UA_Client_readValueAttribute(client, nodeId, value) == UA_STATUSCODE_GOOD;
}
bool writeValueAttribute(UA_NodeId nodeId, const UA_Variant* value) {
return UA_Client_writeValueAttribute(client, nodeId, value) == UA_STATUSCODE_GOOD;
}
private:
UA_Client* client;
内容由零声教学AI助手提供,问题来源于学员提问