UaModeler
1.4.3.352
|
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 the Visual Studio Solution for Lesson 1 of the Getting Started Tutorials for the ANSI C SDK 1.3.0 and newer in six simple steps.
The first step is to add a new Visual Studio Project to the Visual Studio Solution for Lesson 1 of the Getting Started Tutorials delivered with the ANSI C SDK. Open the Solution File by selecting Examples → Getting Started Server → Lesson 1 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 the output directory selected in HowTo (Windows): Create a New Project With a Method Step 2: Selecting a Template 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.
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 output folder.
It is necessary to add 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:
In addition to that, you have to add the following preprocessor definitions to your project file:
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 the Output File name in the Librarian section of your project file to
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:
This is all you have to do in the new project file.
Next, select the server application’s project file (lesson01) and add the library exampleprojectproviderd.lib to Linker → Additional Dependencies.
Finally, enter the output folder of UaModeler at Additional Include Directories.
First of all you have to add the provider in servermain.c:
Include the header file:
Add the provider to ServerMain():
In addition to that, the method has to be implemented in the generated file uaprovider_exampleproject_myobjecttype_methods.c as shown below:
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.