ANSI C Based OPC UA Client/Server SDK
1.8.4.410
|
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 the ANSI C UA SDK into a new application or an existing application.
The provided sample code implements the startup and the shutdown code in the main function of the console application. For integration in existing applications the startup code for the SDK can be integrated into the startup sequence of the application and the shutdown code of the SDK into the shutdown sequence of the application.
Please read the Introduction section before working through this tutorial.
There are two variables needed during the whole runtime of the OPC UA Server. One variable is the handle of the UA Stack platform layer. The other one is the UaServer object containing configuration and management data for the OPC UA Server instance. The variables can be global variables or part of an application management structure available during runtime of the Server.
The first step in the startup code is the initialization of the UA Stack. This requires filling the ProxyStubConfiguration structure with the configuration setting for the UA Stack. The helper function OpcUa_ProxyStubConfiguration_InitializeDefault is setting default values configured for the stack. The trace and serializer settings can be changed. In a second step the stack is initialized and the platform layer is assigned to the stack.
The second step is to initialize the UaServer object. With the first call to UaServer_Initialize the structure and contained structures will be initialized.
After initializing the server object, UaServer_GetConfiguration can be used to get the configuration structure of the server to set server instance specific settings like EndpointUrl, ApplicationUri, ApplicationName and product specific settings like the ProductUri.
With the following calls the providers are initialized:
The third step is to start the Ua Server. After this call, the main loop has to be executed by calling UaBase_DoCom cyclically until it returns an error or the server should be shut down. From this point on, clients are able to connect to the server.
An alternative to manually setting the server configuration is to use the UaBase_Settings utilities:
The shutdown sequence clears the UaServer object first which also closes the Endpoints. Clients are no longer able to connect to the server after this call. In the second call the UA stack is cleaned up.