Клиент чтения исторических данных OPC UA open62541 не скомпилирован

#gcc #sdk #opc-ua #opc #open62541

#gcc #sdk #opc-ua #opc #open62541

Вопрос:

На веб-сайте библиотеки в документации представлены варианты функций для доступа к чтению исторических данных. Также есть пример использования чтения исторических данных в репозитории. Я немного упростил этот пример из репозитория, но я все еще не могу его скомпилировать.

 #include <open62541/client_config_default.h>
#include <open62541/client_highlevel.h>

#include <stdio.h>
#include <stdlib.h>

static UA_Boolean readHist(UA_Client *client, const UA_NodeId *nodeId, UA_Boolean moreDataAvailable, const UA_ExtensionObject *data, void *unused)
{
    printf("nRead historical callback:n");
    printf("tHas more data:t%dnn", moreDataAvailable);

    return true;
}

int main(int argc, char *argv[])
{
    UA_Client *client = UA_Client_new();
    UA_ClientConfig_setDefault(UA_Client_getConfig(client));

    UA_StatusCode retval = UA_Client_connect(client, "opc.tcp://localhost:62544");
    if (retval != UA_STATUSCODE_GOOD)
    {
        UA_Client_delete(client);
        return EXIT_FAILURE;
    }

    UA_NodeId node = UA_NODEID_STRING(1, "MyTag");

    retval = UA_Client_HistoryRead_raw(client, amp;node, readHist, UA_DateTime_fromUnixTime(0), UA_DateTime_now(), UA_STRING_NULL, false, 10, UA_TIMESTAMPSTORETURN_BOTH, (void*) UA_FALSE);

    if (retval != UA_STATUSCODE_GOOD)
    {
        printf("Failed. %sn", UA_StatusCode_name(retval));
    }

    UA_Client_disconnect(client);
    UA_Client_delete(client);
    return retval == UA_STATUSCODE_GOOD ? EXIT_SUCCESS : EXIT_FAILURE;
}
 

Результат компиляции:

 01:02:53 **** Incremental Build of configuration Debug for project open62541 ****
Info: Internal Builder is used for build
gcc -std=c99 -DUA_ARCHITECTURE_WIN32 -DUA_ENABLE_HISTORIZING -O0 -g3 -Wall -c -fmessage-length=0 -o main.o "..\main.c" 
In file included from C:/msys64/mingw64/include/open62541/client_config_default.h:12,
                 from ..main.c:1:
C:/msys64/mingw64/include/open62541/client.h:389:18: error: unknown type name 'UA_HistoryReadResponse'
  389 | static UA_INLINE UA_HistoryReadResponse
      |                  ^~~~~~~~~~~~~~~~~~~~~~
