ANSI C Based OPC UA Client/Server SDK
1.8.1.381
|
There are two main development tasks to implement an OPC UA Server using the SDK. One is to integrate the SDK and the UA Server into a new or an existing application. The second task is to integrate the data sources into the SDK. This tutorial gives an introduction on how to integrate data sources into the ANSI C UA SDK by implementing a data provider. It doesn’t cover everything. The emphasis is on teaching how to quickly create a new Data Provider with new address space and new IO data.
Please read the Introduction section before working through this tutorial.
If you want to create your first data provider it’s the easiest way to just copy the demo provider and rename the files or to generate a provider using the UaModeler. A basic provider should contain these files:
File | Description |
---|---|
uaprovider_xyz.h | Contains provider function definitions. Normally only UaProvider_XYZ_Initialize for initializing your provider. |
uaprovider_xyz.c | Implements the provider initialization and cleanup. |
xyz_read.c | Implements the read service of the provider interface. |
xyz_write.c | Implements the write service of the provider interface. |
xyz_subscription.c | Implements the subscription functionality described in Provider Subscription Mechanism |
uaserver_helper.h | Contains global variable declarations. |
Every provider has to implement an Initialize function with the following signature. This is the main entry point to set up all other functions a provider may provide.
This function is called when loading the provider and has the following purposes:
This is called from the Server SDK before the provider is unloaded to give the provider the chance to clean up its resources.
Providers can also be compiled as Dynamic Link Libraries (aka shared objects). In this case you have to provide an exported DLL function InitializeProvider which calls the UaProvider_XYZ_Initialize function. The defines UAPROVIDER_P_EXPORT and UAPROVIDER_P_IMPORT provided by the SDK can be used to declare a XYZPROVIDER_API macro, depending on how the header is included.
All other functions will be accessed through the provider interface and do not need to be exported. You can use the define BUILD_SHARED_LIBS to check if providers are linked statically or dynamically. See Startup Code for UA Stack and UA Server to see how to load dynamic and static providers.