UaModeler  1.3.4.293
 All Pages
HowTo (Linux): Compile the Generated Method Project Files

The generated code itself is identical for Windows and Linux; hence code that was generated under Windows can be used in a Linux SDK and vice versa. The integration of the generated code into your application strongly depends on the build environment you are using, e.g. Visual Studio, Eclipse, CMake, etc. This example will describe how to integrate the generated code into Server Getting Started Lesson 1 of the Unified Automation ANSI C SDK 1.3 or newer using the CMake files delivered with the SDK in six simple steps.

Step 1: Adding the Generated Provider to the Server Application’s CMakeLists.txt

First of all, the generated provider is added to the server application’s CMakeLists.txt ([SDK Installation Directory]/examples/server_gettingstarted/lesson01/CMakeLists.txt). Add the following code:

####################################### DIFferent Configurations ###############
...
### New code begins; first line only needed for SDK V1.3.x ####
set(SDK_DIR ${UA_INCLUDE_DIR}/..)
ADD_SUBDIRECTORY (${CMAKE_CURRENT_SOURCE_DIR}/exampleproject)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/exampleproject)
SET(PROVIDER_LIST ${PROVIDER_LIST} exampleprojectprovider)
### New code ends #############################################
####################################### Include Paths ##########################
...
Note
The first line of the code to add is only needed when using ANSI C SDK 1.3.x, leave it out when using the ANSI C SDK 1.4.

Step 2: Adding Code to the Server Application’s Source File

Then locate the source file of the application ([SDK Installation Directory]/examples/server_gettingstarted/lesson01/servermain.c) and include the generated provider.

/*============================================================================
* Includes
*===========================================================================*/
...
#include <uaserver_module.h>
#include <uaserver_utilities.h>
#include <uaprovider_exampleproject.h> // Add this line
...

For enabling the server to start up the provider, it has to be added to the server’s provider list.

/* Main OPC UA Server Loop. */
OpcUa_StatusCode ServerMain()
{
UaServer uaServer;
UaServer_Configuration *pServerConfig = OpcUa_Null;
UaServer_Provider Provider; // Add this line
...
printf("UA Server: Building Provider List...\n");
uStatus = UaServer_ProviderList_Create(&uaServer);
OpcUa_GotoErrorIfBad(uStatus);
memset( &Provider, 0, sizeof( Provider ) );
# ifndef BUILD_SHARED_LIBS
Provider.pfInit = UaProvider_ExampleProject_Initialize;
# else
Provider.sProviderLibrary = "exampleprojectprovider";
# endif
UaServer_ProviderList_AddProvider( &uaServer, &Provider )
...

Step 3: Implementing the Example Method of the Generated Provider

Now, we implement the method in the generated file [SDK Installation Directory]/examples/server_gettingstarted/lesson01/exampleproject/ uaprovider_exampleproject_myobjecttype_methods.c as shown below.

OpcUa_StatusCode UaProvider_ExampleProject_MyObjectType_fktSum(
/* in */ UaServer_ProviderCallContext *a_pCallContext ,
/* in */ OpcUa_NodeId *pObjectId ,
/* in */ OpcUa_UInt32 in1,
/* in */ OpcUa_UInt32 in2,
/* out */ OpcUa_UInt32 *out1)
{
OpcUa_StatusCode ret = OpcUa_Good;
OpcUa_ReferenceParameter(a_pCallContext);
OpcUa_ReferenceParameter(pObjectId);
OpcUa_UInt32_Initialize(out1);
*out1 = in1 + in2; // Add this line
return ret;
}

Step 4: Compiling and Running the Server Application

After completing the previous steps, you can compile the example projects with the delivered script [SDK Installation Directory]/buildSdk.sh.

If everything went well, you can find the applications server_lesson01 and server_lesson01d in the folder [SDK Installation Directory]/bin.

Step 6: Connect to the Server Application via UaExpert

The last step is to check wheter the generated provider and its method are correctly implemented. Just connect to the server with Unified Automation’s UaExpert, browse to your generated object type (Root → Types → ObjectTypes → BaseObjectType → MyObjectType) and call the method.