由于“没有合适的UserTokenPolicy”,因此与OpcUA-Server的连接失败

时间:2018-08-02 12:38:23

标签: c++ opc-ua open62541

我是OpcUA的新手,并使用Open62541 v3.0-rc2。

我正在尝试连接到B&R设备上的OpcUA服务器。

当我尝试使用用户名和密码连接到服务器时,收到此消息"No suitable UserTokenPolicy found for the possible endpoints"和此返回值UA_STATUSCODE_BADINTERNALERROR

UA_StatusCode statusCode = UA_Client_connect_username(client,endpoint,"user","password");

与UAExpert到设备的连接正常工作。

UAExpert的日志显示以下消息:

  

安全策略:“ http://opcfoundation.org/UA/SecurityPolicy#None

UA专家中的连接设置: Connection-Settings in UA-Expert

为什么我不能使用以下代码连接到服务器?

#include "open62541.h"

UA_Logger logger = UA_Log_Stdout;

int main(void) {
    const char* endpoint = "opc.tcp://br-automation:4840";

    UA_ClientConfig config = UA_ClientConfig_default;
    UA_Client *client = UA_Client_new(config);

    UA_StatusCode statusCode = UA_Client_connect_username(client,endpoint,"user","password");

    if(statusCode != UA_STATUSCODE_GOOD){
        UA_LOG_ERROR(logger, UA_LOGCATEGORY_CLIENT, "Not connected. Got StatusCode 0x%X",statusCode);
    }
    else{
        UA_LOG_INFO(logger,UA_LOGCATEGORY_CLIENT,"Connected");
    }

    UA_Client_delete(client);

    return statusCode;
}

UA_Client_getEndpoints()给出以下结果:

7 endpoints found
URL of endpoint 0 is opc.tcp://br-automation:4840 Security-Policy: http://opcfoundation.org/UA/SecurityPolicy#None Security-Mode: 1
    UserTokenType 1
    UserTokenType 1
URL of endpoint 1 is opc.tcp://br-automation:4840 Security-Policy: http://opcfoundation.org/UA/SecurityPolicy#Basic128Rsa15 Security-Mode: 2
    UserTokenType 1
    UserTokenType 1
URL of endpoint 2 is opc.tcp://br-automation:4840 Security-Policy: http://opcfoundation.org/UA/SecurityPolicy#Basic128Rsa15 Security-Mode: 3
    UserTokenType 1
    UserTokenType 1
URL of endpoint 3 is opc.tcp://br-automation:4840 Security-Policy: http://opcfoundation.org/UA/SecurityPolicy#Basic256 Security-Mode: 2
    UserTokenType 1
    UserTokenType 1
URL of endpoint 4 is opc.tcp://br-automation:4840 Security-Policy: http://opcfoundation.org/UA/SecurityPolicy#Basic256 Security-Mode: 3
    UserTokenType 1
    UserTokenType 1
URL of endpoint 5 is opc.tcp://br-automation:4840 Security-Policy: http://opcfoundation.org/UA/SecurityPolicy#Basic256Sha256 Security-Mode: 2
    UserTokenType 1
    UserTokenType 1
URL of endpoint 6 is opc.tcp://br-automation:4840 Security-Policy: http://opcfoundation.org/UA/SecurityPolicy#Basic256Sha256 Security-Mode: 3
    UserTokenType 1
    UserTokenType 1

1 个答案:

答案 0 :(得分:0)