Connection QML Type

서버에 연결합니다. 더 보기...

Import Statement: import QtOpcUa
Since: QtOpcUa 5.12

속성

신호

방법

자세한 설명

기본 API는 백엔드를 사용하여 연결합니다. 연결을 시도하기 전에 백엔드를 설정해야 합니다.

import QtOpcUa as QtOpcUa

QtOpcUa.Connection {
    backend: "open62541"
}

Component.onCompleted: {
    connection.connectToEndpoint("opc.tcp://127.0.0.1:43344");
}

속성 문서

authenticationInformation : AuthenticationInformation

이 연결에 대한 인증 정보를 설정합니다. 인증 정보는 connectToEndpoint 을 호출하기 전에 설정해야 합니다. 인증 정보를 설정하지 않으면 익명 모드가 사용됩니다. 현재 연결에는 영향을 미치지 않습니다. 클라이언트의 연결이 끊어졌다가 다시 연결되면 새 자격 증명이 사용됩니다. backend 이 설정되기 전에 이 속성을 읽고 쓰면 쓰기는 무시되고 읽기는 반환되고 유효하지 않은 AuthenticationInformation 이 됩니다.


availableBackends : stringlist [read-only]

사용 가능한 모든 백엔드의 이름을 목록으로 반환합니다. 연결할 때 백엔드를 선택하는 데 사용됩니다.

Connection::backend도 참조하세요 .


backend : string

서버에 연결할 때 사용할 백엔드를 설정합니다. 연결을 시도하기 전에 설정해야 합니다.

Connection::availableBackends도 참조 하세요.


connected : bool [read-only]

연결 상태. 연결이 있으면 true, 그렇지 않으면 false.


connection : QOpcUaClient

이 속성은 C++에서 연결을 주입할 때만 사용됩니다. 연결 설정이 복잡한 경우 C++를 사용하여 모든 세부 사항을 처리할 수 있습니다. 연결이 설정된 후에는 이 프로퍼티를 사용하여 QML로 전달할 수 있습니다. 클라이언트의 소유권이 QML로 이전됩니다.

