1

我正在尝试获取服务器的服务器功能信息,而不使用多播扩展(无 MDNS)。作为 FindServers 方法,适用于applicationDescriptionUA_registeredServer结构,我通过添加容纳能力信息所需的两个字段来修改结构。

typedef struct {
    UA_String serverUri;
    UA_String productUri;
    size_t serverNamesSize;
    UA_LocalizedText *serverNames;
    UA_ApplicationType serverType;
    UA_String gatewayServerUri;
    size_t discoveryUrlsSize;
    UA_String *discoveryUrls;
    UA_String semaphoreFilePath;
    UA_Boolean isOnline;
    //ADDED 
    size_t serverCapabilitiesSize;
    UA_String *serverCapabilities;
} UA_RegisteredServer;

typedef struct {
    UA_String applicationUri;
    UA_String productUri;
    UA_LocalizedText applicationName;
    UA_ApplicationType applicationType;
    UA_String gatewayServerUri;
    UA_String discoveryProfileUri;
    size_t discoveryUrlsSize;
    UA_String *discoveryUrls;
    //ADDED 
    size_t serverCapabilitiesSize;
    UA_String *serverCapabilities;
} UA_ApplicationDescription;

LDS 的初始配置如下所示:

config->applicationDescription.serverCapabilitiesSize= 2;
    UA_String *caps = (UA_String *) UA_Array_new(2, &UA_TYPES[UA_TYPES_STRING]);
    caps[0]=UA_String_fromChars("LDS");
    caps[1]=UA_String_fromChars("TEST");
    config->applicationDescription.serverCapabilities = caps;


    UA_StatusCode retval = UA_Server_run(server, &running);

在 register_server_with_discoveryServer 中,我添加了功能

request.server.serverCapabilitiesSize=server->config.applicationDescription.serverCapabilitiesSize;
    size_t temp_size = server->config.applicationDescription.serverCapabilitiesSize;
    request.server.serverCapabilities = (UA_String*)
            UA_Array_new(temp_size, &UA_TYPES[UA_TYPES_STRING]);

    if(!request.server.serverCapabilities)
            return UA_STATUSCODE_BADOUTOFMEMORY;

    for(size_t i = 0; i < temp_size; ++i)
        request.server.serverCapabilities[i]=server->config.applicationDescription.serverCapabilities[i];

现在,当我运行 findServers.c 代码时,我希望在进入 applicationDescription 详细信息时显示 serverCapabilities 的值。但我没有得到结果。在 FindServers.c 代码中,我打印了功能的大小。它显示为 0,但是在服务器注册时它是 2。

for(size_t i = 0; i < applicationDescriptionArraySize; i++) {
        UA_ApplicationDescription *description = &applicationDescriptionArray[i];
       printf("\n The size: %ld",description->serverCapabilitiesSize);
}

o/p 是:

Server[0]: urn:open62541.example.local_discovery_server
    Name: open62541-based OPC UA Application
    Application URI: urn:open62541.example.local_discovery_server
    Product URI: http://open62541.org
    Type: Discovery Server
    Discovery URL:opc.tcp://o755-gksr:4840/
 The size: 0

serverCapabililty Identifier 是否仅与 mDNS 一起使用,不能修改为在没有 mDNS 的情况下使用?

[x] open62541 版本(发布号或 git 标签):v1.2-119-g7bde5f2b

Build option: cmake -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo -DUA_NAMESPACE_ZERO=FULL UA_ENABLE_DISCOVER = ON UA_ENABLE_DISCOVERY_MULTICAST = ON  UA_ENABLE_AMALGAMATION = ON ..  

4

0 回答 0