EndpointDiscovery QML Type

提供有关服务器上可用端点的信息。更多

Import Statement: import QtOpcUa
Since: QtOpcUa 5.13
Status: Deprecated since 6.9

自 QtOpcUa 6.9 起,该类型已被弃用。我们强烈建议不要在新代码中使用它。

属性

信号

方法

  • EndpointDescription at(index)

详细说明

允许获取和访问服务器上可用端点的信息。

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);
        }
    }
}

属性 文档

connection : Connection

用于请求信息的连接。

如果未设置此属性,则将使用默认连接(如果有)。

另请参阅 ConnectionConnection::defaultConnection


count : int

该元素中端点的当前数量。在使用端点发现中的任何数据之前,应检查status 是否成功检索到信息。

另请参阅 statusStatus


serverUrl : string

从服务器获取端点的发现 URL。每次更改 URL 时,都会向指定服务器发出请求。

启动请求时,可用端点列表会被清空,状态会被设置为Status.GoodCompletesAsynchronously 。请求完成后,status

访问端点列表前,请务必检查status

另请参阅 endpointsChanged


status : Status

该元素的当前状态。如果上次端点检索成功,则状态为Status.Good

if (endpoints.status.isGood) {
    // do something
} else {
    // handle error
}

另请参见 Status


信号文档

endpointsChanged()

检索请求开始、结束或失败时发出的信号。在调用函数中,应首先检查对象的status 。如果状态为Status.GoodCompletesAsynchronously ,则请求仍在运行。如果状态为Status.Good ,则请求已完成,可以读取端点描述。如果状态不佳,则表示发生了错误,status 包含返回的错误代码。

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
        }
}

注: 相应的处理程序是onEndpointsChanged

另请参阅 status,count,at,StatusEndpointDescription


方法文档

返回给定index 的端点描述。如果没有可用的端点或索引无效,则返回无效的端点描述。在使用其中的任何数据之前,应检查status 是否成功检索到信息。

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

另请参阅 count,status, 和EndpointDescription


© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.