
Reduce coding time and launch your software quickly with our OPC UA Client C++ SDK
Our SDK implements an OPC UA communication stack and provides high-level classes to connect to OPC UA Servers & send OPC UA requests.
How It Stands Out
Developing an OPC UA Client Application from scratch can be a tedious process. Just like a Carpenter needs sharpened and easy to use tools to do his job in a short time and with high quality, you need a handy software library that implements all heavy lift OPC UA staff, so you can focus on your application logic. Here’s what makes it stand out:
Shorten your Time to Market and Reduce Development Costs:
Since the SDK comes with many pre-built functions and automatically handles OPC UA communication, your Developers don’t have to spend weeks building the code from scratch. Also, our SDK has been thoroughly tested, so you don’t have to agonize over constant debugging.
These features make it quicker to produce and launch software to the market, which leads to faster profits. Plus, we handle the maintenance for you so you don’t have to spend more money and time on maintainance.


Minimal and Clean Coding:
Designed by Developers for Developers, this SDK was created with minimal code to communicate with OPC UA Servers. C++ features like lambda, inline functions, and futures make it easier to have clean and clutter-free code. Plus, the simple coding makes it easier to learn and implement for your team.
As your business needs change, you can rely on its minimal coding function for flexibility and easy modification. Whether you’re adding new machinery, expanding product lines, or integrating additional data sources, you can use our simple SDK to adjust your systems quickly.
Stability & Scalability:
Included features like automatic re-connection to servers and smart pointers for memory management make sure this SDK is stable and reliable. This eliminates memory leaks, which can be costly and time-consuming to fix in manufacturing fields.
Moreover, you can easily scale this software due to its ability to automatically handle complex data at runtime.

