IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)

EndpointDiscovery QML Type

Provides information about available endpoints on a server.

This type was introduced in QtOpcUa 5.13.

Article lu   fois.

L'auteur

Liens sociaux

Viadeo Twitter Facebook Share on Google+   

EndpointDiscovery QML Type

  • Import Statement: import QtOpcUa

  • Since:: QtOpcUa 5.13

Detailed Description

Allows to fetch and access information about available endpoints on a server.

 
Sélectionnez
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 > 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 > 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

count : int

Current number of endpoints in this element. Before using any data from an endpoint discovery, you should check status if the information was successfully retrieved.

See Also

See also status, Status

serverUrl : string

Discovery URL of the server to fetch the endpoints from. Every time the URL is changed, a request to the given server is started.

When starting the request, the list of available endpoints is cleared and the status is set to Status.GoodCompletesAsynchronously. Once the request is finished, status changes.

Make sure to check status before accessing the list of endpoints.

See Also

See also endpointsChanged

status : Status

The current status of this element. In case the last retrieval of endpoints was successful, the status is Status.Good.

 
Sélectionnez
if (endpoints.status.isGood) {
    // do something
} else {
    // handle error
}
See Also

See also Status

Signal Documentation

 

endpointsChanged()

Emitted when a retrieval request started, finished or failed. In a called function, you should first check the status of the object. If the status is Status.GoodCompletesAsynchronously, the request is still running. If the status is Status.Good, the request has finished and the endpoint descriptions can be read. If the status is not good, an error happened and status contains the returned error code.

 
Sélectionnez
onEndpointsChanged: {
        if (endpoints.status.isGood) {
            if (endpoints.status.status == QtOpcua.Status.GoodCompletesAsynchronusly)
                return; // wait until finished
            if (endpoints.count > 0) {
                var endpointUrl = endpoints.at(0).endpointUrl();
                console.log(endpointUrl);
            }
        } else {
            // handle error
        }
}

The corresponding handler is onEndpointsChanged.

See Also

Method Documentation

 

EndpointDescription at(index)

Returns the endpoint description at given index. In case there are no endoints available or the index is invalid, an invalid endpoint description is returned. Before using any data from this, you should check status if retrieval of the information was successful.

 
Sélectionnez
if (endpoints.status.isGood) {
    if (endpoints.count > 0)
        var endpointUrl = endpoints.at(0).endpointUrl();
        console.log(endpointUrl);
} else {
    // handle error
}
See Also

Vous avez aimé ce tutoriel ? Alors partagez-le en cliquant sur les boutons suivants : Viadeo Twitter Facebook Share on Google+