class MyClass : public QObject {
    Q_OBJECT
    Q_PROPERTY(QOpcUaClient* connection READ connection NOTIFY connectionChanged)

public:
    MyClass (QObject* parent = nullptr);
    QOpcUaClient *connection() const;

signals:
    void connectionChanged(QOpcUaClient *);

클라이언트 설정이 완료되면 connectionChanged 신호를 보내면 아래 QML 코드가 연결을 사용합니다.

import QtOpcUa as QtOpcUa

MyClass {
    id: myclass
}

QtOpcUa.Connection {
    connection: myclass.connection
 }

currentEndpoint : QOpcUaEndpointDescription

연결이 연결된 서버에 대한 엔드포인트 설명입니다. 연결이 설정되지 않으면 빈 엔드포인트 설명이 반환됩니다.


defaultConnection : bool

이 연결을 기본 연결로 설정합니다. 일반적으로 각 노드에 사용할 연결이 지정되어야 합니다. 이 속성을 true 으로 설정하면 노드에 설정된 연결이 없는 모든 경우에 이 연결이 사용됩니다. 이미 설정된 연결은 영향을 받지 않습니다. 여러 연결에서 defaultConnectiontrue 으로 설정된 경우 마지막 연결이 사용됩니다.

QtOpcUa.Connection {
    ...
    defaultConnection: true
    ...
}

Node도 참조하세요 .


namespaces : stringlist [read-only]

연결된 서버에 등록된 모든 네임스페이스 URI의 문자열 목록입니다.


supportedSecurityPolicies : stringlist

지원되는 보안 정책이 포함된 문자열 목록입니다.

이 속성은 현재 기술 미리보기로 제공되므로 제공되는 API 및 기능은 사전 통지 없이 언제든지 변경될 수 있습니다.


supportedUserTokenTypes : array[tokenTypes]

지원되는 모든 사용자 토큰 유형의 사용자 토큰 정책 유형 배열입니다.

이 속성은 현재 기술 미리보기로 제공되며, 따라서 제공되는 API 및 기능은 사전 통지 없이 언제든지 변경될 수 있습니다.


신호 문서

nodeChanged()

기본 노드가 변경되었을 때 발생합니다. NodeId 의 네임스페이스 또는 식별자가 변경되었을 때 발생합니다.

참고: 해당 핸들러는 onNodeChanged 입니다.


readNodeAttributesFinished(readResults)

readNodeAttributes()를 사용하여 시작된 읽기 요청이 완료되면 발생합니다. readResults 매개 변수는 서버에서 요청된 값을 포함하는 ReadResult 항목의 배열입니다.

connection.onReadNodeAttributesFinished(results) {
    for (var i = 0; results.length; i++) {
        if (results[i].status.isGood) {
            console.log(results[i].value);
        } else {
            // handle error
        }
    }
}

참고: 해당 핸들러는 onReadNodeAttributesFinished 입니다.

readNodeAttributes() 및 ReadResult도 참조하세요 .


writeNodeAttributesFinished(writeResults)

writeNodeAttributes()를 사용하여 시작된 쓰기 요청이 완료되면 발생합니다. writeResults 매개변수는 서버에서 요청된 값을 포함하는 WriteResult 항목의 배열입니다.

for (var i = 0; i < writeResults.length; i++) {
    console.log(writeResults[i].nodeId);
    console.log(writeResults[i].namespaceName);
    console.log(writeResults[i].attribute);

    if (writeResults[i].status.isBad) {
        // value was not written
    }
}

참고: 해당 핸들러는 onWriteNodeAttributesFinished 입니다.

writeNodeAttributes() 및 WriteResult도 참조하세요 .


메서드 문서

connectToEndpoint(endpointDescription)

endpointDescription 로 지정된 엔드포인트에 연결합니다.

EndpointDescription도 참조하세요 .


disconnectFromEndpoint()

설정된 연결을 끊습니다.


readNodeAttributes(valuesToBeRead)

이 함수는 서버에서 한 번에 여러 값을 읽는 데 사용됩니다. 읽기 요청이 성공적으로 전송되면 true 을 반환합니다.

valuesToBeRead 매개 변수는 ReadItem 항목의 JavaScript 배열이어야 합니다.

// List of items to read
var readItemList = [];
// Item to be added to the list of items to be read
var readItem;

// Prepare an item to be read

// Create a new read item and fill properties
readItem = QtOpcUa.ReadItem.create();
readItem.ns = "http://qt-project.org";
readItem.nodeId = "s=Demo.Static.Scalar.Double";
readItem.attribute = QtOpcUa.Constants.NodeAttribute.DisplayName;

// Add the prepared item to the list of items to be read
readItemList.push(readItem);

// Add further items
[...]

if (!connection.readNodeAttributes(readItemList)) {
    // handle error
}

읽기 요청의 결과는 readNodeAttributesFinished() 신호로 제공됩니다.

readNodeAttributesFinished() 및 ReadItem도 참조하세요 .


writeNodeAttributes(valuesToBeWritten)

이 함수는 한 번에 여러 값을 서버에 쓰는 데 사용됩니다. 쓰기 요청이 성공적으로 전송되면 true 을 반환합니다.

valuesToBeWritten 매개 변수는 WriteItem 항목의 JavaScript 배열이어야 합니다.

// List of items to write
var writeItemList = [];
// Item to be added to the list of items to be written
var writeItem;

// Prepare an item to be written

// Create a new write item and fill properties
writeItem = QtOpcUa.WriteItem.create();
writeItem.ns = "http://qt-project.org";
writeItem.nodeId = "s=Demo.Static.Scalar.Double";
writeItem.attribute = QtOpcUa.Constants.NodeAttribute.Value;
writeItem.value = 32.1;
writeItem.valueType = QtOpcUa.Constants.Double;

// Add the prepared item to the list of items to be written
writeItemList.push(writeItem);

// Add further items
[...]

if (!connection.writeNodeAttributes(writeItemList)) {
    // handle error
}

쓰기 요청의 결과는 Connection::writeNodeAttributesFinished() 신호로 제공됩니다.

Connection::writeNodeAttributesFinished() 및 WriteItem도 참조하세요 .


© 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.