More Features
Modern C++ Advantages
Other SDKs don’t use the power of standard C++ capabilities introduced in its modern versions (C++ 17). These SDKs sometimes use their custom-type definition for even basic data types like bool or float, not to mention more complex types like std::string or std::vector.
Our SDK mainly uses standard C++ data types and was designed with a “Low Code” philosophy in mind. So Developers using it can reduce their stress levels by writing minimal code lines. This means your apps can be developed faster, leading to a faster time to market and lower product costs.
Clean Coding & Easy OPC Request Linking:
This allows you to store the value of any C++ variable type in a request context. When you send a request to an OPC UA server, you can attach extra data (like a variable or object). Later, when the response arrives, the data is still available alongside the request and response. This is useful because it helps you keep track of where the response should go in your application.
If you need to process the data later, you can attach a smart pointer to an object, ensuring it’s available when the response comes back. Overall, this avoids manual tracking and makes your code cleaner & more efficient.
Complex Data Type Support
Many SDKs require you to define all possible data structures in advance to generate corresponding classes for each type. With our SDK, you don’t need to spend time predefining complex data types because it figures it out automatically.
Our SDK complex data types are treated as key-value pairs, so you can easily loop through them and access their values without needing custom classes for each type.
Synchronous and Asynchronous Callbacks
When a request is sent, the result is returned using C++ “future”. You can wait for the response synchronously. Or, you can get the response asynchronously by handling callbacks. By using callbacks, there’s no need to implement interfaces or functions because you can just use lambda (small, inline) functions to handle the response.
Eliminate Data Leaks & Auto Re-Connect to Servers
This feature eliminates memory leaks by using smart pointers for object lifetime management. It also automatically re-connects to servers. After reconnecting, subscriptions and monitored items are created automatically.
Secure Mode Communication
The system automatically generates self-signed root certificates and application instance certificates signed by them. Our supported security policies are Basic256Sha256 and None.
These can create a secure channel in secured mode (sign and encryption).
Sample code
Below is the source code of a sample console application that uses all the main features of the SDK. Complete project source code is available at the GitHub repository https://github.com/onewayautomation/ogamma-sdk-sample-app.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 | #include <opcua/Connection.h> #include <iostream> #include <iomanip> using namespace OWA::OpcUa; int main (int argc, char** argv) { (void)argc; (void)argv; const std::string value1 = "Hello World!"; const std::string value2 = "Hi there!"; bool succeeded = false; // initSdk must be called in order to initialize logging subsystem: OWA::OpcUa::Utils::initSdk(); { std::string endpointUrl; endpointUrl = "opc.tcp://opcuaserver.com:48010"; // endpointUrl = "opc.tcp://localhost:48010"; // The Connection instance can be created in simpler way too, if support for Complex types is not required, and default configuration is OK: // auto connection = Connection::create(endpointUrl, true); ClientConfiguration config(endpointUrl); config.readTypeDefinitionsOnConnect = true; config.readXmlTypeDictionaryOnConnect = true; config.createSession = true; config.securityMode = SecurityMode(SecurityPolicyId::None, MessageSecurityMode::None); // To connect in secured mode, uncomment line below. config.securityMode = SecurityMode(SecurityPolicyId::Basic256Sha256, MessageSecurityMode::SignAndEncrypt); // If the option acceptAnyCertificate is false, then connections only to servers with trusted certificate will be allowed. // If certificate is not valid or trusted, it will be saved in the data/PKI/rejected folder. // To trust the certificate, move it to the folder data\PKI\trusted\certs config.certificateSettings.validationRules.acceptAnyCertificate = false; // Default identity token is Anonymous. // Setting username/password token below: auto userNameIdentityToken = std::make_shared<UserNameIdentityToken>(); // Default credentials in Unified automation Demo Server. userNameIdentityToken->userName = "root"; userNameIdentityToken->password = "secret"; // To connect using Anonymous token, uncomment line below: config.identityToken = userNameIdentityToken; auto connection = Connection::create(config); // Namespace manager holds information about server namespace array and complex data types. // Required if you need to expand complex type values. std::shared_ptr < NamespaceManager> namespaceManager; connection->SetNamespaceManagerUpdatedCallback([&namespaceManager](std::shared_ptr < NamespaceManager> nsm) { namespaceManager = nsm; // Namespace settings can be serialized to XML string and saved: std::string nsmContent; if (nsm->serializeToString(nsmContent).isGood()) { auto saveResult = Utils::saveStringToFile(nsmContent, "./namespaceSettings.xml"); } }); auto connectResult = connection->connect().get(); if (!connectResult.isGood()) { std::cerr << "Failed to connect, error: " << connectResult.toString() << std::endl; } else { // Example how to read a few variables: { NodeId nodeId(4294967295, 2); // Alternatively, node id can be initialized from serialized string: NodeId nid; if (!nid.parse("ns=2;i=4294967295")) { std::cout << "Failed to parse node id" << std::endl; } ReadRequest::Ptr readRequest(new ReadRequest(nodeId)); readRequest->nodesToRead.push_back(nid); readRequest->nodesToRead.push_back(NodeId("abra-cadabra")); // Node with this ID does not exist in the address space auto readResponse = connection->send(readRequest).get(); if (readResponse->isGood() && readResponse->results.size() == readRequest->nodesToRead.size()) { auto requestIter = readRequest->nodesToRead.begin(); for (auto result = readResponse->results.begin(); result != readResponse->results.end(); result++, requestIter++) { if (Utils::isGood(result->statusCode)) { std::cout << "Node " << requestIter->nodeId.toString() << " has value " << result->value.toString() << std::endl; } else { std::cout << "Failed to read from node " << requestIter->nodeId.toString() << ", error: " << Utils::toString(result->statusCode) << std::endl; } } } } // Read from a node and write to it. { NodeId nodeId("Demo.Static.Scalar.String", 2); ReadRequest::Ptr readRequest(new ReadRequest(nodeId)); auto readResponse = connection->send(readRequest).get(); if (readResponse->isGood() && readResponse->results.size() == 1 && Utils::isGood(readResponse->results[0].statusCode)) { // We know that data type of the value is String, therefore convert it to string should succeed: std::string currentValue = readResponse->results[0].value; std::string newValue = (currentValue == value1) ? value2 : value1; WriteRequest::Ptr writeRequest(new WriteRequest(WriteValue(nodeId, DataValue(Variant(newValue))))); // Example of write request writing to the variable of 32 bit unsigned integer type. // Here constructor of the Variant takes value of explicitly defined data type uint32_t: { WriteRequest::Ptr writeRequest2(new WriteRequest(WriteValue(NodeId("Demo.Static.Scalar.UInt32", 2), DataValue(Variant((uint32_t)456))))); } auto writeResponse = connection->send(writeRequest).get(); if (writeResponse->isGood() && Utils::isGood(writeResponse->results[0])) { readResponse = connection->send(readRequest).get(); if (readResponse->isGood() && readResponse->results.size() == 1 && Utils::isGood(readResponse->results[0].statusCode)) { currentValue = readResponse->results[0].value.toString(); if (currentValue == newValue) { std::cout << "Wrote value " << currentValue << " to the server!" << std::endl; succeeded = true; } } } } } // Write to the variable of known integer data type: { WriteRequest::Ptr writeRequest(new WriteRequest()); NodeId nodeId("Demo.Static.Scalar.Byte", 2); DataValue dv; // Literal numeric value like 123 can be treated as of many data types: could be float, double or 8, 16, 32, 64 bit signed or unsigned integer. // OPC UA requires written values to have exactly the same data type as data type of the variable on the server. // Therefore, explicitly convert it the data type of the variable, which in case of this variable is Byte. // C++ has native equivalent to it, so uint8_t is used to represent OPC UA Byte data type. // As a result of using conversion to uint8_t, Variant variable will have data type set to Byte: dv.value = (uint8_t) 123; // Alternatively, we could assign to the Variant variable values of other variables, without explicit conversion, in this case variable's data type is already known to the compiler: uint8_t byteValue = 123; dv.value = byteValue; WriteValue wv; wv.nodeId = nodeId; wv.value = dv; writeRequest->nodesToWrite.push_back(wv); auto writeResponse = connection->send(writeRequest).get(); if (writeResponse->isGood() && Utils::isGood(writeResponse->results[0])) { std::cout << "Wrote value " << dv.value.toString() << " to the variable with node id " << nodeId.toString() << std::endl; } else { std::cout << "Wrote value " << dv.value.toString() << " to the variable with node id " << nodeId.toString() << std::endl; } } // Create subscription and monitored items: { DateTime startTime(true); auto createSubscriptionRequest = std::make_shared<CreateSubscriptionRequest>(); createSubscriptionRequest->requestedPublishingInterval = 1000; double samplingRate = 1000; uint32_t queueSize = 10; std::atomic<int> counter = 0; // Notification Observer type callback is called when Publish response is received from the server. NotificationObserver notificationCallback = [&counter, &namespaceManager](NotificationMessage& notificationMessage) { counter++; std::cout << "Got notification number " << counter << " with sequence number " << notificationMessage.sequenceNumber << std::endl; for (auto iter = notificationMessage.notificationData.begin(); iter != notificationMessage.notificationData.end(); iter++) { auto p = iter->get(); DataChangeNotification* dcn = dynamic_cast<DataChangeNotification*>(p); if (dcn) { for (auto m = dcn->monitoredItems.begin(); m != dcn->monitoredItems.end(); m++) { std::cout << "Handle = " << m->clientHandle << ", timestamp = " << m->dataValue.sourceTimestamp.toString(true) << ", value = " << m->dataValue.value.toJson(namespaceManager) << std::endl; } } } }; auto createSubscriptionResponse = connection->send(createSubscriptionRequest, notificationCallback, false, [samplingRate, queueSize, connection] (std::shared_ptr<CreateSubscriptionRequest>& request, std::shared_ptr<CreateSubscriptionResponse>& response) { (void)request; if (response->isGood()) { CreateMonitoredItemsRequest::Ptr createMonItemsRequest(new CreateMonitoredItemsRequest()); createMonItemsRequest->subscriptionId = response->subscriptionId; createMonItemsRequest->itemsToCreate.push_back(MonitoredItemCreateRequest(NodeId(std::string("Demo.Dynamic.Scalar.String"), 2), samplingRate, queueSize)); createMonItemsRequest->itemsToCreate.push_back(MonitoredItemCreateRequest(NodeId(std::string("Demo.Dynamic.Scalar.XmlElement"), 2), samplingRate, queueSize)); // Server Status Node, complex type createMonItemsRequest->itemsToCreate.push_back(MonitoredItemCreateRequest(NodeId(2256), samplingRate, queueSize)); for (int index = 0; index < 10; index++) { std::stringstream s; s << "Demo.Massfolder_Dynamic.Variable" << std::dec << std::setw(4) << std::setfill('0') << index; createMonItemsRequest->itemsToCreate.push_back(MonitoredItemCreateRequest(NodeId(s.str(), 2), samplingRate, queueSize)); } auto response = connection->send(createMonItemsRequest, false).get(); if (!response->isGood()) { std::cerr << "Failed to send CreateMonitoredItems request" << std::endl; } } else { std::cerr << "Failed to create subscription, error: " << Utils::toString(response->header.serviceResult) << std::endl; } return true; }); // Wait until 10 data change notification is received, or timeout: while (counter < 10 && DateTime::diffInMilliseconds(startTime, DateTime(true)).count() < 20000) { std::this_thread::sleep_for(std::chrono::milliseconds(1)); } } // Recursively browse OPC UA Server address space, using browse and Browse Next service calls. { DateTime startTime(true); auto browseRequest = std::make_shared<BrowseRequest>(); const int maxLevel = 3; browseRequest->requestedMaxReferencesPerNode = 10; BrowseDescription bd; bd.browseDirection = BrowseDirection::forward; bd.includeSubtypes = true; bd.referenceTypeId = Ids::HierarchicalReferences; bd.nodeClassMask.value = 0; bd.nodeClassMask.bits.Object = 1; bd.nodeClassMask.bits.Variable = 1; bd.nodeId = 85; // Start browsing from Objects Node browseRequest->nodesToBrowse.push_back(bd); // Variables to call callback functions recursively. Passed to lambda functions by reference. std::function<bool(std::shared_ptr<BrowseRequest>& request, std::shared_ptr<BrowseResponse>& response)> cb; std::function<bool(std::shared_ptr<BrowseNextRequest>& request, std::shared_ptr<BrowseNextResponse>& response)> cbbn; // Variables to keep track of sent requests and received responses: std::atomic<int> numberOfRequests = 0; std::atomic<int> numberOfResponses = 0; std::atomic <int> totalNodes = 0; // This function is called when BrowseNext response is received. auto browseNextCallbackFunction = [connection, &cbbn, &cb, &numberOfRequests, &numberOfResponses, maxLevel, &totalNodes] (std::shared_ptr<BrowseNextRequest>& request, std::shared_ptr<BrowseNextResponse>& response) { std::pair<int, std::vector<NodeId>> requestContext = std::any_cast<std::pair<int, std::vector<NodeId>>>(request->context); int level = requestContext.first; if (!Utils::isGood(response)) { std::cerr << "Browse request failed with error " << Utils::toString(response->header.serviceResult) << std::endl; } else if (response->results.size() != requestContext.second.size()) { std::cerr << "Browse request has incorrect number of results " << response->results.size() << " vs. expected " << requestContext.second.size() << std::endl; } else { // Normal flow of the operation. auto browseNextRequest = std::make_shared<BrowseNextRequest>(); auto nextLevelRequest = std::make_shared<BrowseRequest>(); nextLevelRequest->context = requestContext.first + 1; auto reqIter = requestContext.second.begin(); for (auto iter = response->results.begin(); iter != response->results.end(); iter++, reqIter++) { for (int index = 0; index < level; index++) std::cout << "\t"; std::cout << "Browsed Node id = " << reqIter->toString() << std::endl; for (auto r = iter->references.begin(); r != iter->references.end(); r++) { totalNodes++; for (int index = 0; index < (level + 1); index++) std::cout << "\t"; std::cout << "Display name = " << r->displayName.toString() << ", node id = " << r->nodeId.toString() << std::endl; if (level < maxLevel) { BrowseDescription bd; bd.browseDirection = BrowseDirection::forward; bd.includeSubtypes = true; bd.referenceTypeId = Ids::HierarchicalReferences; bd.nodeClassMask.value = 0; bd.nodeClassMask.bits.Object = 1; bd.nodeClassMask.bits.Variable = 1; bd.nodeId = r->nodeId.nodeId; nextLevelRequest->nodesToBrowse.push_back(bd); } } if (!iter->continuationPoint.empty()) { browseNextRequest->continuationPoints.push_back(iter->continuationPoint); } } if (!browseNextRequest->continuationPoints.empty()) { numberOfRequests++; connection->send(browseNextRequest, cbbn); } if (!nextLevelRequest->nodesToBrowse.empty()) { numberOfRequests++; connection->send(nextLevelRequest, cb); } } numberOfResponses++; return true; }; // This callback function is called when Browse response is received. auto callbackFunction = [maxLevel, connection, browseNextCallbackFunction, &cb, &numberOfRequests, &numberOfResponses, &totalNodes] (std::shared_ptr<BrowseRequest>& request, std::shared_ptr<BrowseResponse>& response) { int level = std::any_cast<int>(request->context); if (!Utils::isGood(response)) { std::cerr << "Browse request failed with error " << Utils::toString(response->header.serviceResult) << std::endl; } else if (response->results.size() != request->nodesToBrowse.size()) { std::cerr << "Browse response has incorrect number of results " << response->results.size() << " vs. expected " << request->nodesToBrowse.size() << std::endl; } else { // Normal flow of the operation. auto browseNextRequest = std::make_shared<BrowseNextRequest>(); auto nextLevelRequest = std::make_shared<BrowseRequest>(); nextLevelRequest->context = level + 1; auto reqIter = request->nodesToBrowse.begin(); std::vector<NodeId> browseNextNodeIds; for (auto iter = response->results.begin(); iter != response->results.end(); iter++, reqIter++) { for (int index = 0; index < level; index++) std::cout << "\t"; std::cout << "Browsed Node id = " << reqIter->nodeId.toString() << std::endl; for (auto r = iter->references.begin(); r != iter->references.end(); r++) { totalNodes++; for (int index = 0; index < (level + 1); index++) std::cout << "\t"; std::cout << "Display name = " << r->displayName.toString() << ", node id = " << r->nodeId.toString() << std::endl; if (level < maxLevel) { BrowseDescription bd; bd.browseDirection = BrowseDirection::forward; bd.includeSubtypes = true; bd.referenceTypeId = Ids::HierarchicalReferences; bd.nodeClassMask.value = 0; bd.nodeClassMask.bits.Object = 1; bd.nodeClassMask.bits.Variable = 1; bd.nodeId = r->nodeId.nodeId; nextLevelRequest->nodesToBrowse.push_back(bd); } } if (!iter->continuationPoint.empty()) { browseNextRequest->continuationPoints.push_back(iter->continuationPoint); browseNextNodeIds.push_back(reqIter->nodeId); } } if (!browseNextRequest->continuationPoints.empty()) { numberOfRequests++; browseNextRequest->context = std::make_pair(level, browseNextNodeIds); connection->send(browseNextRequest, browseNextCallbackFunction); } if (!nextLevelRequest->nodesToBrowse.empty()) { numberOfRequests++; connection->send(nextLevelRequest, cb); } } numberOfResponses++; return true; }; cb = callbackFunction; cbbn = browseNextCallbackFunction; int level = 0; browseRequest->context = level; numberOfRequests++; // Send the request asynchronously. connection->send(browseRequest, callbackFunction); // Wait until browsing is complete: while (numberOfResponses != numberOfRequests) { std::this_thread::sleep_for(std::chrono::milliseconds(1)); } std::cout << "Recursive browsing completed in " << DateTime::diffInMilliseconds(startTime, DateTime(true)).count() << " ms, browsed " << totalNodes << " nodes with max. depth " << maxLevel << std::endl; } } } OWA::OpcUa::Utils::closeSdk(); if (!succeeded) { std::cout << "Writing new value to the server failed!" << std::endl; return -1; } else { return 0; } } |
For more technical details please refer to our online User Manual by clicking the button below.
To see the SDK in action, please clone the sample application from the Git repository below:
Try for Free
Windows
- Try it out on a Windows OS to test its capabilities
- Please note that it has a limitation where the process exits after running for one hour.
Linux
- Try it out on a Linux OS to test its capabilities
- Please note that it has a limitation where the process exits after running for one hour.
Purchase:
Raspberry Pi (ARM)
- Try it out on a Raspberry Pi to test its capabilities
- Please note that it has a limitation where the process exits after running for one hour.
Binary Edition
- The rights to use header files and pre-built binary libraries for one of the supported platforms (ex: Linux) for one Developer.
- Binaries can be integrated into commercial end-product distribution packages.Try it out on a Windows OS to test its capabilities.
Source Code Edition
- The rights to a full source code that can build binary libraries for any supported platform for one Developer. These binary libraries can be integrated into commercial end-product distribution packages.
- * Please note that the source code you’re assigned CANNOT BE re-distributed!
Your FAQs
Why should I use One-Way Automation’s SDK when there are open-source projects for C or C++?
An open-source library is usually more financially feasible. But since your Developers could spend hours customizing the SDK with no customer support, the number of hours spent would outweigh the cost savings. Also, while open-source libraries are free, you wouldn’t have control and ownership over it. Sometimes you can customize your copy of the open-source code, but merging the code to the main code branch might be challenging. Plus, open-source tools are usually owned by library managers who are often hard to reach. So you might end up tediously maintaining your version of the library with no support. Therefore, purchasing our SDK with 24/7 support, true ownership, and endless customization could be a better choice.
Can I use it to code applications for Windows using Visual Studio, or Linux with Raspberry Pi?
Yes, the SDK works on multiple platforms!
What are your licensing options?
We have two types of licenses:
- Binary License: This features the rights to use header files and pre-built binary libraries for one of the supported platforms (ex: Linux) for one Developer. Binaries can be integrated into commercial end-product distribution packages.
- Source Code License: This features the rights to a full source code that can build binary libraries for any supported platform for one Developer. These binary libraries can be integrated into commercial end-product distribution packages. Please note that the source code you’re assigned cannot be re-distributed.
Which development tools do I need to use the SDK?
If using Windows, CMake, and Visual Studio Community Edition (2022 or 2019) are needed.
If using Linux and Raspberry Pi, please employ GCC and CMake.
Do you have free trials or an evaluation version?
Yes, the Binary Edition is available to download via our online store for testing purposes. It has a limitation: the process exits after running for one hour.
Please select the desired platform version (Windows, Linux, or Raspberry Pi) to download via the tables above.
Can I write a multi-threaded application with this SDK?
Yes. Plus, you don’t need support for single-thread mode.