Connect to OPC UA server with OPC Toolbox

4 views (last 30 days)
Richard  Mens
Richard Mens on 10 Nov 2017
Commented: Srijith Vijay on 22 Jul 2025
I encounter a problem during connecting the OPC Toolbox to an OPC server.
I use a B&R PLC as server which works, as there is another client using this as server. However, when I try to connect through the OPC Toolbox to the server I get the following warning and error:
Warning: Some endpoints could not be retreived:
B&R Embedded OPC-UA Server and Client: The hostname could not be resolved.
In opc.ua.getServerInfo (line 68)
In opcuaserverinfo (line 29)
Error using opc.ua.Client/fetchEndpoints (line 625)
The hostname could not be resolved.
Error in opc.ua.Client/connect (line 409)
errorCode = clnt.fetchEndpoints;
The warning is given when asked for server information. The error is given when trying to connect to the server.
But when I put the endpoint in with uaClient.EnpointUrl: 'opc.tcp://hostname:port', I encouter following error:
Error using asyncioimpl.Channel/init
Endpoint Url must be a non-empty string.
Error in asyncio.Channel (line 105)
customProps = obj.ChannelImpl.init(options);
Error in opc.ua.Channel (line 17)
obj@asyncio.Channel(deviceName, converterName, varargin{:});
Error in opc.ua.Client/connect (line 466)
clnt.AsyncChannel = opc.ua.Channel(options, [Inf,0]);f true
So, MATLAB is clearing the string I put in the EndpointUrl.
When using UaExpert as tool to check the connection, I encouter a similar warning: Discovery GetEndpoints on opc.tcp://br-automation:4840 failed (BadHostUnknown). However, UaExpert is able to supress this warning and connect to the OPC server.
Has anybody encoutered the same problem? Or any suggestions on how-to-fix this problem? I would really appreciate an answer.

Answers (4)

Richard  Mens
Richard Mens on 16 Nov 2017
Hi all,
I found a solution! The solution is probably not the most fancy way to solve the issue, but it works for now.
- In the Client.m file I break at set.Endpoint, line 169 and line 174
- I make a client from the server endpoint:
uaClient = opcua('opc.tcp://hostname:port/')
- Then I monitor the newUrl, every time the string becomes empty I fill it with the EndpointUrl.
And I am connected!
  1 Comment
Jorge Val
Jorge Val on 21 Sep 2018
Dear Richard, I have the same issue. I also have difficulties implementing the changes you mentioned. Could you upload more details of your solution? Thanks

Sign in to comment.


Mario Ricardo Nascimento Marques Junior
Dear Richard, You can make the client.m file available? I have difficulties for make the changes you suggest. Tks
  1 Comment
Michael Groen
Michael Groen on 8 Nov 2018
Hey Mario,
You can try to use the "Run and Time"-Button to start your programm. In the Profiler you might be able to click on the Client Function (something like 'Client>Client.connect') --> scroll down to the eof and click any blue line-number of the Code. Then the object-file might open in the editor and there you can make some changes ;)

Sign in to comment.


MathWorks Industrial Communication Toolbox Team
This issue arises when the OPC UA Server includes certificates with endpoints that cannot be accessed by the client, particularly when the client connects through multiple interfaces.
You can find more info in the below MATLAB Answer:

Thomas Pursche
Thomas Pursche on 22 Jul 2025
Hi all,
I encountered a similar problem. I wanted to connect to an OPCUA server that was running on a different machine. Connection via different OPCUA client like Matrikon or UA Expert or something like this were no problem, but with my Matlab application no change.
The first thing is connection via opcua('opc.tcp://myIPadress:myPort') is not working. The first step is to change it in the following:
opcua( obj.Host,obj.Portnum)
The next issue is that when now browsing via opcuaserverinfo, the server cannot find any Endpoints. No Endpoints no connection. The reason seems that Matlabs Toolbox is currently not capable of resolve Hostname other than localhost, also IP adress not working.
The solution is go to C:\Windows\System32\drivers\etc
Open the hosts file with a text Editor and write your IP adress and then your Hostname in the file like this
myIPAdress MySuperServerHostname
Afterwards Matlab is directly able to make a connection, no restart needed.
Best regards,
Thomas
  1 Comment
Srijith Vijay
Srijith Vijay on 22 Jul 2025
Starting MATLAB R2025a, you can now replace the endpoint URL hostname with input hostname/IP using the name-value argument UseDiscoveryHostname. For more information, see Create OPC UA Client and Configure Endpoint URL Hostname.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!