OPC UA Java development notes (three): open62541 establish a foundation server

Two days ago I have been engaged in open62541, because the server sdk milo library is no way to generate nodes based on xml files, so ready to use open62541 to build server, milo combination Spring Boot to the client component.

Most of the network is to create a open62541.h header file, there is open62541.c executable file, but the new version seems not the case.
Then many tutorials are talking about linux, linux beginners but is still relatively small, as I wrote this one to help you configure.

But open62541 members considerable trouble, I tried did not thoroughly understand an afternoon, this morning finally be a little understand. Next, I step by step in terms of.

Why open62541?

  1. And commercial libraries, can directly generate the code generated according to the xml file uamodeler, simple steps.
  2. There is a complete tutorial, suitable for beginners, step by step to get started.
    3. There are many blog about domestic open62541 for reference

Understand the reason, we need to be practical operation, the first step is the hardest, that is installed

1. First, download

Here Insert Picture Description
Open62541 github we enter the official website open62541 , select the release version.
Here I use the win64 version.

Just great unpack the following file is completed, the file while myserver.c is to be established
Here Insert Picture Description

2. Establish project

Create a new C ++ in VS2019 the empty project .
Here Insert Picture Description
Open the project, and open the folder where the project file E: \ Code_Library \ TeachingOPC \ TeachingOPC , note the sln inside that folder. We downloaded copy of the release folder several files to the project folder.
Here Insert Picture Description
Position as
Here Insert Picture Description
Here Insert Picture Description
one of open62541 x64 library files, a header file is open62541
open the project in VS, then select all the files included in the project
Here Insert Picture Description
which is included after
Here Insert Picture Description
then the best place to metaphysics, and I'm still not out I understand why things. This time we need VS2015, but also open to 2015
Here Insert Picture Description
and then in the directory that contains additional add this one, $ (ProjectDir), then on it.

On this point I have a doubt, this operation I would VS2019 on to do will not work, then in 2015 on to do on it, I guess probably because the original document is the 2015 compilation, but after this operation 2019 above can also be used, very strange.

Next we create a new c or cpp file, enter the following code, the source code is:

#include <open62541/plugin/log_stdout.h>
#include <open62541/server.h>
#include <open62541/server_config_default.h>
#include <signal.h>
#include <stdlib.h>

static volatile UA_Boolean running = true;

static void stopHandler(int sig) {
	UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND, "received ctrl-c");
	running = false; 
}
int main(void) {
	signal(SIGINT, stopHandler);
	signal(SIGTERM, stopHandler);
	UA_Server *server = UA_Server_new();
	UA_ServerConfig_setDefault(UA_Server_getConfig(server));
	UA_StatusCode retval = UA_Server_run(server, &running);
	UA_Server_delete(server);
	return retval == UA_STATUSCODE_GOOD ? EXIT_SUCCESS : EXIT_FAILURE;
}

Successful operation
Here Insert Picture Description

PS:

  1. If Console which abnormal error, it may be the port is occupied, see solving occupied port
  2. If prompted less a dll file, then go online to search for the file, there is how the next tutorial, specifically what name I forget, a good solution to the problem

This is the windows side, the establishment of opc server method

Released six original articles · won praise 2 · Views 292

Guess you like

Origin blog.csdn.net/qq_41989109/article/details/104514147