High Performance OPC UA Server SDK
1.3.0.231
|
This lesson will guide you through the process of setting up a basic OPC UA Server console application.
Files used in this lesson:
The recommended way of building applications with the SDK is using CMake. This and the further lessons rely on CMake being installed on the build machine.
Each lesson contains a CMakeLists.txt with the following structure:
The file server_main.c contains the functions server_main_init to start the server and server_main_clear to shut down the server. These are called by the main entry function of the compiled binary.
The main function starts the server and keeps the server running by calling uaapplication_timed_docom in the main loop until a shutdown is requested. Then the server is shut down:
First a crash handler is installed, the platform layer is initialized and the trace (if available) is opened with the given level and facilities:
To continue, the configuration of the server must be set. It is being stored in a global variable that must be named g_appconfig:
The appconfig struct controls memory consumption by specifing the maximum amount of dynamically allocated memory and the number of stack and SDK resources, like the maximum number of secure channels, sessions, or subscriptions. It also specifies the number and properties of endpoints to open and some further settings. The easiest way to create the appconfig is loading it from a settings file:
There are some fields in the appconfig that are not loaded from the settings file but have to be set manually. These are the information about the manufacturer, the product, and the application.
Now the shared memory and interprocess communication mechanism can be initialized. This allows using IPC functionality like ipc_malloc.
Next the SDK is initialized to set up libaries like encoder and allocate SDK resources. Also the address space is created by initializing the providers.
The providers to be loaded are stored in a global array with a handle and an init function for each array. The handle used to uniquely identify the provider will be assigned by the SDK, so it should be set to a negative number before start. The init function must be implemented by the provider. How to create a provider and implement such a function will be covered in the next lesson, in this application only the server provider is included:
Now the server can be started to begin listening for network connections:
The server stops handling network connections by calling uaserver_stop. The resources are cleared in the opposite direction than they were allocated:
CMake needs to know the source folder and the build folder for the project. The source folder is the lesson01 folder where the above mentioned CMakeLists.txt and server_main.c are stored (you can also use the higher level server_gettingstarted folder to build all lessons at once). The build folder is the folder where the executable will be built, e.g. a newly created folder inside or next to the source folder.
Depending on your platform you can choose one of the options described below.
To start the server, the follwing files must be in the same folder as the server:
Furthermore, the openssl dynamic libraries are needed. These must be either in the default search path of the system or also next to the server executable.
The endpoint address and port of the server default to 127.0.0.1 and
Now the server application can be started from its folder and a UA client like UaExpert can be used to connect and browse through the server addressspace.