C:/msys64/mingw64/include/open62541/client.h:390:56: error: unknown type name 'UA_HistoryReadRequest'
  390 | UA_Client_Service_historyRead(UA_Client *client, const UA_HistoryReadRequest request) {
      |                                                        ^~~~~~~~~~~~~~~~~~~~~
C:/msys64/mingw64/include/open62541/client.h: In function 'UA_Client_Service_historyRead':
C:/msys64/mingw64/include/open62541/client.h:391:5: error: unknown type name 'UA_HistoryReadResponse'; did you mean 'UA_ReadResponse'?
  391 |     UA_HistoryReadResponse response;
      |     ^~~~~~~~~~~~~~~~~~~~~~
      |     UA_ReadResponse
C:/msys64/mingw64/include/open62541/client.h:392:53: error: 'UA_TYPES_HISTORYREADREQUEST' undeclared (first use in this function); did you mean 'UA_NS0ID_HISTORYREADREQUEST'?
  392 |     __UA_Client_Service(client, amp;request, amp;UA_TYPES[UA_TYPES_HISTORYREADREQUEST],
      |                                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                                     UA_NS0ID_HISTORYREADREQUEST
C:/msys64/mingw64/include/open62541/client.h:392:53: note: each undeclared identifier is reported only once for each function it appears in
C:/msys64/mingw64/include/open62541/client.h:393:30: error: 'UA_TYPES_HISTORYREADRESPONSE' undeclared (first use in this function); did you mean 'UA_NS0ID_HISTORYREADRESPONSE'?
  393 |         amp;response, amp;UA_TYPES[UA_TYPES_HISTORYREADRESPONSE]);
      |                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                              UA_NS0ID_HISTORYREADRESPONSE
C:/msys64/mingw64/include/open62541/client.h: At top level:
C:/msys64/mingw64/include/open62541/client.h:397:18: error: unknown type name 'UA_HistoryUpdateResponse'
  397 | static UA_INLINE UA_HistoryUpdateResponse
      |                  ^~~~~~~~~~~~~~~~~~~~~~~~
C:/msys64/mingw64/include/open62541/client.h:398:58: error: unknown type name 'UA_HistoryUpdateRequest'
  398 | UA_Client_Service_historyUpdate(UA_Client *client, const UA_HistoryUpdateRequest request) {
      |                                                          ^~~~~~~~~~~~~~~~~~~~~~~
C:/msys64/mingw64/include/open62541/client.h: In function 'UA_Client_Service_historyUpdate':
C:/msys64/mingw64/include/open62541/client.h:399:5: error: unknown type name 'UA_HistoryUpdateResponse'
  399 |     UA_HistoryUpdateResponse response;
      |     ^~~~~~~~~~~~~~~~~~~~~~~~
C:/msys64/mingw64/include/open62541/client.h:400:53: error: 'UA_TYPES_HISTORYUPDATEREQUEST' undeclared (first use in this function); did you mean 'UA_NS0ID_HISTORYUPDATEREQUEST'?
  400 |     __UA_Client_Service(client, amp;request, amp;UA_TYPES[UA_TYPES_HISTORYUPDATEREQUEST],
      |                                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                                     UA_NS0ID_HISTORYUPDATEREQUEST
C:/msys64/mingw64/include/open62541/client.h:401:30: error: 'UA_TYPES_HISTORYUPDATERESPONSE' undeclared (first use in this function); did you mean 'UA_NS0ID_HISTORYUPDATERESPONSE'?
  401 |         amp;response, amp;UA_TYPES[UA_TYPES_HISTORYUPDATERESPONSE]);
      |                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                              UA_NS0ID_HISTORYUPDATERESPONSE

01:02:56 Build Failed. 10 errors, 0 warnings. (took 2s.585ms)
 

При компиляции он выдает ошибки, подобные этим, которые относятся к файлу «client.cpp » в котором нет объявлений типа.

введите описание изображения здесь

Я даже понятия не имею, что нужно сделать. Я пытаюсь скомпилировать пример, предоставленный разработчиками, но даже он не может быть скомпилирован. Это ошибка, недостаток или я делаю что-то не так? Очень необходимо реализовать метод чтения исторических данных через OPC UA. Я прошу помощи в решении этой проблемы.

Мои инструменты:

  • Windows 10
  • MSYS2 (MinGW)
  • Eclipse IDE
  • open62541 (версия v1.2.3)

Обновить

Итак, я перестроил библиотеку ветвей 1.2. Сборка прошла успешно:

 User@WIN-RRMNF8HHDN5 MINGW64 ~/open62541
# git submodule update --init --recursive
Submodule path 'deps/ua-nodeset': checked out '393b633468a5d1d062dd253e1488d1d8ba335b6f'

User@WIN-RRMNF8HHDN5 MINGW64 ~/open62541
# mkdir build amp;amp; cd build

User@WIN-RRMNF8HHDN5 MINGW64 ~/open62541/build
# cmake -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo -DUA_NAMESPACE_ZERO=FULL ..
-- Building for: Ninja
-- The C compiler identification is GNU 11.2.0
-- The CXX compiler identification is GNU 11.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/msys64/mingw64/bin/cc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/msys64/mingw64/bin/c  .exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PythonInterp: C:/msys64/mingw64/bin/python.exe (found version "3.9.7")
-- Found Git: C:/msys64/usr/bin/git.exe (found version "2.34.1")
-- open62541 Version: 1.2.3
-- The selected architecture is: win32
-- Test CC flag -std=c99
-- Performing Test flag_supported
-- Performing Test flag_supported - Success
-- Test CC flag -pipe
-- Performing Test flag_supported
-- Performing Test flag_supported - Success
-- Test CC flag -Wall
-- Performing Test flag_supported
-- Performing Test flag_supported - Success
-- Test CC flag -Wextra
-- Performing Test flag_supported
-- Performing Test flag_supported - Success
-- Test CC flag -Wpedantic
-- Performing Test flag_supported
-- Performing Test flag_supported - Success
-- Test CC flag -Werror
-- Performing Test flag_supported
-- Performing Test flag_supported - Success
-- Test CC flag -Wno-static-in-inline
-- Performing Test flag_supported
-- Performing Test flag_supported - Success
-- Test CC flag -Wno-overlength-strings
-- Performing Test flag_supported
-- Performing Test flag_supported - Success
-- Test CC flag -Wno-unused-parameter
-- Performing Test flag_supported
-- Performing Test flag_supported - Success
-- Test CC flag -Wc  -compat
-- Performing Test flag_supported
-- Performing Test flag_supported - Success
-- Test CC flag -Wformat
-- Performing Test flag_supported
-- Performing Test flag_supported - Success
-- Test CC flag -Wformat-security
-- Performing Test flag_supported
-- Performing Test flag_supported - Success
-- Test CC flag -Wformat-nonliteral
-- Performing Test flag_supported
-- Performing Test flag_supported - Success
-- Test CC flag -Wmissing-prototypes
-- Performing Test flag_supported
-- Performing Test flag_supported - Success
-- Test CC flag -Wstrict-prototypes
-- Performing Test flag_supported
-- Performing Test flag_supported - Success
-- Test CC flag -Wredundant-decls
-- Performing Test flag_supported
-- Performing Test flag_supported - Success
-- Test CC flag -Wuninitialized
-- Performing Test flag_supported
-- Performing Test flag_supported - Success
-- Test CC flag -Winit-self
-- Performing Test flag_supported
-- Performing Test flag_supported - Success
-- Test CC flag -Wcast-qual
-- Performing Test flag_supported
-- Performing Test flag_supported - Success
-- Test CC flag -Wstrict-overflow
-- Performing Test flag_supported
-- Performing Test flag_supported - Success
-- Test CC flag -Wnested-externs
-- Performing Test flag_supported
-- Performing Test flag_supported - Success
-- Test CC flag -Wmultichar
-- Performing Test flag_supported
-- Performing Test flag_supported - Success
-- Test CC flag -Wundef
-- Performing Test flag_supported
-- Performing Test flag_supported - Success
-- Test CC flag -fno-strict-aliasing
-- Performing Test flag_supported
-- Performing Test flag_supported - Success
-- Test CC flag -fexceptions
-- Performing Test flag_supported
-- Performing Test flag_supported - Success
-- Could NOT find Sphinx (missing: SPHINX_EXECUTABLE)
-- Could NOT find LATEX (missing: LATEX_COMPILER)
-- Configuring done
-- Generating done
-- Build files have been written to: C:/msys64/home/User/open62541/build

User@WIN-RRMNF8HHDN5 MINGW64 ~/open62541/build
# cmake --build .
[1/66] Generating src_generated/open62541/nodeids.h
[2/66] Generating src_generated/open62541/statuscodes.h, src_generated/open62541/statuscodes.c
[3/66] Generating src_generated/open62541/transport_generated.c, src_generated/open62541/transport_generated.h, src_generated/open62541/transport_generated_handling.h, src_generated/open62541/transport_generated_encoding_binary.h
[4/66] Generating src_generated/open62541/types_generated.c, src_generated/open62541/types_generated.h, src_generated/open62541/types_generated_handling.h, src_generated/open62541/types_generated_encoding_binary.h
[5/66] Generating src_generated/open62541/namespace0_generated.c, src_generated/open62541/namespace0_generated.h
INFO:__main__:Preprocessing C:/msys64/home/User/open62541/deps/ua-nodeset/Schema/Opc.Ua.NodeSet2.xml
INFO:__main__:Generating Code for Backend: open62541
INFO:__main__:NodeSet generation code successfully printed
[6/66] Building C object CMakeFiles/open62541-object.dir/src_generated/open62541/statuscodes.c.obj
[7/66] Building C object CMakeFiles/open62541-object.dir/src_generated/open62541/transport_generated.c.obj
[8/66] Building C object CMakeFiles/open62541-object.dir/src_generated/open62541/types_generated.c.obj
[9/66] Building C object CMakeFiles/open62541-object.dir/src/ua_types_print.c.obj
[10/66] Building C object CMakeFiles/open62541-object.dir/src/ua_types.c.obj
[11/66] Building C object CMakeFiles/open62541-object.dir/src/ua_types_encoding_binary.c.obj
[12/66] Building C object CMakeFiles/open62541-object.dir/src/ua_connection.c.obj
[13/66] Building C object CMakeFiles/open62541-object.dir/src/ua_timer.c.obj
[14/66] Building C object CMakeFiles/open62541-object.dir/src/ua_util.c.obj
[15/66] Building C object CMakeFiles/open62541-object.dir/src/ua_securechannel.c.obj
[16/66] Building C object CMakeFiles/open62541-object.dir/src/server/ua_session.c.obj
[17/66] Building C object CMakeFiles/open62541-object.dir/src/ua_securechannel_crypto.c.obj
[18/66] Building C object CMakeFiles/open62541-object.dir/src/server/ua_server_ns0.c.obj
[19/66] Building C object CMakeFiles/open62541-object.dir/src/server/ua_server.c.obj
[20/66] Building C object CMakeFiles/open62541-object.dir/src/server/ua_nodes.c.obj
[21/66] Building C object CMakeFiles/open62541-object.dir/src/server/ua_server_utils.c.obj
[22/66] Building C object CMakeFiles/open62541-object.dir/src/server/ua_server_discovery.c.obj
[23/66] Building C object CMakeFiles/open62541-object.dir/src/server/ua_server_config.c.obj
[24/66] Building C object CMakeFiles/open62541-object.dir/src/server/ua_server_binary.c.obj
[25/66] Building C object CMakeFiles/open62541-object.dir/src/pubsub/ua_pubsub_networkmessage.c.obj
[26/66] Building C object CMakeFiles/open62541-object.dir/src/pubsub/ua_pubsub_writer.c.obj
[27/66] Building C object CMakeFiles/open62541-object.dir/src/server/ua_server_async.c.obj
[28/66] Building C object CMakeFiles/open62541-object.dir/src/pubsub/ua_pubsub_ns0.c.obj
[29/66] Building C object CMakeFiles/open62541-object.dir/src/pubsub/ua_pubsub_reader.c.obj
[30/66] Building C object CMakeFiles/open62541-object.dir/src/server/ua_services_method.c.obj
[31/66] Building C object CMakeFiles/open62541-object.dir/src/pubsub/ua_pubsub_manager.c.obj
[32/66] Building C object CMakeFiles/open62541-object.dir/src/server/ua_services_subscription.c.obj
[33/66] Building C object CMakeFiles/open62541-object.dir/src/server/ua_services_attribute.c.obj
[34/66] Building C object CMakeFiles/open62541-object.dir/src/server/ua_services_session.c.obj
[35/66] Building C object CMakeFiles/open62541-object.dir/src/server/ua_services_monitoreditem.c.obj
[36/66] Building C object CMakeFiles/open62541-object.dir/src/server/ua_services_view.c.obj
[37/66] Building C object CMakeFiles/open62541-object.dir/src/server/ua_services_discovery.c.obj
[38/66] Building C object CMakeFiles/open62541-object.dir/src/server/ua_services_discovery_multicast.c.obj
[39/66] Building C object CMakeFiles/open62541-object.dir/src/client/ua_client_discovery.c.obj
[40/66] Building C object CMakeFiles/open62541-object.dir/src/server/ua_services_nodemanagement.c.obj
[41/66] Building C object CMakeFiles/open62541-object.dir/src/client/ua_client.c.obj
[42/66] Building C object CMakeFiles/open62541-object.dir/src/server/ua_services_securechannel.c.obj
[43/66] Building C object CMakeFiles/open62541-object.dir/deps/aa_tree.c.obj
[44/66] Building C object CMakeFiles/open62541-object.dir/deps/libc_time.c.obj
[45/66] Building C object CMakeFiles/open62541-object.dir/src/client/ua_client_connect.c.obj
[46/66] Building C object CMakeFiles/open62541-object.dir/deps/base64.c.obj
[47/66] Building C object CMakeFiles/open62541-object.dir/deps/pcg_basic.c.obj
[48/66] Building C object CMakeFiles/open62541-object.dir/src/client/ua_client_highlevel.c.obj
[49/66] Building C object CMakeFiles/open62541-object.dir/src/client/ua_client_subscriptions.c.obj
[50/66] Building C object CMakeFiles/open62541-object.dir/src/pubsub/ua_pubsub_config.c.obj
[51/66] Building C object CMakeFiles/open62541-object.dir/src/server/ua_subscription.c.obj
[52/66] Building C object CMakeFiles/open62541-object.dir/src/server/ua_subscription_monitoreditem.c.obj
[53/66] Building C object CMakeFiles/open62541-object.dir/src/server/ua_subscription_datachange.c.obj
[54/66] Building C object CMakeFiles/open62541-plugins.dir/plugins/ua_log_stdout.c.obj
[55/66] Building C object CMakeFiles/open62541-object.dir/src/ua_types_lex.c.obj
[56/66] Building C object CMakeFiles/open62541-plugins.dir/plugins/ua_nodestore_ziptree.c.obj
[57/66] Building C object CMakeFiles/open62541-plugins.dir/plugins/ua_config_default.c.obj
[58/66] Building C object CMakeFiles/open62541-plugins.dir/plugins/ua_nodestore_hashmap.c.obj
[59/66] Building C object CMakeFiles/open62541-plugins.dir/plugins/ua_accesscontrol_default.c.obj
[60/66] Building C object CMakeFiles/open62541-plugins.dir/plugins/crypto/ua_pki_none.c.obj
[61/66] Building C object CMakeFiles/open62541-plugins.dir/arch/win32/ua_clock.c.obj
[62/66] Building C object CMakeFiles/open62541-plugins.dir/plugins/crypto/ua_securitypolicy_none.c.obj
[63/66] Building C object CMakeFiles/open62541-plugins.dir/arch/win32/ua_architecture_functions.c.obj
[64/66] Building C object CMakeFiles/open62541-plugins.dir/arch/network_tcp.c.obj
[65/66] Building C object CMakeFiles/open62541-object.dir/src_generated/open62541/namespace0_generated.c.obj
C:/msys64/home/User/open62541/build/src_generated/open62541/namespace0_generated.c: In function 'namespace0_generated':
C:/msys64/home/User/open62541/build/src_generated/open62541/namespace0_generated.c:117159:15: note: variable tracking size limit exceeded with '-fvar-tracking-assignments', retrying without
117159 | UA_StatusCode namespace0_generated(UA_Server *server) {
       |               ^~~~~~~~~~~~~~~~~~~~
[66/66] Linking C shared library binlibopen62541.dll
 

После установки библиотеки я попытался снова собрать свой код. На этот раз появилась совершенно другая ошибка:

 03:18:12 **** Rebuild of configuration Debug for project open62541 ****
Info: Internal Builder is used for build
gcc -std=c99 -DUA_ARCHITECTURE_WIN32 -DUA_ENABLE_HISTORIZING -O0 -g3 -Wall -c -fmessage-length=0 -o main.o "..\main.c" 
gcc -o open62541.exe main.o -lopen62541 -lws2_32 
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: main.o: in function `main':
C:msys64homeUseropen62541Debug/../main.c:78: undefined reference to `__imp_UA_Client_HistoryRead_raw'
collect2.exe: error: ld returned 1 exit status

03:18:14 Build Failed. 2 errors, 0 warnings. (took 2s.452ms)
 

Вот сам код, который я пытаюсь скомпилировать:

 #include <open62541/client_config_default.h>
#include <open62541/client_highlevel.h>

#include <stdio.h>
#include <stdlib.h>

static UA_Boolean readHist(UA_Client *client, const UA_NodeId *nodeId, UA_Boolean moreDataAvailable, const UA_ExtensionObject *data, void *unused)
{
    printf("nRead historical callback:n");
    printf("tHas more data:t%dnn", moreDataAvailable);

    return true;
}

int main(int argc, char *argv[])
{
    UA_Client *client = UA_Client_new();
    UA_ClientConfig_setDefault(UA_Client_getConfig(client));

    UA_StatusCode retval = UA_Client_connect(client, "opc.tcp://localhost:62544");
    if (retval != UA_STATUSCODE_GOOD)
    {
        UA_Client_delete(client);
        return EXIT_FAILURE;
    }

    UA_NodeId node = UA_NODEID_STRING(1, "TNPZ.P_NEFT.R1.M");

    retval = UA_Client_HistoryRead_raw(client, amp;node, readHist, UA_DateTime_fromUnixTime(0), UA_DateTime_now(), UA_STRING_NULL, false, 10, UA_TIMESTAMPSTORETURN_BOTH, (void*) UA_FALSE);

    if (retval != UA_STATUSCODE_GOOD)
    {
        printf("Failed. %sn", UA_StatusCode_name(retval));
    }

    UA_Client_disconnect(client);
    UA_Client_delete(client);
    return retval == UA_STATUSCODE_GOOD ? EXIT_SUCCESS : EXIT_FAILURE;
}
 

Ответ №1:

Для того, чтобы механизм чтения исторических данных работал, необходимо при СБОРКЕ БИБЛИОТЕКИ включить параметр UA_ENABLE_HISTORIZING, который не указан в официальной документации для библиотеки.

 cmake -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo -DUA_ENABLE_HISTORIZING=ON -DUA_NAMESPACE_ZERO=FULL ..