UaModeler  1.2.0.214
 All Pages
HowTo (Windows): 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 Visual Studio 2010 with Service Pack 1 in six simple steps.

NOTE: To compile the server with Visual Studio 2010 SP1 you need to have the third-party files compiled with Visual Studio 2010 SP1 as well.

Step 1: Adding a new vc(x)proj into the Visual Studio Solution

The first step is to add a new Visual Studio Project file into the existing Visual Studio Solution file delivered with the Ansi C SDK. Open the Solution File by selecting SDKSource → Build UA SDK from the start menu. Right click on the solution and select Add → New Project as shown in the screenshot below.

Now select a new Win32 Project and set the location to <Installation Directory>\UaSdkAnsiCServerProSource\vs\uaserver\uaserverc\providers and press the “OK” button.

Continue the wizard to Application Settings, select Static library and uncheck Precompiled header. Confirm with the “Finish” button and return to the solution.

Step 2: Adding the generated source files to the project

The next step is to add the source and header files (*.c and *.h) of the provider generated in HowTo (Windows): Create a new project with a method into the project created in the previous step: Right click on the project and select Add → Existing Item and select all generated source files in the folder <Installation Directory>\UaSdkAnsiCServerProSource\vs\uaserver\uaserverc\providers\exampleproject except the file uaprovider_exampleproject_myobjecttype.c.

Step 3: Adding include directories and preprocessor definitions

You also have to add all needed include directories, preprocessor definitions and a build event to finish your project file. Select “Properties” from the context menu.

First of all, add the following include directories to your project file:
..\..\..\..\..\src\uaserver\uaserverc\providers\exampleproject\.;..\..\..\..\..\src\uaserver\uaserverc\;..\..\..\..\..\src\uaserver\uaserverc\platforms\win32;..\..\..\..\..\src\uaserver\uaserverc\tools;..\..\..\..\..\src\uaserver\uaserverc\tools\platforms\win32;..\..\..\..\..\include\uastack;..\..\..\..\..\src\uastack\stackcore;

In addition to that, you have to add the preprocessor definitions into your project file.

Add these defines:
WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;_UA_STACK_USE_DLL;OPCUA_SUPPORT_SECURITYPOLICY_BASIC128RSA15=1;OPCUA_SUPPORT_SECURITYPOLICY_BASIC256=1;OPCUA_SUPPORT_SECURITYPOLICY_NONE=1;OPCUA_SUPPORT_PKI=1;OPCUA_MULTITHREADED=0;OPCUA_USE_SYNCHRONISATION=0;UASERVER_SERVICES_HISTORYREAD=1;UASERVER_SERVICES_HISTORYUPDATE=1;UASERVER_SERVICES_CALL=1;UASERVER_SUPPORT_EVENTS=1;HAVE_ENCODING_BINARY=1;

Set also the Output File name in the Librarian section of your project file to $(OutDir)\exampleprojectproviderd.lib. The “d” depends to your configuration. Use this “d” only in debug mode of your Visual Studio configuration.

The last step in your new project file is to add a Post-Build Event to copy the compiled library into the lib folder. To do this, navigate to Build Events → Post-Build Event and add the following line: copy /Y "$(TargetDir)" "..\..\..\..\..\lib". This is all you have to do in the new project file.

Step 4: Adding the exampleprojectprovider project into the server application

Next, select the server application’s project file (demoserver) and add the library exampleprojectproviderd into the Additional Dependencies form of the “Linker” section.

At last, add the new include directories into the server’s project file. Navigate to the section Additional Include Directories and add the following line: ..\..\..\..\src\uaserver\uaserverc\providers\exampleproject.

Step 5: Adding code to the application and implementing the method

First of all you have to add some code into the server’s main file (uaserver.c) as shown in the screenshots below.

In addition to that, the method has to be implemented in the generated file uaprovider_exampleproject_myobjecttype_methods.c as shown below.

Step 6: Compile, run and connect to the server

Now compile the whole solution and start up the application. You can see that the generated provider (ExampleProject Provider) was loaded and initialized, which means that this provider can be called and browsed in within any client.

Now 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.