OPCUA open62541连接西门子840d sl出现错误,有偿求解。

采用open62541连接连接西门子840d sl服务器,连接代码如下:

...
UA_Client *client = UA_Client_new();
UA_ClientConfig *cc = UA_Client_getConfig(client);
UA_ClientConfig_setDefault(cc);
cc->securityMode = UA_MESSAGESECURITYMODE_SIGN;
UA_StatusCode retval = UA_Client_connectUsername(client, "opc.tcp://192.168.1.1:4840", "Account", "Passw");
...

出现错误如下:

[2021-12-24 11:52:45.093 (UTC+0800)] warn/userland      AcceptAll Certificate Verification. Any remote certificate will be accepted.
[2021-12-24 11:52:45.134 (UTC+0800)] info/channel       Connection 192 | SecureChannel 2027298388 | SecureChannel opened with SecurityPolicy http://opcfoundation.org/UA/SecurityPolicy#None and a revised lifetime of 600.00s
[2021-12-24 11:52:45.135 (UTC+0800)] info/client        Client Status: ChannelState: Open, SessionState: Closed, ConnectStatus: Good
[2021-12-24 11:52:45.139 (UTC+0800)] info/client        Rejecting endpoint 0: security mode doesn't match
[2021-12-24 11:52:45.139 (UTC+0800)] info/client        Rejecting endpoint 1: security mode doesn't match
[2021-12-24 11:52:45.140 (UTC+0800)] info/client        Rejecting endpoint 2: security policy not available
[2021-12-24 11:52:45.140 (UTC+0800)] info/client        Rejecting endpoint 3: security mode doesn't match
[2021-12-24 11:52:45.140 (UTC+0800)] info/client        Rejecting endpoint 4: security policy not available
[2021-12-24 11:52:45.140 (UTC+0800)] info/client        Rejecting endpoint 5: security mode doesn't match
[2021-12-24 11:52:45.140 (UTC+0800)] info/client        Rejecting endpoint 6: security policy not available
[2021-12-24 11:52:45.141 (UTC+0800)] error/client       No suitable endpoint found
[2021-12-24 11:52:45.149 (UTC+0800)] info/client        Client Status: ChannelState: Closed, SessionState: Closed, ConnectStatus: BadInternalError

采用UaExpert可以连上服务器并读取变量,服务器属性如下:

img

猜测应该是security policy设置有问题,但不知道如何设置。项目比较简单但比较紧急,只需编写Qt OPCUA客户端实现对西门子840d服务器变量访问,可有偿解决,价格可进一步商量:line_cliche@foxmail.com。感谢!

MiniWeb 用户和读取权限你弄了?

请问你的西门子软件是什么版本的

看代码分析,设置顺序上是否存在问题,你看一下下面的代码是否可以。
有帮助请采纳谢谢!


...
UA_Client *client = UA_Client_new();
UA_ClientConfig *cc = UA_Client_getConfig(client);
cc->securityMode = UA_MESSAGESECURITYMODE_SIGN;
UA_ClientConfig_setDefault(cc);
UA_StatusCode retval = UA_Client_connectUsername(client, "opc.tcp://192.168.1.1:4840", "Account", "Passw");
...

可能是权限不够的原因

插个眼

No suitable endpoint found

方便把报错的截图发一下嘛

感觉是安全模式配置的不对。