산업 제조
산업용 사물 인터넷 | 산업자재 | 장비 유지 보수 및 수리 | 산업 프로그래밍 |
home  MfgRobots >> 산업 제조 >  >> Manufacturing Technology >> 산업기술

PLCnext CLI 템플릿

이 문서는 PLCnext CLI 버전 22.0.0 LTS에 적용됩니다.

<시간 />

C++를 사용하여 PLCnext Control 장치를 프로그래밍하는 경우 PLCnext CLI와 함께 설치된 코드 템플릿을 사용했을 것입니다.

Visual Studio 및 Eclipse에서 PLCnext 프로젝트 마법사(PLCnext IDE 확장으로 설치됨)로 새 프로젝트를 생성할 때 사용할 프로젝트 템플릿을 선택해야 합니다.

PLCnext CLI를 사용하여 명령줄에서 새 C++ 프로젝트를 생성할 때 프로젝트 템플릿도 지정해야 합니다.

세 가지 기본 프로젝트 템플릿은 다음과 같습니다.

  project              The project is a template for user programs.
                       They are managed by the PLM (Program Library Manager).

  acfproject           The acfproject is a template for component based platform development.
                       The resulting component will be managed by the ACF
                       (Application Component Framework).

  consumablelibrary    The consumable library is a template, that creates a library
	                   which can be used by other projects.

위의 정보는 plcncli new를 실행하면 볼 수 있습니다. 명령. 이러한 유형의 프로젝트에 대한 자세한 내용은 PLCnext 정보 센터에서 찾을 수 있습니다.

이 문서에서는 PLCnext CLI와 함께 설치된 추가 프로젝트 템플릿을 활성화하고 사용하는 방법과 고유한 프로젝트 템플릿을 만들고 사용하는 방법에 대해 설명합니다.

하지만 먼저 PLCnext CLI 템플릿 시스템이 어떻게 작동하는지 살펴보겠습니다.

PLCnext CLI 템플릿 시스템

PLCnext CLI에는 TemplateLocations라는 기본 설정이 포함되어 있습니다. , 코드 템플릿을 찾을 위치를 알려줍니다. 다음 명령을 사용하여 이 설정의 값을 볼 수 있습니다.

user@machine:~$ plcncli get setting TemplateLocations

{
  "setting": {
    "TemplateLocations": "./Templates/Templates.xml"
  }
}

xml 파일의 경로는 plcncli에 상대적입니다. 설치 경로.

./Templates로 이동하면 디렉토리에 Templates.xml이 표시됩니다. 파일 및 여러 하위 디렉토리.

Templates.xml의 내용 나열 파일 ...

user@machine:~/plcncli/Templates$ cat Templates.xml 
<?xml version="1.0" encoding="utf-8"?>
<Templates xmlns="http://www.phoenixcontact.com/schema/clitemplates">
  <Include type="Template">ProjectTemplate/TemplateDescription.xml</Include>
  <Include type="Template">ProgramTemplate/TemplateDescription.xml</Include>
  <Include type="Format">ProjectTemplate/FormatTemplates.xml</Include>
  <Include type="Template">ComponentTemplate/TemplateDescription.xml</Include>
  <Include type="Template">BaseTemplates/BaseTemplateDescription.xml</Include>
  <Include type="Template">BaseTemplates/CodeTemplateDescription.xml</Include>
  <Include type="Fields">BaseTemplates/FieldTemplates.xml</Include>
  <Include type="Types">BaseTemplates/TypeTemplates.xml</Include>
  <Include type="Format">BaseTemplates/FormatTemplates.xml</Include>
  <Include type="Template">AcfProjectTemplate/TemplateDescription.xml</Include>
  <Include type="Template">BaseProjectTemplate/TemplateDescription.xml</Include>
  <Include type="Template">AcfComponentTemplate/TemplateDescription.xml</Include>
  <Include type="Template">BaseComponentTemplate/TemplateDescription.xml</Include>
  <Include type="Template">ConsumableLibraryTemplate/TemplateDescription.xml</Include>
</Templates>

... TemplateDescription.xml에 대한 참조가 있음을 알 수 있습니다. Templates 아래의 디렉토리에 있는 다양한 유형의 파일 예배 규칙서. 여기에는 템플릿이 사용될 때 수행할 작업을 PLCnext CLI에 알려주는 지침이 포함되어 있습니다.

위에 표시된 템플릿 설명 파일은 이미 익숙한 세 가지 기본 프로젝트 템플릿을 구현합니다.

추가 템플릿을 활성화하는 방법

기본적으로 사용할 수 없는 PLCnext CLI와 함께 기본적으로 설치되는 "숨겨진" 프로젝트 템플릿이 하나 있습니다.

  minimumproject    This is the same as acfproject, but without the capability to create 
	                Port variables in the Global Data Space.

MinimalAcfTemplates.xml을 추가하여 PLCnext CLI에서 이 템플릿을 사용할 수 있도록 할 수 있습니다. 파일 - Templates에서 이미 눈치채셨을 수 있습니다. 디렉토리 - 템플릿 위치 설정:

