ServerDiscovery QML Type▲
-
Import Statement: import QtOpcUa
-
Since:: QtOpcUa 5.13
Detailed Description▲
Allows to fetch and access information about servers known to a server or discovery server.
QtOpcUa.Connection {
id
:
connection
backend
:
availableBackends[0
]
defaultConnection
:
true
}
QtOpcUa.ServerDiscovery {
discoveryUrl
:
"opc.tcp://127.0.0.1:43344"
onServersChanged
: {
if (
status
.
isGood) {
if (
status
.
status
==
QtOpcUa.
Status
.
GoodCompletesAsynchronusly)
return;
// wait until finished
if (
count &
gt;
0
) {
// choose right server
endpointDiscovery.
serverUrl =
at
(
0
).
discoveryUrls[
0
];
console.log
(
"Using server URL:"
,
endpointDiscovery.
serverUrl);
}
else {
// no servers retrieved
}
}
else {
// Fetching servers failed
console.log
(
"Error fetching server:"
,
servers.
status
.
status
);
}
}
}
QtOpcUa.EndpointDiscovery {
id
:
endpointDiscovery
onEndpointsChanged
: {
if (
status
.
isGood) {
if (
status
.
status
==
QtOpcUa.
Status
.
GoodCompletesAsynchronusly)
return;
// wait until finished
if (
count &
gt;
0
) {
// choose right endpoint
console.log
(
"Using endpoint"
,
at
(
0
).
endpointUrl,
at
(
0
).
securityPolicy);
connection.connectToEndpoint
(
at
(
0
));
}
else {
// no endpoints retrieved
}
}
else {
// Fetching endpoints failed
console.log
(
"Error fetching endpoints:"
,
status
.
status
);
}
}
}
Property Documentation▲
connection : Connection▲
The connection to be used for requesting information.
If this property is not set, the default connection will be used, if any.
See Also▲
See also Connection, Connection::defaultConnection
count : int▲
Current number of servers in this element. Before using any data from this server discovery, you should check status if retrieval of the information was successful.
See Also▲
discoveryUrl : string▲
URL of the server to retrieve the list of servers from. Every time the URL is changed, a request to the given server is started.
When starting the request, the list of available servers is cleared and the status is set to Status.GoodCompletesAsynchronously. Once the request is finished, status changes. Make sure to check the status before accessing the list of servers.
onServersChanged
:
{
if
(status.isGood) {
if
(status.status ==
QtOpcUa.Status.GoodCompletesAsynchronusly)
return
; // wait until finished
if
(count &
gt; 0
) {
var serverUrl =
at(0
).serverUrl();
console.log(serverUrl);
}
}
else
{
// handle error
}
}
See Also▲
See also ApplicationDescription, status, at, count, Status
status : Status▲
Method Documentation▲
ApplicationDescription at(index)▲
Returns the application description at given index. In case there are no servers available or the index is invalid, an invalid application description is returned. Before using any returned data, you should check status if retrieval of the information was successful.
if
(servers.status.isGood) {
if
(servers.count &
gt; 0
)
var serverUrl =
at(0
).serverUrl();
console.log(serverUrl);
// Choose endpoint to connect to
}
else
{
// handle error
}
See Also▲
See also count, status, ApplicationDescription