Why does the OPC-Toolbox not connect with my PiXtend V2 / CoDeSys

1 次查看(过去 30 天)
There is no Problem to connect with a server on my localhost, like the matlab-examples. But when I try to connect with my PiXtend - PLC which uses CoDeSys, I alwasy get an error-message like this:
  1 个评论
olaf just
olaf just 2018-4-16
%try_OPC_UA.m %-----------------------------------------------
serverList = opcuaserverinfo('192.168.2.121:4840/') %PiXtend WLAN IP hsInfo = findDescription(serverList, 'raspberrypi') uaClient = opcua(hsInfo) connect(uaClient) %Verbinden klappt nicht !!!
Command Window:
>> try_OPC_UA
serverList =
OPC UA ServerInfo 'OPCUAServer@raspberrypi':
Connection Information
Hostname: '192.168.2.121'
Port: 4840
hsInfo =
OPC UA ServerInfo 'OPCUAServer@raspberrypi':
Connection Information
Hostname: '192.168.2.121'
Port: 4840
uaClient =
OPC UA Client OPCUAServer@raspberrypi: Hostname: 192.168.2.121 Port: 4840 Timeout: 10
Status: Disconnected
Client functions Error using opc.ua.Client/connect (line 499) The hostname could not be resolved.
Error in try_OPC_UA (line 8) connect(uaClient) %Verbinden klappt nicht !!!
>>

请先登录,再进行评论。

回答(3 个)

Jorge Val
Jorge Val 2018-9-21
Dear Olaf,
I have the same issue. I am using OPC UA server from RaspberryPi - CODESYS. I manage to access from Python and UAexpert clients. However, I cannot connect with Matlab:
uaClient =
OPC UA Client OPCUAServer@raspberrypi:
Hostname: 192.168.100.10
Port: 4840
Timeout: 10
Status: Disconnected
Client functions
Error using opc.ua.Client/connect (line 499)
*The hostname could not be resolved.*

robotik bocholt
robotik bocholt 2018-9-25
.. and we changed the PLC. With Siemens S7-1512 ist works, OPC_UA even with Matlab.

MathWorks Industrial Communication Toolbox Team
Hi,
This error could be happening because the OPC UA server is returning a discovery URL or endpoint URL containing a hostname that can't be resolved by the computer. You can verify this by capturing the OPC UA data packets in an application like Wireshark and viewing the "FindServersResponse" or "GetEndPointsResponse" OPC UA packets.
For e.g. here are the sequence of steps that occur internally when executing the following command:
uaClient = opcua("192.168.100.10",4840)
  1. Query Discovery URL: In this step the OPC UA client will send the "FindServersRequest" packet to 192.168.100.10 and the server at that IP will respond with a "FindServersResponse" containing the server's discovery URL.
  2. Get Endpoints: The client then sends a "GetEndpointsRequest" to the discovery URL received in the previous step. The server should ideally return a "GetEndpointsResponse" containing the final end point URL that the client can connect to.
So, in either step #1 or #2 above, the discovery or endpoint URL may contain a hostname that cannot be resolved by the computer on which the client runs. (e.g. opc.tcp://raspberrypi:4840).
As per the OPC UA Foundation:
"A Server may have multiple HostNames. For this reason, the Client shall pass the URL it used to connect to the Endpoint to this Service.The implementation of this Service shall use this information to return responses that are accessible to the Client via the provided URL.”
ie; when a client makes a call to an OPC UA Server to discover the endpoints to which it can connect, it is the server's responsibility to return endpoints that the client can discover. Because the server may be available on multiple hostnames (for example, the IP address, the hostname, or multiple IP addresses if there are multiple network cards) the server needs to use the hostname/IP sent by the client to construct the right endpoints.
Fix:
A short-term solution involves the client machine "registering" the server's hostname locally along with the network path used to connect to the server. The client's HOSTS file can include the IP address and hostname in the C:\Windows\System32\Drivers\etc\hosts file.
For e.g. add a line as follows to the above file in your system:
192.168.100.10 raspberrypi
In the long run, it is crucial to ensure that the server is configured to offer endpoints accessible through all available paths.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by