Qt OPC UA 데이터 유형 생성기

Qt OPC UA Qt 6.7부터 qopcuaxmldatatypes2cpp 데이터 유형 생성기는 .bsd 파일의 열거형과 구조화된 유형으로부터 Qt OPC UA 호환 가능한 C++ 열거형과 데이터 클래스를 생성하는 데이터 유형 생성기( )와 함께 제공됩니다. 보조 기능으로 노드 ID 열거형은 CSV 파일에서 생성됩니다.

생성기는 다음 인수로 제어할 수 있는 명령줄 도구입니다:

LongShort목적
--input-i포함된 모든 열거형 및 구조체 유형이 생성될 .bsd 파일입니다. 여러 모델에 대한 코드를 생성하는 데 두 번 이상 사용할 수 있습니다.
--dependencyinput-d--input을 통해 전달된 입력 파일에서 구조체에 필요한 유형만 생성되는 종속성 입력 .bsd 파일입니다. 여러 다른 모델에 대한 종속성이 있는 모델을 수용하기 위해 두 번 이상 사용할 수 있습니다.
--nodeids-n열거형을 생성할 노드 ID가 포함된 .csv 파일의 이름 및 경로(예: MyModel:/path/to/nodeids.csv => 열거형 클래스 MyModelNodeId). 여러 번 지정할 수 있습니다.
--output-o생성된 파일을 저장할 출력 디렉터리입니다.
--prefix-p생성된 파일, 열거형 및 클래스 이름의 접두사. 기본값은 GeneratedOpcUa 입니다.
--bundle-b생성된 모든 파일을 #포함하는 번들 파일 <접두사>데이터타입스.h 및 <접두사>데이터타입스.cpp를 생성합니다.

각 실행에 대해 다음 파일이 생성됩니다:

  • 모든 열거된 유형이 포함된 네임스페이스가 포함된 .h 파일 1개
  • 각 구조화된 유형에 대해 .h 파일 1개 및 .cpp 파일 1개
  • 인코딩 및 디코딩 메서드가 포함된 .h 파일 1개와 .cpp 파일 1개
  • n이 한 번 이상 주어진 경우 노드 ID 열거형을 포함하는 .h 파일 1개
  • b가 주어진 경우 번들 파일 <접두사>데이터타입스.h 및 <접두사>데이터타입스.cpp

CMake 통합

qt_opcua_generate_datatypes() 함수는 하나 또는 여러 개의 입력 .bsd 파일과 필요한 모든 종속성 .bsd 파일을 가져와 qopcuaxmldatatypes2cpp를 호출합니다. 생성된 소스 및 헤더 파일은 OUTPUT_DIR에 기록되고 첫 번째 인수로 지정된 대상에 추가됩니다.

아웃풋 디렉터리 또는 그 상위 디렉터리도 대상의 인클루드 디렉터리에 추가해야 합니다.

다음 CMakeLists.txt 스니펫은 코드 생성기를 CMake 기반 프로젝트에 통합하는 방법을 보여줍니다:

find_package(Qt6 REQUIRED COMPONENTS Core OpcUa)

qt_standard_project_setup()

qt_add_executable(my_codegen
    mycodegen.cpp
)

qt_opcua_generate_datatypes(
    my_codegen # The target to add the generated files to
    INPUT_BSD "${CMAKE_CURRENT_SOURCE_DIR}/mymodel.bsd" # Must be set at least once if INPUT_CSV_MAP is not set
    INPUT_BSD "${CMAKE_CURRENT_SOURCE_DIR}/myothermodel.bsd"
    DEPENDENCY_BSD "${CMAKE_CURRENT_SOURCE_DIR}/mydependency.bsd" # Optional
    INPUT_CSV_MAP "MyModel:${CMAKE_CURRENT_SOURCE_DIR}/mymodel.csv" # Must be set at least once if INPUT_BSD is not set
    INPUT_CSV_MAP "MyOtherModel:${CMAKE_CURRENT_SOURCE_DIR}/myothermodel.csv"
    PREFIX "GeneratedOpcUa" # Mandatory
    OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated" # Mandatory
)

target_include_directories(my_codegen
    PRIVATE
        ${CMAKE_CURRENT_BINARY_DIR}
)

target_link_libraries(my_codegen PRIVATE Qt6::Core Qt6::OpcUa)

생성된 파일은 데이터 유형과 인코더/디코더 클래스에 대한 두 개의 최상위 헤더를 포함하여 모든 헤더 또는 소스 파일에서 사용할 수 있습니다.

#include <generated/generatedopcuabinarydeencoder.h> // If INPUT_BSD was set
#include <generated/generatedopcuadatatypes.h> // If INPUT_BSD was set
#include <generated/generatedopcuanodeids.h> // If INPUT_CSV_MAP was set

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