user@machine:~$ plcncli set setting TemplateLocations ./Templates/MinimalAcfTemplates.xml --add

이제 새 XML 파일이 템플릿 위치에 추가되었습니다.

user@machine:~$ plcncli get setting TemplateLocations

{
  "setting": {
    "TemplateLocations": "./Templates/Templates.xml;./Templates/MinimalAcfTemplates.xml"
  }
}

... 그리고 plcncli new 명령이 실행됩니다. minimumproject 이제 옵션 목록에 나타납니다. 이제 이 템플릿을 사용하여 명령줄에서 새 C++ 프로젝트를 만들 수 있습니다.

참고: PLCnext CLI에 프로젝트 템플릿을 추가해도 Visual Studio 또는 Eclipse 프로젝트 마법사에 프로젝트 템플릿이 자동으로 추가되지 않습니다.

자신만의 PLCnext CLI 템플릿을 만드는 방법

사용자 지정 PLCnext CLI 템플릿 생성은 간단한 예를 사용하여 시연됩니다. "Hello World!"를 생성하는 PLCnext CLI 템플릿이 생성됩니다. C++의 콘솔 애플리케이션.

절차는 다음과 같습니다.

  1. 새 PLCnext CLI 프로젝트 템플릿에 대한 디렉터리를 만듭니다.

    Linux:

    user@machine:~/plcncli/Templates$ mkdir ExeTemplate && cd ExeTemplate
    
  2. 이 유형의 모든 새 프로젝트의 시작점으로 사용할 수 있는 템플릿 C++ 코드가 포함된 파일을 만드십시오.

    user@machine:~/plcncli/Templates/ExeTemplate$ touch Main.cpp
    

    이 예제에 사용된 C++ 코드는 다음과 같습니다.

    #include 
    
    int main() {
       std::cout << "Hello World!" << std::endl;
       return 0;
    }   
    
  3. 템플릿 cmake 소스 파일을 만듭니다.

    user@machine:~/plcncli/Templates/ExeTemplate$ touch CMakeLists.txt
    

    이 예제에 사용된 CMake 코드는 다음과 같습니다.

    cmake_minimum_required(VERSION 3.13)
    
    project($(name))
    
    if(NOT CMAKE_BUILD_TYPE)
      set(CMAKE_BUILD_TYPE Release)
    endif()
    
    ################# create target #######################################################
    
    file(GLOB_RECURSE Headers CONFIGURE_DEPENDS src/*.h src/*.hpp src/*.hxx)
    file(GLOB_RECURSE Sources CONFIGURE_DEPENDS src/*.cpp)
    add_executable(${CMAKE_PROJECT_NAME} ${Headers} ${Sources})
    
    #######################################################################################
    
    ################# set install directories #############################################
    
    string(REGEX REPLACE "^.*\\(([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+).*$" "\\1" _ARP_SHORT_DEVICE_VERSION ${ARP_DEVICE_VERSION})
    set(BIN_INSTALL_DIR ${ARP_DEVICE}_${_ARP_SHORT_DEVICE_VERSION}/${CMAKE_BUILD_TYPE})
    
    #######################################################################################
    
    ################# project include-paths ###############################################
    
    target_include_directories(${CMAKE_PROJECT_NAME}
        PRIVATE
        $)
    
    #######################################################################################
    
    ################# include arp cmake module path #######################################
    
    list(INSERT CMAKE_MODULE_PATH 0 "${ARP_TOOLCHAIN_CMAKE_MODULE_PATH}")
    
    #######################################################################################
    
    ################# set link options ####################################################
    # WARNING: Without --no-undefined the linker will not check, whether all necessary    #
    #          libraries are linked. When a library which is necessary is not linked,     #
    #          the firmware will crash and there will be NO indication why it crashed.    #
    #######################################################################################
    
    target_link_options(${CMAKE_PROJECT_NAME} PRIVATE LINKER:--no-undefined)
    
    #######################################################################################
    
    ################# add link targets ####################################################
    
    find_package(ArpDevice REQUIRED)
    find_package(ArpProgramming REQUIRED)
    
    target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE ArpDevice ArpProgramming)
    
    #######################################################################################
    
    ################# install #############################################################
    
    install(TARGETS ${CMAKE_PROJECT_NAME} RUNTIME DESTINATION ${BIN_INSTALL_DIR})
    unset(_ARP_SHORT_DEVICE_VERSION)
    
    #######################################################################################	
    

    CMake 코드에는 자리 표시자 $(name)이 포함됩니다. , plcncli new에 전달되는 프로젝트의 이름으로 대체됩니다. 명령.

  4. 선택 사항:README 파일을 새 템플릿 디렉터리에 추가합니다. 이 디렉터리는 이 템플릿에서 만든 각각의 새 프로젝트에서 README 파일을 만드는 데 사용할 수도 있습니다.

  5. PLCnext CLI 프로젝트 구성 파일을 생성합니다.

    이 파일은 PLCnext CLI에 대한 프로젝트 구성 정보를 저장하는 데 사용됩니다. 프로젝트가 구축되어야 하는 대상 목록입니다.

    이 예의 경우 .proj 파일이 ConsumableLibraryTemplate에서 복사되었습니다. 디렉토리를 만들고 다음을 생성하도록 편집했습니다.

    <?xml version="1.0" encoding="utf-8"?>
    <ProjectSettings xmlns="http://www.phoenixcontact.com/schema/cliproject">
      <Type>exeproject</Type>
      <Version>0.1</Version>
      <Name>$(name)</Name>
    </ProjectSettings>
    

    Type 필드에는 이 프로젝트 템플릿의 고유한 이름이 포함되어야 하며, 이 이름은 다음 단계의 템플릿 설명 파일에도 포함됩니다.

    Name 필드에는 자리 표시자 $(name)가 포함됩니다. , 각 새 프로젝트를 만드는 동안 프로젝트 이름으로 대체됩니다.

  6. 템플릿 설명 파일을 만듭니다.

    이 예의 경우 TemplateDescription.xml 파일이 ConsumableLibraryTemplate에서 복사되었습니다. 디렉토리를 만들고 다음을 생성하도록 편집했습니다.

    <?xml version="1.0" encoding="utf-8"?>
    <TemplateDescription name="exeproject" isRoot="true" basedOn="baseproject" supportedFirmwareVersions="19.0.0.16199" requiredCliVersion="19.0.0.660" version="1.0" 
                         xmlns="http://www.phoenixcontact.com/schema/clitemplates" identifier="ProjectSettingsIdentifier">
      <File name="plcnext.proj" template=".proj"/>
      <File name="CMakeLists.txt" template="CMakeLists.txt"/>
      <File name="README.md" template="README.md"/>
      <File name="$(name)Main.cpp" template="Main.cpp" path="src"/>
      <Description>Create a new stand-alone executable project.</Description>
      <Example>
        <Arguments>
          <Argument name="name" value="MyExe"/>
        </Arguments>
        <Description>creates a new stand-alone executable project in the directory 'MyExe'</Description>
      </Example>
    </TemplateDescription>
    

    템플릿 설명의 필드는 다음과 같습니다.

    • name="exeproject" :plcncli new exeproject 명령을 사용하여 이 템플릿에서 프로젝트를 생성할 수 있습니다. .
    • File name="A" template="B" path="C" :지정된 템플릿 파일을 기반으로 지정된 경로의 새 프로젝트에 파일을 생성합니다. 파일 이름에는 $(name)와 같은 자리 표시자가 포함될 수도 있습니다. , 각 새 프로젝트를 만드는 동안 프로젝트 이름으로 대체됩니다.
    • DescriptionExample plcncli의 관련 섹션에 표시되는 필드 도움말 시스템.
  7. PLCnext CLI에 새 템플릿에 대해 알리는 데 사용할 새 템플릿 파일을 만듭니다.

    이 예의 경우 MinimalAcfTemplates.xml Templates의 파일 디렉토리가 CustomTemplates.xml이라는 파일에 복사되었습니다. , 해당 파일은 다음을 생성하도록 편집되었습니다.

    <?xml version="1.0" encoding="utf-8"?>
    <Templates xmlns="http://www.phoenixcontact.com/schema/clitemplates">
             <Include type="Template">ExeTemplate/TemplateDescription.xml</Include>
    </Templates>
    
  8. PLCnext CLI를 사용하여 사용자 정의 템플릿 등록

    user@machine:~$ plcncli set setting TemplateLocations ./Templates/CustomTemplates.xml --add
    

    경로는 PLCnext CLI 설치 디렉토리에 상대적입니다.

  9. 사용해 보세요!

    다음 bash 명령 목록은 새 템플릿의 기능을 보여줍니다.

    plcncli new                                   # The help text includes the new template and description
    plcncli new exeproject --help                 # Displays the example showing how to use this template
    plcncli new exeproject --name "HelloWorld"    # Creates a new project based on the template
    cd HelloWorld
    plcncli set target -n AXCF2152 -v 2022 --add  # Sets the build target
    plcncli build                                 # Builds the project with the default template code
    scp bin/AXCF2152_22.0.3.129/Release/HelloWorld [email protected]:~  # Copies the executable to the device
    ssh [email protected]
    ./HelloWorld                                  # Runs the executable!
    

기여

앞으로 Github에서 PLCnext CLI Templates 프로젝트에 기여할 수 있을 예정입니다. 그때까지는 새로운 템플릿에 대한 아이디어나 직접 만든 템플릿의 예에 대한 문제를 열 ​​수 있습니다.

질문이나 의견이 있으십니까?

아래에 의견을 게시하거나 PLCnext 커뮤니티 포럼에서 질문하십시오.


산업기술

  1. C++ 클래스 템플릿
  2. C++ 템플릿
  3. 파이썬 - XML ​​처리
  4. PLCnext Technology의 VLAN 설정
  5. grpcurl을 사용하는 원격 gRPC
  6. 알리바바 클라우드 커넥터 사용 방법
  7. DHCP에서 PlcNext 웹 서버에 액세스
  8. PC에서 WakeOnLan(WoL)에 PLCnext 사용
  9. PLCnext의 클러스터 관리?
  10. PLCnext Tableau 대시보드