Professional OPC
Development Tools

logos

OPC development in C and C++

QuickOPC will make it easy for you to integrate OPC client functionality into your solution developed in C or C++ language. Reading a value from OPC Data Access or OPC UA server, or writing a data value can be achieved in just a few lines of C or C++ code. You can also set up subscriptions and receive event notifications about data changes. OPC Alarms&Events specification is also supported. Programming to the raw OPC interfaces can be complex in C/C++, but our component interfaces hide the complexities of OPC from the developer.

You can create OPC C or OPC C++ programs in various environments: ATL, MFC, console applications, and Windows services are all supported. The development tool we have targeted primarily is Visual Studio; older versions of Microsoft Visual C/C++ (VS 6.0, VS 2003, VS 2005, VS 2008 or VS 2010) can be used, too.

Note: For managed C++ (C++/CLR), see QuickOPC.NET.

QuickOPC Price List

Read More

Useful links: Examples - Visual C++ / Examples - Portable C++ / Knowledge Base - C++

Simple QuickOPC Example in C++

The code below (in C++) reads 4 OPC items at once, and displays their values, timestamps and qualities, using QuickOPC-COM:

CComSafeArray<BSTR> ItemIdArray(4);
ItemIdArray[0] = _T("Simulation.Random");
ItemIdArray[1] = _T("Trends.Ramp (1 min)");
ItemIdArray[2] = _T("Trends.Sine (1 min)");
ItemIdArray[3] = _T("Simulation.Register_I4");
 
CComVariant vMissing;
vMissing.vt = VT_ERROR;
 
CComVariant vResults(EasyDAClientPtr->ReadMultipleItems(_T(""), _T("OPCLabs.KitServer.2"), 
    CComVariant(ItemIdArray.Detach()), vMissing));
 
CComSafeArray<VARIANT> ResultArray(vResults.parray);
for (int i = ResultArray.GetLowerBound(0); i < ResultArray.GetUpperBound(0); i++)
{
    IDAVtqResultPtr DAVtqResultPtr(ResultArray[i]);
    IDAVtqPtr DAVtqPtr(DAVtqResultPtr->Vtq);
    _tprintf(_T("results(%d).Vtq.ToString(): %s\n"), i, DAVtqPtr->ToString().bstrVal);
}

And, a code to read a value of a node from an OPC Unified Architecture (OPC UA) server, using QuickOPC-UA for COM:

    // Instatiate the client object
    _EasyUAClientPtr ClientPtr(__uuidof(EasyUAClient));
 
    // Perform the operation
    _variant_t value = ClientPtr->ReadValue(
        L"opc.tcp://opcua.demo-this.com:51210/UA/SampleServer", 
        L"nsu=http://test.org/UA/Data/;i=10853");
    
    // Display results
    _variant_t vString;
    vString.ChangeType(VT_BSTR, &value);
    _tprintf(_T("value: %s\n"), CW2T((_bstr_t)vString));

The PubSub variety of OPC UA (as opposed to client-server) uses message-oriented middleware to deliver the data. QuickOPC supports it as well. Code example is available in the documentation, and installed with the product.

More C and C++ examples are included with the product.

 

Footnote & required disclosure: QuickOPC (including its Options) is a software development kit (SDK) for development of OPC clients and subscribers. Installing QuickOPC or its Options does not change system settings.