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 start up and the shut down code in the main function of the console application. For integration in existing applications the start up code for the SDK can be integrated into the start up sequence of the application and the shutdown code of the SDK into the shut down sequence of the application.
Please read the Introduction section before working through this tutorial.
Contents:
// The UA Stack platform layer instance OpcUa_Handle g_hProxyStubPlatformLayer = OpcUa_Null; // The UA Server instance UaServer g_UaServer;
OpcUa_StatusCode uStatus = OpcUa_Good; OpcUa_ProxyStubConfiguration proxyStubConfiguration; // Initialize ProxyStubConfiguration with default values OpcUa_ProxyStubConfiguration_InitializeDefault(&proxyStubConfiguration); // Default values can be changed here proxyStubConfiguration.bProxyStub_Trace_Enabled = OpcUa_True; // Initialize UA Stack and assign platform layer to UA Stack uStatus = UaServer_Module_InitializeUaStack(g_hProxyStubPlatformLayer, &proxyStubConfiguration); OpcUa_GotoErrorIfBad(uStatus);
UaServer_Provider provider; // Initialize Server uStatus = UaServer_Initialize( &g_UaServer, "opc.tcp://localhost:4841", "MyNodeName::4841/UaCSDKSampleServer", "http://www.unified-automation.com/UaCSDKSampleServer", "ANSI C SDK UA Sample Server"); OpcUa_GotoErrorIfBad(uStatus); // Initialize provider list and add mandatory server provider uStatus = UaServer_ProviderList_Create(&g_UaServer); OpcUa_ReturnErrorIfBad(uStatus); // Add sample provider to provider list memset(&provider, 0, sizeof(provider)); #ifdef UAPROVIDER_STATIC provider.pfInit = UaProvider_Sample_Initialize; // static intialization function #else provider.sProviderLibrary = "sampleprovider"; // basename of shared library which contains the provider #endif UaServer_ProviderList_AddProvider(&g_UaServer, &provider); // initialize the providers uStatus = UaServer_Providers_Initialize(&g_UaServer); OpcUa_ReturnErrorIfBad(uStatus);
// StartUp Server uStatus = UaServer_StartUp(&g_UaServer); OpcUa_GotoErrorIfBad(uStatus);
// Clean Up Server UaServer_Clear(&g_UaServer); // Clean Up UA Stack UaServer_Module_ClearUaStack(g_hProxyStubPlatformLayer);