├── inc ├── plc_cr.h ├── plc_io.h ├── plc_cfg.h ├── plc_comm.h ├── plc_mem.h ├── plc_stat.h ├── plc_debug.h ├── plc_define.h ├── plc_std_fb.h ├── plc_std_fc.h ├── plc_timer.h └── plc_type_define.h ├── src ├── plc_cr.c ├── plc_io.c ├── plc_cfg.c ├── plc_comm.c ├── plc_main.c ├── plc_mem.c ├── plc_stat.c ├── plc_debug.c ├── plc_std_fb.c ├── plc_std_fc.c └── plc_timer.c ├── port ├── plc_port.c └── plc_port.h ├── docs ├── images │ ├── coil.png │ ├── add_task.gif │ ├── contact.png │ ├── plc_menu.png │ ├── LD_edit │ │ ├── 1.png │ │ ├── 10.png │ │ ├── 11.png │ │ ├── 12.png │ │ ├── 13.png │ │ ├── 14.png │ │ ├── 15.png │ │ ├── 16.png │ │ ├── 17.png │ │ ├── 18.png │ │ ├── 2.png │ │ ├── 3.png │ │ ├── 4.png │ │ ├── 5.png │ │ ├── 6.png │ │ ├── 7.png │ │ ├── 8.png │ │ ├── 9.png │ │ ├── ld_edit.gif │ │ ├── ld_edit_by_menu.gif │ │ ├── ld_call_function.gif │ │ └── ld_call_function_block_instance.gif │ ├── add_program.gif │ ├── cross_link.png │ ├── edit_menu.png │ ├── file_menu.png │ ├── help_menu.png │ ├── ld_example.png │ ├── ld_toolbar.PNG │ ├── main_window.PNG │ ├── new_program.PNG │ ├── new_project.PNG │ ├── new_project.gif │ ├── pou_ld_page.png │ ├── task_insert.gif │ ├── tool_menu.png │ ├── view_menu.png │ ├── add_resource.gif │ ├── app_directory.PNG │ ├── main_toolbar.PNG │ ├── new_function.PNG │ ├── output_window.png │ ├── plctoc_output.PNG │ ├── pou_text_page.PNG │ ├── project_tree.png │ ├── resource_page.png │ ├── task_example.PNG │ ├── c_files_generate.gif │ ├── ld_param_modify.png │ ├── options_dialog.PNG │ ├── pou_param_insert.gif │ ├── resource_insert.gif │ ├── software_model.png │ ├── configuration_page.PNG │ ├── main_window_marked.PNG │ ├── new_function_block.PNG │ ├── var_global_insert.gif │ ├── add_program_instance.gif │ ├── ld_right_button_menu.png │ ├── plcapp_directory_show.PNG │ ├── new_rtt_project_config.PNG │ ├── program_instance_insert.gif │ ├── character_representations.PNG │ ├── program_instance_example.PNG │ ├── software_model_example_code.png │ ├── software_model_example_graph.png │ ├── communication_function_blocks.png │ ├── communication_via_access_paths.png │ ├── plc_language_elements_combination.PNG │ ├── communication_via_global_variables.png │ └── data_flow_connection_whthin_a_program.png ├── PLC集成开发环境使用示例1.md ├── PLC集成开发环境用户手册.md ├── plccore软件包移植及使用说明.md └── IEC61131-3标准PLC编程参考手册.md ├── .project ├── examples └── plcapp │ ├── dataType.h │ ├── configuration.c │ ├── pou.h │ ├── resource.h │ ├── PROGRAM0.c │ ├── configuration.h │ └── resource.c ├── .gitignore ├── README.md └── LICENSE /inc/plc_cr.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/inc/plc_cr.h -------------------------------------------------------------------------------- /inc/plc_io.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/inc/plc_io.h -------------------------------------------------------------------------------- /src/plc_cr.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/src/plc_cr.c -------------------------------------------------------------------------------- /src/plc_io.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/src/plc_io.c -------------------------------------------------------------------------------- /inc/plc_cfg.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/inc/plc_cfg.h -------------------------------------------------------------------------------- /inc/plc_comm.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/inc/plc_comm.h -------------------------------------------------------------------------------- /inc/plc_mem.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/inc/plc_mem.h -------------------------------------------------------------------------------- /inc/plc_stat.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/inc/plc_stat.h -------------------------------------------------------------------------------- /src/plc_cfg.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/src/plc_cfg.c -------------------------------------------------------------------------------- /src/plc_comm.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/src/plc_comm.c -------------------------------------------------------------------------------- /src/plc_main.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/src/plc_main.c -------------------------------------------------------------------------------- /src/plc_mem.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/src/plc_mem.c -------------------------------------------------------------------------------- /src/plc_stat.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/src/plc_stat.c -------------------------------------------------------------------------------- /inc/plc_debug.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/inc/plc_debug.h -------------------------------------------------------------------------------- /inc/plc_define.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/inc/plc_define.h -------------------------------------------------------------------------------- /inc/plc_std_fb.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/inc/plc_std_fb.h -------------------------------------------------------------------------------- /inc/plc_std_fc.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/inc/plc_std_fc.h -------------------------------------------------------------------------------- /inc/plc_timer.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/inc/plc_timer.h -------------------------------------------------------------------------------- /port/plc_port.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/port/plc_port.c -------------------------------------------------------------------------------- /port/plc_port.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/port/plc_port.h -------------------------------------------------------------------------------- /src/plc_debug.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/src/plc_debug.c -------------------------------------------------------------------------------- /src/plc_std_fb.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/src/plc_std_fb.c -------------------------------------------------------------------------------- /src/plc_std_fc.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/src/plc_std_fc.c -------------------------------------------------------------------------------- /src/plc_timer.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/src/plc_timer.c -------------------------------------------------------------------------------- /docs/images/coil.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/coil.png -------------------------------------------------------------------------------- /inc/plc_type_define.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/inc/plc_type_define.h -------------------------------------------------------------------------------- /docs/images/add_task.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/add_task.gif -------------------------------------------------------------------------------- /docs/images/contact.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/contact.png -------------------------------------------------------------------------------- /docs/images/plc_menu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/plc_menu.png -------------------------------------------------------------------------------- /docs/images/LD_edit/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/LD_edit/1.png -------------------------------------------------------------------------------- /docs/images/LD_edit/10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/LD_edit/10.png -------------------------------------------------------------------------------- /docs/images/LD_edit/11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/LD_edit/11.png -------------------------------------------------------------------------------- /docs/images/LD_edit/12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/LD_edit/12.png -------------------------------------------------------------------------------- /docs/images/LD_edit/13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/LD_edit/13.png -------------------------------------------------------------------------------- /docs/images/LD_edit/14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/LD_edit/14.png -------------------------------------------------------------------------------- /docs/images/LD_edit/15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/LD_edit/15.png -------------------------------------------------------------------------------- /docs/images/LD_edit/16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/LD_edit/16.png -------------------------------------------------------------------------------- /docs/images/LD_edit/17.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/LD_edit/17.png -------------------------------------------------------------------------------- /docs/images/LD_edit/18.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/LD_edit/18.png -------------------------------------------------------------------------------- /docs/images/LD_edit/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/LD_edit/2.png -------------------------------------------------------------------------------- /docs/images/LD_edit/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/LD_edit/3.png -------------------------------------------------------------------------------- /docs/images/LD_edit/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/LD_edit/4.png -------------------------------------------------------------------------------- /docs/images/LD_edit/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/LD_edit/5.png -------------------------------------------------------------------------------- /docs/images/LD_edit/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/LD_edit/6.png -------------------------------------------------------------------------------- /docs/images/LD_edit/7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/LD_edit/7.png -------------------------------------------------------------------------------- /docs/images/LD_edit/8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/LD_edit/8.png -------------------------------------------------------------------------------- /docs/images/LD_edit/9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/LD_edit/9.png -------------------------------------------------------------------------------- /docs/images/add_program.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/add_program.gif -------------------------------------------------------------------------------- /docs/images/cross_link.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/cross_link.png -------------------------------------------------------------------------------- /docs/images/edit_menu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/edit_menu.png -------------------------------------------------------------------------------- /docs/images/file_menu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/file_menu.png -------------------------------------------------------------------------------- /docs/images/help_menu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/help_menu.png -------------------------------------------------------------------------------- /docs/images/ld_example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/ld_example.png -------------------------------------------------------------------------------- /docs/images/ld_toolbar.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/ld_toolbar.PNG -------------------------------------------------------------------------------- /docs/images/main_window.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/main_window.PNG -------------------------------------------------------------------------------- /docs/images/new_program.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/new_program.PNG -------------------------------------------------------------------------------- /docs/images/new_project.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/new_project.PNG -------------------------------------------------------------------------------- /docs/images/new_project.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/new_project.gif -------------------------------------------------------------------------------- /docs/images/pou_ld_page.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/pou_ld_page.png -------------------------------------------------------------------------------- /docs/images/task_insert.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/task_insert.gif -------------------------------------------------------------------------------- /docs/images/tool_menu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/tool_menu.png -------------------------------------------------------------------------------- /docs/images/view_menu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/view_menu.png -------------------------------------------------------------------------------- /docs/images/add_resource.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/add_resource.gif -------------------------------------------------------------------------------- /docs/images/app_directory.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/app_directory.PNG -------------------------------------------------------------------------------- /docs/images/main_toolbar.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/main_toolbar.PNG -------------------------------------------------------------------------------- /docs/images/new_function.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/new_function.PNG -------------------------------------------------------------------------------- /docs/images/output_window.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/output_window.png -------------------------------------------------------------------------------- /docs/images/plctoc_output.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/plctoc_output.PNG -------------------------------------------------------------------------------- /docs/images/pou_text_page.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/pou_text_page.PNG -------------------------------------------------------------------------------- /docs/images/project_tree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/project_tree.png -------------------------------------------------------------------------------- /docs/images/resource_page.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/resource_page.png -------------------------------------------------------------------------------- /docs/images/task_example.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/task_example.PNG -------------------------------------------------------------------------------- /docs/images/LD_edit/ld_edit.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/LD_edit/ld_edit.gif -------------------------------------------------------------------------------- /docs/images/c_files_generate.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/c_files_generate.gif -------------------------------------------------------------------------------- /docs/images/ld_param_modify.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/ld_param_modify.png -------------------------------------------------------------------------------- /docs/images/options_dialog.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/options_dialog.PNG -------------------------------------------------------------------------------- /docs/images/pou_param_insert.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/pou_param_insert.gif -------------------------------------------------------------------------------- /docs/images/resource_insert.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/resource_insert.gif -------------------------------------------------------------------------------- /docs/images/software_model.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/software_model.png -------------------------------------------------------------------------------- /docs/images/configuration_page.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/configuration_page.PNG -------------------------------------------------------------------------------- /docs/images/main_window_marked.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/main_window_marked.PNG -------------------------------------------------------------------------------- /docs/images/new_function_block.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/new_function_block.PNG -------------------------------------------------------------------------------- /docs/images/var_global_insert.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/var_global_insert.gif -------------------------------------------------------------------------------- /docs/images/add_program_instance.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/add_program_instance.gif -------------------------------------------------------------------------------- /docs/images/ld_right_button_menu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/ld_right_button_menu.png -------------------------------------------------------------------------------- /docs/images/plcapp_directory_show.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/plcapp_directory_show.PNG -------------------------------------------------------------------------------- /docs/images/LD_edit/ld_edit_by_menu.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/LD_edit/ld_edit_by_menu.gif -------------------------------------------------------------------------------- /docs/images/new_rtt_project_config.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/new_rtt_project_config.PNG -------------------------------------------------------------------------------- /docs/images/program_instance_insert.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/program_instance_insert.gif -------------------------------------------------------------------------------- /docs/images/LD_edit/ld_call_function.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/LD_edit/ld_call_function.gif -------------------------------------------------------------------------------- /docs/images/character_representations.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/character_representations.PNG -------------------------------------------------------------------------------- /docs/images/program_instance_example.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/program_instance_example.PNG -------------------------------------------------------------------------------- /docs/images/software_model_example_code.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/software_model_example_code.png -------------------------------------------------------------------------------- /docs/images/software_model_example_graph.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/software_model_example_graph.png -------------------------------------------------------------------------------- /docs/images/communication_function_blocks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/communication_function_blocks.png -------------------------------------------------------------------------------- /docs/images/communication_via_access_paths.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/communication_via_access_paths.png -------------------------------------------------------------------------------- /docs/images/plc_language_elements_combination.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/plc_language_elements_combination.PNG -------------------------------------------------------------------------------- /docs/images/communication_via_global_variables.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/communication_via_global_variables.png -------------------------------------------------------------------------------- /docs/images/data_flow_connection_whthin_a_program.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/data_flow_connection_whthin_a_program.png -------------------------------------------------------------------------------- /docs/images/LD_edit/ld_call_function_block_instance.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hyafz/plccore/HEAD/docs/images/LD_edit/ld_call_function_block_instance.gif -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | plccore 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /examples/plcapp/dataType.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------ 2 | 自动生成代码,请勿修改! 3 | ------------------------------------------------*/ 4 | #ifndef _dataType_H_ 5 | #define _dataType_H_ 6 | 7 | include "plc_type_define.h" 8 | 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /examples/plcapp/configuration.c: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------ 2 | 自动生成代码,请勿修改! 3 | ------------------------------------------------*/ 4 | #include "configuration.h" 5 | #include "plc_cfg.h" 6 | 7 | CONFIGURATION_S CONFIGURATION0; 8 | 9 | void _configuration_init_(void) 10 | { 11 | _resource_init_(&(CfgCB.rscCB)); 12 | } 13 | 14 | -------------------------------------------------------------------------------- /examples/plcapp/pou.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------ 2 | 自动生成代码,请勿修改! 3 | ------------------------------------------------*/ 4 | #ifndef _pou_H_ 5 | #define _pou_H_ 6 | #include "plc_type_define.h" 7 | 8 | #define PROGRAM0_STK_DEPTH 1 9 | typedef struct{ 10 | BYTE reserved; 11 | }PROGRAM0_S; 12 | 13 | void _PROGRAM0_(PROGRAM0_S* pParList); 14 | 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /examples/plcapp/resource.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------ 2 | 自动生成代码,请勿修改! 3 | ------------------------------------------------*/ 4 | #ifndef _resource_H_ 5 | #define _resource_H_ 6 | 7 | #include "plc_port.h" 8 | #include "plc_cfg.h" 9 | 10 | #define _RESOURCE_NAME_IS_RESOURCE0_ 11 | 12 | typedef struct{ 13 | PROGRAM0_S PROGRAM_INSTANCE0; 14 | }RESOURCE_S; 15 | 16 | void _resource_init_(RSC_CB_S* pRscCB); 17 | 18 | #endif 19 | 20 | -------------------------------------------------------------------------------- /examples/plcapp/PROGRAM0.c: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------ 2 | 自动生成代码,请勿修改! 3 | ------------------------------------------------*/ 4 | #include "plc_mem.h" 5 | #include "plc_cr.h" 6 | #include "pou.h" 7 | 8 | void _PROGRAM0_(PROGRAM0_S* pParList) 9 | { 10 | 11 | CR_Init(PROGRAM0_STK_DEPTH); 12 | CR_BOOL_LD(~QX(0)); 13 | 14 | QX_SET(0, CR_BOOL); 15 | 16 | _POU_Return: 17 | return; 18 | goto _POU_Return; 19 | _Error_Return: 20 | return; 21 | goto _Error_Return; 22 | } 23 | 24 | -------------------------------------------------------------------------------- /examples/plcapp/configuration.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------ 2 | 自动生成代码,请勿修改! 3 | ------------------------------------------------*/ 4 | #ifndef _configuration_H_ 5 | #define _configuration_H_ 6 | 7 | #include "pou.h" 8 | #include "resource.h" 9 | 10 | typedef struct{ 11 | #ifdef _RESOURCE_NAME_IS_RESOURCE0_ 12 | RESOURCE_S RESOURCE0; 13 | #endif 14 | }CONFIGURATION_S; 15 | 16 | extern CONFIGURATION_S CONFIGURATION0; 17 | 18 | void _configuration_init_(void); 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Object files 5 | *.o 6 | *.ko 7 | *.obj 8 | *.elf 9 | 10 | # Linker output 11 | *.ilk 12 | *.map 13 | *.exp 14 | 15 | # Precompiled Headers 16 | *.gch 17 | *.pch 18 | 19 | # Libraries 20 | *.lib 21 | *.a 22 | *.la 23 | *.lo 24 | 25 | # Shared objects (inc. Windows DLLs) 26 | *.dll 27 | *.so 28 | *.so.* 29 | *.dylib 30 | 31 | # Executables 32 | *.exe 33 | *.out 34 | *.app 35 | *.i*86 36 | *.x86_64 37 | *.hex 38 | 39 | # Debug files 40 | *.dSYM/ 41 | *.su 42 | *.idb 43 | *.pdb 44 | 45 | # Kernel Module Compile Results 46 | *.mod* 47 | *.cmd 48 | .tmp_versions/ 49 | modules.order 50 | Module.symvers 51 | Mkfile.old 52 | dkms.conf 53 | -------------------------------------------------------------------------------- /examples/plcapp/resource.c: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------ 2 | 自动生成代码,请勿修改! 3 | ------------------------------------------------*/ 4 | #include "configuration.h" 5 | #include "resource.h" 6 | #include "plc_mem.h" 7 | 8 | BOOL _task_TASK0_single_get_(void) 9 | { 10 | BOOL ret = 0; 11 | return ret; 12 | } 13 | 14 | TIME _task_TASK0_interval_get_(void) 15 | { 16 | TIME ret = 0; 17 | ret = 500; 18 | return ret; 19 | } 20 | 21 | void _task_TASK0_run_(void) 22 | { 23 | void* pParList; 24 | 25 | pParList = (void *)&(CONFIGURATION0.RESOURCE0.PROGRAM_INSTANCE0); 26 | 27 | 28 | _PROGRAM0_((PROGRAM0_S*)pParList); 29 | 30 | } 31 | 32 | void _task_default_run_(void) 33 | { 34 | void* pParList; 35 | 36 | } 37 | 38 | void _resource_init_(RSC_CB_S* pRscCB) 39 | { 40 | TASK_CB_S* pTaskCB; 41 | 42 | pRscCB->taskNum = 1; 43 | 44 | pTaskCB = &(pRscCB->taskCB[0]); 45 | pTaskCB->priority = 0; 46 | pTaskCB->singleGet = _task_TASK0_single_get_; 47 | pTaskCB->intervalGet = _task_TASK0_interval_get_; 48 | pTaskCB->taskRun = _task_TASK0_run_; 49 | 50 | pTaskCB = &(pRscCB->taskDefaultCB); 51 | pTaskCB->priority = PLC_TASK_LOWEST_PRIORITY; 52 | pTaskCB->taskRun = _task_default_run_; 53 | 54 | } 55 | -------------------------------------------------------------------------------- /docs/PLC集成开发环境使用示例1.md: -------------------------------------------------------------------------------- 1 | PLC集成开发环境(PLC IDE)使用示例 2 | ================================ 3 | 4 | ## 示例一 5 | 本示例使用一块具有6路本地数字量输出的PLC开发板,采用指令表语言,实现六位二进制数的累加,以输出灯亮灭的形式显示出来,并通过调节任务触发周期时间控制显示的变化速度。 6 | 7 | ### 1.新建工程 8 | ![新建工程](images/new_project.gif) 9 | 10 | ### 2.添加资源 11 | ![添加资源](images/add_resource.gif) 12 | “Ctrl + S”快捷键保存。 13 | 14 | ### 3.新建程序 15 | 新建程序program0,编程语言选择IL语言。 16 | ![新建程序](images/add_program.gif) 17 | 18 | ### 4.使用IL语言编辑程序 19 | 在编辑窗体中输入以下代码: 20 | ``` 21 | LD %QB0 (* 加载直接表示变量%QB0的值 *) 22 | ADD BYTE#1 (* 加1 *) 23 | ST %QB0 (* 重新保存至直接表示变量%QB0 *) 24 | ``` 25 | “Ctrl + S”快捷键保存代码。 26 | 27 | ### 5.在资源中添加任务 28 | 添加任务task0,修改任务触发周期时间为500ms。 29 | ![添加任务](images/add_task.gif) 30 | “Ctrl + S”快捷键保存。 31 | 32 | ### 6.在资源中添加程序program0的实例,并关联至任务task0 33 | ![添加程序实例](images/add_program_instance.gif) 34 | “Ctrl + S”快捷键保存。 35 | 36 | ### 7.将工程翻译并输出为C语言代码文件 37 | ![翻译生成C语言代码文件](images/c_files_generate.gif) 38 | 生成完成后可在工程目录下的plctoc_output子目录下找到生成的代码: 39 | ![生成的代码目录](images/plctoc_output.png) 40 | 41 | ### 8.复制生成的代码文件 42 | 将plctoc_output路径下的所有文件(不带目录结构)复制至RTT工程的plcapp目录 43 | ![plcapp目录](images/plcapp_directory_show.png) 44 | 45 | ### 9.在rt-thread Studio中刷新RTT工程树,build生成目标代码并下载至目标板,查看运行效果 46 | 47 | 48 | 视频链接:https://v.youku.com/v_show/id_XNDYwMzAzNDA2MA==.html 49 | 50 | ### 10.修改任务触发周期时间为100ms,重新生成代码并编译下载,查看效果 51 | 52 | 53 | 视频链接:https://v.youku.com/v_show/id_XNDYwMzAzMTQ2NA==.html 54 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # plccore 2 | 3 | ## 1、介绍 4 | 5 | plccore是一个基于rt-thread的可编程控制器(PLC)运行时内核,与本人开发的上位机编程软件——plcide一起构成一套完整的可编程控制器开发系统。依托RT-Thread的大量板级支持包(BSP),plccore可以快速移植适配更多MCU,节省大量开发时间。对于MCU开发者,plcide + plccore + rt-thread提供一种图形化、表格化的方式来开发MCU控制程序,非常方便、简单。 6 | 7 | ### 1.1 plccore的目标 8 | 开发plccore + plcide可编程控制器系统的目标有三点: 9 | - 实现完全遵循IEC61131-3标准的可扩展的开放型PLC编程系统,提高代码模块复用率; 10 | - 实现编译型PLC,相比解释型PLC不论指令密度还是执行效率都大大提升; 11 | - 探索使用图形化和表格化的形式开发嵌入式应用程序,简化MCU开发; 12 | 13 | ### 1.2 plccore能做什么? 14 | 对于MCU开发者,当你完成了RT-Thread + plccore移植后,可以使用plcide进行: 15 | 1. 图形化编写控制逻辑,任意多平台复用 16 | 2. 表格化配置多任务系统,不用写代码,支持不同的任务驱动模式: 17 | - 循环执行 18 | - 外部信号触发 19 | - 定时触发 20 | 21 | ### 1.3 目录结构 22 | 23 | | 名称 | 说明 | 24 | | ---- | ---- | 25 | | docs | 文档目录 | 26 | | examples | 例子目录,并有相应的一些说明 | 27 | | inc | 头文件目录 | 28 | | src | 源代码目录 | 29 | | port | 移植代码目录 | 30 | 31 | ### 1.4 许可证 32 | 33 | plccore package 遵循 LGPLv2.1 许可,详见 `LICENSE` 文件。 34 | 35 | ### 1.5 依赖 36 | 37 | - RT-Thread nano 3.1.3+ 38 | 39 | ## 2 如何移植plccore? 40 | 请参考软件包docs目录下给出的移植教程: 41 | 42 | GitHub: https://github.com/hyafz/plccore/blob/master/docs/plccore%E8%BD%AF%E4%BB%B6%E5%8C%85%E7%A7%BB%E6%A4%8D%E5%8F%8A%E4%BD%BF%E7%94%A8%E8%AF%B4%E6%98%8E.md 43 | 44 | 码云: https://gitee.com/hyafz/plccore/blob/master/docs/plccore%E8%BD%AF%E4%BB%B6%E5%8C%85%E7%A7%BB%E6%A4%8D%E5%8F%8A%E4%BD%BF%E7%94%A8%E8%AF%B4%E6%98%8E.md 45 | 46 | ## 3 如何获取上位机编程软件plcide? 47 | 通过百度网盘获取: 48 | 链接:https://pan.baidu.com/s/1QhqtQxH-Lha5Qvx2C7pesA 49 | 提取码:tjd8 50 | 51 | ## 4 如何使用plcide? 52 | 请参考软件包docs目录下给出的PLC集成开发环境用户手册: 53 | 54 | GitHub: https://github.com/hyafz/plccore/blob/master/docs/PLC%E9%9B%86%E6%88%90%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83%E7%94%A8%E6%88%B7%E6%89%8B%E5%86%8C.md 55 | 56 | 码云: https://gitee.com/hyafz/plccore/blob/master/docs/PLC%E9%9B%86%E6%88%90%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83%E7%94%A8%E6%88%B7%E6%89%8B%E5%86%8C.md 57 | 58 | 以及编程参考手册: 59 | 60 | GitHub: https://github.com/hyafz/plccore/blob/master/docs/IEC61131-3%E6%A0%87%E5%87%86PLC%E7%BC%96%E7%A8%8B%E5%8F%82%E8%80%83%E6%89%8B%E5%86%8C.md 61 | 62 | 码云: https://gitee.com/hyafz/plccore/blob/master/docs/IEC61131-3%E6%A0%87%E5%87%86PLC%E7%BC%96%E7%A8%8B%E5%8F%82%E8%80%83%E6%89%8B%E5%86%8C.md 63 | 64 | ## 5 示例 65 | 目前提供一个示例: 66 | 67 | GitHub: https://github.com/hyafz/plccore/blob/master/docs/PLC%E9%9B%86%E6%88%90%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83%E4%BD%BF%E7%94%A8%E7%A4%BA%E4%BE%8B1.md 68 | 69 | 码云: https://gitee.com/hyafz/plccore/blob/master/docs/PLC%E9%9B%86%E6%88%90%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83%E4%BD%BF%E7%94%A8%E7%A4%BA%E4%BE%8B1.md 70 | 71 | 后续将增加更多的示例。 72 | 73 | ## 6 联系方式 & 感谢 74 | 75 | * 维护 76 | - hyafz(401190549@qq.com) 77 | * 主页: 78 | - GitHub: https://github.com/hyafz/plccore 79 | - 码云:https://gitee.com/hyafz/plccore 80 | 81 | 82 | ## The End 83 | -------------------------------------------------------------------------------- /docs/PLC集成开发环境用户手册.md: -------------------------------------------------------------------------------- 1 | PLC集成开发环境(PLC IDE)用户手册 2 | ======================================== 3 | 4 | # 修订历史 5 | 6 | 版本 | 日期 | 修订人 | 审核人 | 描述 7 | :-: | :-: | :-: | :-: | :-: 8 | V0.1 | 2020.2.21 | 冯洲 | 冯洲 | 初次创建,部分软件功能还未实现,以实际为准。 9 | 10 | #1 软件介绍 11 | PLC IDE是一款符合IEC61131-3标准的通用PLC上位机编程软件,用户界面友好,操作简单方便。PLC IDE依照标准定义的PLC编程模型描述控制系统。可以将标准PLC语言编写的程序,转换为C语言程序输出。还可以结合PLC运行时内核代码直接编译出二进制的目标代码,实现编译型PLC功能。同时,软件还提供其它一些必备功能,比如程序下载、监控、调试等。 12 | ##1.1 软件特点 13 | - 符合IEC61131-3标准,对应国标GB/T 15969-3; 14 | - 支持标准编程模型:配置-资源-任务-程序-功能、功能块; 15 | - 支持 IL(指令表)和 LD(梯形图)两种标准语言,未来会支持其它标准PLC编程语言,以及C语言、G代码等其它语言; 16 | - 丰富的指令集,并支持 IEC61131-3 定义的标准功能与功能块; 17 | - 可将PLC程序翻译为C语言程序输出; 18 | - 可将PLC程序交叉编译为二进制目标代码,实现编译型PLC,相比解释型PLC,执行效率大大提高,指令密度更高,容错性更强(社区版软件不支持); 19 | - 显著降低PLC硬件成本,使用价格低廉、运算能力及存储空间有限的MCU就可实现完整的、高可靠性、高实时性的PLC功能,例如STM32F103RCT6; 20 | - 良好的系统扩展性,不但支持单PLC控制,未来还将支持多PLC协同控制; 21 | - 开放平台,支持添加新型号的PLC,有专门文档提供移植教程; 22 | - 使用标准格式的文本保存PLC程序,便于程序复用与同行交流; 23 | - 支持多种编程接口:串口、SWD/JTAG; 24 | 25 | #2 软件安装 26 | 27 | 按照安装包向导提示操作即可。 28 | 29 | #3 软件运行目录说明 30 | 31 | 软件安装完成后,进入安装目录,可以看到该目录下包含如下内容(某些子目录及文件需要软件运行一次后才创建): 32 | ![软件运行目录内容](images/app_directory.PNG) 33 | 34 | 这些子目录与文件的作用分别是: 35 | - build子目录:构建目标代码的中间目录 36 | - log子目录:保存软件运行时输出的各种Log信息文件 37 | - processors子目录:保存各种目标处理器相关工程、设置、代码文件 38 | - projects子目录:保存用户创建的工程文件 39 | - tools子目录:保存软件需要用到的各种第三方工具软件,比如build工具、交叉编译工具链等 40 | - plcide_en.qm、plcide_zh_CN.qm:界面语言文件 41 | - lastLoadProject:保存上次加载的工程路径文件名的文本文件 42 | - plcide.exe:软件可执行文件 43 | - 其它目录及*.dll文件:软件依赖的各种动态链接库文件 44 | #4 软件界面 45 | 软件主界面截图如下: 46 | 47 |
48 | 49 | ![软件主界面](images/main_window_marked.PNG) 50 | 软件主界面 51 | 1 标题栏,2 主菜单, 3 主工具栏, 4 梯形图编辑工具栏, 52 | 5 项目管理窗体, 6 主窗体, 7 库管理窗体, 8 信息输出窗体 53 |
54 | 55 | 以下各节将分别介绍软件界面的各组成部分。 56 | 57 | ##4.1 标题栏 58 | 59 | 标题栏显示软件名称、版本号等信息。 60 | 61 | ##4.2 主菜单 62 | 63 | 主菜单包括文件、编辑、插入、PLC、工具、视图、窗体、帮助等菜单项。 64 | 65 | ###4.2.1 文件菜单 66 | 67 | ![文件菜单](images/file_menu.PNG) 68 | 69 | | 名称 | 快捷键 | 功能描述 | 70 | | :-: | :-: | :-: | 71 | |新建 | | 创建一个新项目 | 72 | |打开 | | 打开硬盘上保存的项目文件 | 73 | |保存 | Ctrl+S | 将当前项目保存到硬盘 | 74 | |关闭 | | 关闭当前项目 | 75 | 76 | ###4.2.2 编辑菜单 77 | ![编辑菜单](images/edit_menu.PNG) 78 | 79 | | 名称 | 快捷键 | 功能描述 | 80 | | :-: | :-: | :-: | 81 | 复制 | | 复制选中对象,比如一段文本、一个文件、一个POU等。 82 | 剪切 | | 剪切选中对象,比如一段文本、一个文件、一个POU等。 83 | 粘贴 | | 粘贴复制或剪切的对象,比如一段文本、一个文件、一个POU等。 84 | 撤消 | | 撤消当前操作 85 | 重做 | | 重做当前撤消的操作 86 | 87 | ###4.2.3 插入菜单 88 | | 名称 | 快捷键 | 功能描述 | 89 | | :-: | :-: | :-: | 90 | | | 91 | 92 | ###4.2.4 PLC菜单 93 | ![PLC菜单](images/plc_menu.PNG) 94 | | 名称 | 快捷键 | 功能描述 | 95 | | :-: | :-: | :-: | 96 | 生成PLC文件 | | 解析工程信息生成标准格式的PLC代码文本,保存为后缀为.plc的文件。 97 | 生成C文件 | | 解析工程信息生成C语言代码,保存为后缀为.c/.h的文件 98 | 创建 | | 将当前工程编译生成目标代码文件(社区版软件不支持) 99 | 清除 | | 清除生成的文件 100 | 下载 | | 下载目标代码至PLC(社区版软件不支持) 101 | 运行 | | 控制PLC开始运行控制功能(社区版软件不支持) 102 | 停止 | | 控制PLC停止运行控制功能(社区版软件不支持) 103 | 监控 | | 监控PLC运行状态与数据(社区版软件不支持) 104 | 105 | ###4.2.5 工具菜单 106 | ![工具菜单](images/tool_menu.PNG) 107 | | 名称 | 快捷键 | 功能描述 | 108 | | :-: | :-: | :-: | 109 | 选项 | | 打开选项配置对话框 110 | 111 | ###4.2.6 视图菜单 112 | ![视图菜单](images/view_menu.PNG) 113 | | 名称 | 快捷键 | 功能描述 | 114 | | :-: | :-: | :-: | 115 | 工程可停靠窗体 | | 打开/关闭工程可停靠窗体 116 | 库可停靠窗体 | | 打开/关闭库可停靠窗体 117 | 输出可停靠窗体 | | 打开/关闭输出可停靠窗体 118 | 119 | ###4.2.7 窗体菜单 120 | | 名称 | 快捷键 | 功能描述 | 121 | | :-: | :-: | :-: | 122 | | | 123 | 124 | ###4.2.8 帮助菜单 125 | ![视图菜单](images/help_menu.PNG) 126 | | 名称 | 快捷键 | 功能描述 | 127 | | :-: | :-: | :-: | 128 | 帮助 | | 打开帮助文档 129 | 修订历史 | | 打开修订历史对话框 130 | 关于 | | 打开“关于”对话框 131 | 132 | ##4.3 工具栏 133 | 软件提供两个工具栏:主工具栏、梯形图编辑工具栏。 134 | ###4.3.1 主工具栏 135 | ![主工具栏](images/main_toolbar.PNG) 136 | 137 | 主工具栏图标依次是:新建、打开、保存、复制、剪切、粘贴、撤消、重做、创建、下载、运行、停止、监控、调试、配置,分别对应主菜单相关功能,请查看4.2.1 ~ 4.2.8节表格。 138 | ###4.3.2 梯形图编辑工具栏 139 | ![梯形图编辑工具栏](images/ld_toolbar.PNG) 140 | 141 | | 名称 | 快捷键 | 功能描述 | 142 | | :-: | :-: | :-: | 143 | 水平连接 | | 向梯形图中插入水平连接线 144 | 竖直连接 | | 向梯形图中插入竖直连接线 145 | 交叉连接 | | 向梯形图中插入各种交叉连接线,通过下拉列表选择类型 146 | 触点 | | 向梯形图中插入各种触点,通过下拉列表选择类型 147 | 线圈 | | 向梯形图中插入各种线圈,通过下拉列表选择类型 148 | 功能调用(规划) | |向梯形图中插入各种功能调用,通过下拉列表选择类型 149 | 功能块实例调用(规划) | |向梯形图中插入功能块调用,通过下拉列表选择类型 150 | 151 | 交叉连接有如下图所示类型: 152 | ![交叉连接类型](images/cross_link.PNG) 153 | 154 | 触点有如下图所示类型: 155 | ![触点类型](images/contact.PNG) 156 | 157 | 线圈有如下图所示类型: 158 | ![线圈类型](images/coil.PNG) 159 | 160 | ##4.4 项目管理窗体 161 | 项目管理窗体内部是一个树型结构,描述了项目的各组成部分,项目树的各叶子节点都可以点开进行相应编辑与操作。 162 | 163 | ![项目管理窗体](images/project_tree.PNG) 164 | 165 | ##4.5 PLC库管理窗体 166 | 等待补充… 167 | 168 | ##4.6 主窗体 169 | 主窗体是一个多页面控件,集中管理显示各种主要功能页面: 170 | - PLC配置管理页面 171 | - PLC资源管理页面 172 | - PLC程序组织单元(POU)管理页面 173 | 174 | ###4.6.1 PLC配置管理页面 175 | ![配置管理页面](images/configuration_page.PNG) 176 | 177 | ###4.6.2 PLC资源管理页面 178 | ![资源管理页面](images/resource_page.PNG) 179 | 180 | ###4.6.3 PLC程序组织单元编辑页面 181 | ![文本语言编辑](images/pou_text_page.PNG) 182 | ![梯形图语言编辑](images/pou_ld_page.PNG) 183 | 184 | ##4.7 信息输出窗体 185 | 信息输出窗体显示各种必要的信息,供用户查看。 186 | ![信息输出窗体](images/output_window.PNG) 187 | 188 | #5 软件操作 189 | ##5.1 工程管理 190 | ###5.1.1 新建工程 191 | 以下两种操作可新建工程: 192 | - 主菜单->File->New 193 | - 主工具栏->New 194 | ![新建工程](images/new_project.png) 195 | 196 | ###5.1.2 打开工程 197 | 以下两种操作可打开工程: 198 | - 主菜单->File->Open 199 | - 主工具栏->Open 200 | 201 | ###5.1.3 保存工程 202 | 以下两种操作可保存工程: 203 | - 主菜单->File->Save 204 | - 主工具栏->Save 205 | 206 | ###5.1.4 关闭工程 207 | 关闭工程操作: 208 | 主菜单->File->Close 209 | 210 | ##5.2 组态与编程 211 | ###5.2.1 修改PLC配置 212 | 双击工程树的配置叶子节点,可打开PLC配置管理页面。在本页面可以添加、删除和编辑从属于配置的全局变量、存取路径、实例专用的初始化、资源。 213 | 214 | ####5.2.1.1 添加删除全局变量 215 | 在VAR_GLOBAL表中右键点击,弹出右键菜单,选择“Insert”,即可插入一个全局变量。添加完成后可设置全局变量的名称、数据类型、位置、初始值、描述信息等。 216 | ![添加全局变量](images/var_global_insert.gif) 217 | 在右键菜单中选择“Remove”可以删除选定的全局变量。 218 | 219 | ####5.2.1.2 添加删除存取路径说明 220 | 等待补充… 221 | 222 | ####5.2.1.3 添加删除实例专用初始化说明 223 | 等待补充… 224 | 225 | ####5.2.1.4 添加删除资源说明 226 | 在资源说明表中右键点击,弹出右键菜单,选择“Insert”,即可插入一个资源说明。添加完成后可设置资源名称、处理器类型、描述信息。双击行可打开资源管理页面进行各种详细的设置。 227 | ![添加资源](images/resource_insert.gif) 228 | 在右键菜单中选择“Remove”可以删除选定的资源说明。 229 | 230 | ###5.2.2 修改PLC资源 231 | 点击配置管理页面中资源说明表格中的行,则打开对应的资源管理页面。在本页面可以添加、删除和编辑从属于资源的全局变量、任务和程序实例。 232 | ####5.2.2.1 添加删除全局变量 233 | 在全局变量表中右键点击,弹出右键菜单,选择“Insert”,即可插入一个全局变量。添加完成后可设置全局变量的名称、数据类型、位置、初始值、描述信息等。 234 | 在右键菜单中选择“Remove”可以删除选定的全局变量。 235 | 在资源中添加与删除全局变量都和在配置中的操作一样。 236 | 237 | ####5.2.2.2 添加删除任务 238 | 在任务表中右键点击,弹出右键菜单,选择“Insert”,即可插入一个任务。添加完成后可设置任务的名称、触发模式(信号跳变触发、周期触发)、触发时间、优先级、描述信息。 239 | 在右键菜单中选择“Remove”可以删除选定的任务。 240 | ![添加任务](images/task_insert.gif) 241 | 242 | ####5.2.2.3 添加删除程序实例 243 | 在程序实例中右键点击,弹出右键菜单,选择“Insert”,即可插入一个程序实例。添加完成后可设置程序实例的名称、程序名称、关联的任务名称、描述信息。 244 | 在右键菜单中选择“Remove”可以删除选定的程序实例。 245 | ![添加程序实例](images/program_instance_insert.gif) 246 | 247 | ###5.2.3 新建程序组织单元 248 | ####5.2.3.1 新建功能 249 | 在工程树的FUNCTION标签上右键点击,弹出右键菜单,选择”Insert Function”可弹出新建功能对话框。在本对话框中可设置新建功能的名称、输出数据类型、使用的编程语言。 250 | ![新建功能对话框](images/new_function.png) 251 | 252 | ####5.2.3.2 新建功能块 253 | 在工程树的FUNCTION BLOCK标签上右键点击,弹出右键菜单,选择”Insert Function Block”可弹出新建功能块对话框。在本对话框中可设置新建功能的名称、使用的编程语言。 254 | ![新建功能块对话框](images/new_function_block.png) 255 | 256 | ####5.2.3.3 新建程序 257 | 在工程树的PROGRAM标签上右键点击,弹出右键菜单,选择”Insert Program”可弹出新建程序对话框。在本对话框中可设置新建功能的名称、使用的编程语言。 258 | ![新建程序对话框](images/new_program.png) 259 | 260 | ###5.2.4 编辑程序组织单元 261 | 新建程序组织单元,或者点击项目树的任一程序组织单元叶子节点,则进入程序组织单元管理页面,可以添加、删除和修改程序参数、变量,编辑程序逻辑。程序逻辑可以使用文本语言或者图形语言。 262 | 263 | ####5.2.4.1 添加删除参数 264 | 在参数表中右键点击,弹出右键菜单,选择“Insert”,即可插入一个参数。添加完成后可设置参数的类型、名称、数据类型、初始值、属性、描述信息等。 265 | 在右键菜单中选择“Remove”可以删除选定的参数。 266 | ![添加程序组织单元参数](images/pou_param_insert.gif) 267 | 268 | ####5.2.4.2 文本语言程序编辑 269 | 目前文本语言编辑器只能进行基本的文本输入,没有附加特殊功能。用户需要自己按照编程参考描述的语法规则输入文本,完成程序编辑。 270 | 后续会加入语法着色、自动补全、错误检查等高级功能。 271 | 272 | ####5.2.4.3 梯形图语言程序编辑 273 | 梯形图程序呈现在一张画布上,画面左右是两条电源轨线,中间由行列排布的大小相同的矩形图元组成,梯形图程序的基本规则是使信号由左电源轨线传输至右电源轨线,形成一条或多条通路。如下图所示: 274 | ![梯形图程序](images/pou_ld_page.PNG) 275 | 如果一个元件的大小超出了一个图元的范围,则它将占用多个图元,比如功能与功能块实例调用。 276 | 277 | 目前支持两种模式编辑梯形图程序。 278 | - 通过工具栏编辑 279 | 选中一个图元,然后点击梯形图工具栏上的连线或元件图标,即可将选中的元件放置在图元位置,如下面的动图所示: 280 | ![通过工具栏编辑梯形图](images/LD_edit/ld_edit.gif) 281 | 梯形图编辑工具栏的说明参见“梯形图编辑工具栏”一节。 282 | 283 | - 通过右键菜单编辑 284 | 选中一个图元,右键调出菜单,选择需要的连线或元件,就能将选中的对象放置到图元上。如下面的动图所示: 285 | ![通过右键菜单编辑梯形图](images/LD_edit/ld_edit_by_menu.gif) 286 | 梯形图编辑右键菜单如下图所示: 287 | ![梯形图编辑右键菜单](images/ld_right_button_menu.png) 288 | 从右键菜单中可选择插入: 289 | - 水平连接线 290 | - 竖直连接线 291 | - 交叉连接线(规划) 292 | - 触点 293 | - 线圈 294 | - 功能 295 | - 功能块实例 296 | - 标签 297 | - 行:在选定图元下方插入一行空白图元,用于扩展画布范围。 298 | - 列:在选定图元的右方插入一列空白图元,用于扩展画布范围。 299 | 300 | 从右键菜单选择“Remove”, 可移除当前选中的图元。 301 | 插入元件后,单击元件的参数域,可以修改参数。例如: 302 | ![修改元件参数](images/ld_param_modify.png) 303 | 304 | ##5.3 代码生成 305 | 根据不同的需求,可以选择输出不同的代码文件: 306 | - 标准PLC代码文件,用于与同样符合标准的其它编程环境进行交流; 307 | - C代码文件,用于外部单片机控制程序开发; 308 | - 目标代码文件,直接下载至目标PLC中执行(社区版不支持); 309 | 310 | ###5.3.1 生成PLC代码 311 | 选择“主菜单”=>“PLC”=>“生成PLC代码”,即可生成PLC代码,并输出到以工程名命名,后缀为”.plc”的文件中。 312 | 313 | ###5.3.2 生成C代码 314 | 选择“主菜单”=>“PLC”=>“生成C代码”,即可生成C语言代码(*.c/*.h),并输出到工程目录下名称为”plctoc_output”的子目录中。 315 | 316 | ###5.3.3 构建目标代码(社区版软件不支持) 317 | 选择“主菜单”=>“PLC”=>“Build”,即可直接构建目标代码,生成以下文件: 318 | - 工程名.bin——二进制文件 319 | - 工程名.elf 320 | 321 | ##5.4 PLC联机操作(社区版软件不支持) 322 | 323 | ###5.4.1 程序下载 324 | 等待补充… 325 | 326 | ###5.4.2 PLC运行/停止控制 327 | 等待补充… 328 | 329 | ###5.4.3 PLC运行时监控 330 | 等待补充… 331 | 332 | ###5.4.4 PLC程序调试 333 | 等待补充… 334 | 335 | ###5.5 软件选项设置 336 | 以下操作可以弹出选项设置对话框: 337 | - 主菜单->Tools->Options… 338 | - 主工具栏->Options… 339 | ![选项对话框](images/options_dialog.png) 340 | 通过选项设置对话框可设置软件的各种配置选项,包括语言设置、通信接口设置及连接等。 341 | 342 | #6 编程参考 343 | 参见文档《IEC61131-3标准PLC编程参考手册》 344 | 345 | #7 库 346 | ##7.1 标准库 347 | 等待补充… 348 | 349 | ##7.2 扩展库 350 | 等待补充… 351 | 352 | ##7.3 用户库 353 | 等待补充… 354 | -------------------------------------------------------------------------------- /docs/plccore软件包移植及使用说明.md: -------------------------------------------------------------------------------- 1 | plccore软件包移植及使用说明 2 | ========================= 3 | 4 | 本软件包适用于RT-Thread nano,也适用于RT-Thread完整版,移植方式略有不同。 5 | 使用RTT完整版本移植更方便,可以很容易地整合RTT平台的各种驱动程序与软件包。但是相比nano版本,占用ROM与RAM空间更大,执行效率较低,任务实时性也较差。请用户根据需求进行权衡取舍。 6 | 本软件包目前仅针对意法半导体的STM32系列MCU进行了测试验证。 7 | 推荐使用RT-Thread Studio + Stm32CubeMX两款软件进行移植,操作方便,文档教程详细,即使是新手也很容易上手。 8 | 移植过程参考了RT-Thread官方提供的STM32系列BSP制作教程:https://github.com/RT-Thread/rt-thread/blob/master/bsp/stm32/docs/STM32%E7%B3%BB%E5%88%97BSP%E5%88%B6%E4%BD%9C%E6%95%99%E7%A8%8B.md 。 9 | 10 | --- 11 | ## 1. 准备 12 | 13 | 1. RT-Thread Studio软件(下载地址:https://www.rt-thread.org/page/studio.html) 14 | 2. Stm32CubeMX软件(下载地址:https://www.st.com/content/st_com/zh/products/development-tools/software-development-tools/stm32-software-development-tools/stm32-configurators-and-code-generators/stm32cubemx.html) 15 | 3. PLC组态及控制逻辑编程软件PLC IDE(电子邮件联系 401190549@qq.com 索取) 16 | 4. 获取plccore软件包 17 | - 基于RT-Thread nano 18 | 方式一:从github下载:https://github.com/hyafz/plccore 19 | 方式二:从码云下载:https://gitee.com/hyafz/plccore 20 | - 基于RT-Thread完整版 21 | 在RT-Thread Studio的配置中心添加plccore软件包。 22 | 23 | --- 24 | ## 2. 硬件要求 25 | - 必须使用一个检测输入状态的GPIO作为运行开关状态检测; 26 | - 必须使用一个GPIO控制一个LED亮灭作为运行状态显示灯(运行时亮,停止时灭); 27 | - 建议使用一个GPIO控制一个LED亮灭作为停止状态显示灯(运行时灭,停止时亮),如果没有,可定义一个空闲的管脚; 28 | - 建议使用一个GPIO控制一个LED亮灭作为错误状态显示灯(正常时灭,错误时常亮或闪烁),如果没有,可定义一个空闲的管脚; 29 | - 必须具备一个与上位机通信的串口; 30 | - 必须具备一个作为PLC主定时器的硬件定时器; 31 | 32 | --- 33 | ## 3. 使用RT-Thread Studio + Stm32CubeMX生成目标板的BSP工程 34 | 35 | ### 新建RT-Thread工程 36 | - 启动RT-Thread Studio,新建RT-Thread工程 37 | - 输入工程名称 38 | - 选择工程文件存放路径 39 | - 选择基于芯片 40 | - 选择RT-Thread版本 41 | - 选择对应的芯片型号 42 | - 选择控制台串口,必须与PLC专用串口不同 43 | - 选择调试口(JTAG or SWD) 44 | - 点击“完成”等待工程生成 45 | 46 | ![新建RTT工程配置](images/new_rtt_project_config.png) 47 | 48 | ### 配置RT-Thread工程 49 | - 在RT-Thread Settings中使能消息队列 50 | - 如果 **不使用控制台串口** ,在RT-Thread Settings中禁止“为rt_kprintf使用控制台”。 51 | - 如果 **使用RTT完整版** ,在RT-Thread Settings中添加plccore软件包,并使能HWTIMER设备驱动程序。 52 | 53 | ### 使用Stm32CubeMX生成目标板配置工程 54 | 55 | > ***不要与BSP工程放在同一目录下!*** 56 | > ***需要检查STM32CubeMX使用的固件库与RTT使用的版本是否一致*** 57 | 58 | - 配置RCC时钟 59 | - 配置与上位机通信的专属串口(如果使用控制台串口,必须不同!) 60 | 波特率115200、8位数据位、1位停止位、无校验 61 | 启动对应串口全局中断,设置中断优先级。 62 | - 配置PLC专属硬件定时器 63 | 分频后时钟为1MHz,定时值1000,即1ms中断一次。 64 | 启动对应定时器全局中断,设置中断优先级。 65 | - 配置管脚属性(翻转速率、上下拉等) 66 | - 运行开关 67 | - 运行指示灯 68 | - 停止指示灯 69 | - 错误指示灯 70 | - 本地输入、输出管脚等 71 | - 保存工程并生成代码 72 | 73 | ### 复制stm32f1xx_hal_conf.h文件 74 | 75 | 从Stm32CubeMX生成工程的inc目录下复制stm32f1xx_hal_conf.h文件至BSP工程drivers目录 76 | 77 | ### 复制stm32f1xx_hal_msp.c文件 78 | 79 | 从Stm32CubeMX生成工程的src目录下复制stm32f1xx_hal_msp.c文件至BSP工程drivers目录 80 | 81 | ### 修改stm32f1xx_hal_msp.c包含的头文件 82 | 83 | 将 84 | ``` 85 | #include "main.h" 86 | ``` 87 | 修改为: 88 | ``` 89 | #include "board.h" 90 | ``` 91 | 92 | ### 修改stm32f1xx_hal_msp.c中的HAL_UART_MspInit()函数 93 | 94 | > ***注意:本步骤只适用于nano版本的移植*** 95 | > ***如果使用控制台串口,需要执行本步骤,否则跳过。*** 96 | 97 | 因为drv_usart.c中已经实现了HAL_UART_MspInit(),不能重复定义,所以需要将stm32f1xx_hal_msp.c文件中的 98 | ``` 99 | void HAL_UART_MspInit(UART_HandleTypeDef* huart) 100 | ``` 101 | 修改为 102 | ``` 103 | void HAL_UART_MspInitEx(UART_HandleTypeDef* huart) 104 | ``` 105 | 106 | ### 修改drv_usart.c 107 | 108 | > ***注意:本步骤只适用于nano版本的移植*** 109 | > ***如果使用控制台串口,需要执行本步骤,否则跳过。*** 110 | 111 | RTT Studio为nano生成的drv_usart.c文件的实现有点问题,需要修改后才能支持多个串口设备。 112 | 113 | 将 114 | ``` 115 | void HAL_UART_MspInit(UART_HandleTypeDef *huart) 116 | ``` 117 | 移至 118 | ``` 119 | #endif /* RT_USING_CONSOLONE */ 120 | ``` 121 | 行之后,并修改成如下: 122 | 123 | ``` 124 | #endif /* RT_USING_CONSLONE */ 125 | 126 | void HAL_UART_MspInit(UART_HandleTypeDef *huart) 127 | { 128 | #ifdef RT_USING_CONSOLE 129 | /* if this uart is shell function */ 130 | if(huart == &handle) 131 | { 132 | stm32_gpio_configure(_uart_config); 133 | return; 134 | } 135 | #endif 136 | extern void HAL_UART_MspInitEx(UART_HandleTypeDef *huart); 137 | HAL_UART_MspInitEx(huart); 138 | } 139 | ``` 140 | ### 修改board.h 141 | 142 | > ***注意:本步骤只适用于RTT完整版本的移植*** 143 | 144 | 使能PLC专用串口及相关管脚配置,例如使用USART1作为PLC专用串口: 145 | ``` 146 | #define BSP_USING_UART1 147 | #if defined(BSP_USING_UART1) 148 | #define UART1_TX_PORT GPIOA 149 | #define UART1_RX_PORT GPIOA 150 | #define UART1_TX_PIN GPIO_PIN_9 151 | #define UART1_RX_PIN GPIO_PIN_10 152 | #endif 153 | ``` 154 | 使能PLC专用硬件定时器,例如使用TIM3作为PLC专用硬件定时器: 155 | ``` 156 | #define BSP_USING_TIM 157 | #ifdef BSP_USING_TIM 158 | #define BSP_USING_TIM3 159 | #endif 160 | ``` 161 | 162 | ### 修改board.c中的时钟配置函数 163 | 164 | RT-Thread Studio生成的工程默认使用HSI时钟,实际如果使用了HSE、LSE时钟,应该修改时钟配置,可以在CubeMX中配置好后,将生成的main.c中的SystemClock_Config()函数覆盖board.c中的SystemClock_Config()函数。 165 | ``` 166 | /** 167 | * @brief System Clock Configuration 168 | * @retval None 169 | */ 170 | void SystemClock_Config(void) 171 | { 172 | RCC_OscInitTypeDef RCC_OscInitStruct = {0}; 173 | RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; 174 | 175 | /** Initializes the CPU, AHB and APB busses clocks 176 | */ 177 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; 178 | RCC_OscInitStruct.HSEState = RCC_HSE_ON; 179 | RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1; 180 | RCC_OscInitStruct.HSIState = RCC_HSI_ON; 181 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; 182 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; 183 | RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9; 184 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) 185 | { 186 | Error_Handler(); 187 | } 188 | /** Initializes the CPU, AHB and APB busses clocks 189 | */ 190 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK 191 | |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; 192 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; 193 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; 194 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; 195 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; 196 | 197 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) 198 | { 199 | Error_Handler(); 200 | } 201 | } 202 | ``` 203 | ### 在board.c中增加中断向量表配置函数 204 | 205 | > ***注意:如果想使用IAP程序通过串口下载程序至目标机,需要执行此步。如果使用JLINK、ST-Link下载程序,跳过此步。*** 206 | 207 | ``` 208 | #define VECT_TAB_OFFSET 0x00006000U /*!< Vector Table base offset field. 209 | This value must be a multiple of 0x200. */ 210 | void VectorTable_Config(void) 211 | { 212 | #ifdef VECT_TAB_SRAM 213 | SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM. */ 214 | #else 215 | SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH. */ 216 | #endif 217 | } 218 | ``` 219 | 220 | ### 修改drv_common.c 221 | 222 | > ***注意:如果想使用IAP程序通过串口下载程序至目标机,需要执行此步。如果使用JLINK、ST-Link下载程序,跳过此步。*** 223 | 224 | 在函数rt_hw_board_init()中调用SystemClock_Config()之后增加下述代码: 225 | ``` 226 | extern void VectorTable_Config(void); 227 | VectorTable_Config(); 228 | ``` 229 | 即: 230 | ``` 231 | ... 232 | /* enable interrupt */ 233 | __set_PRIMASK(0); 234 | /* System clock initialization */ 235 | SystemClock_Config(); 236 | 237 | /* NVIC Vector table config */ 238 | extern void VectorTable_Config(void); 239 | VectorTable_Config(); 240 | 241 | /* disbale interrupt */ 242 | __set_PRIMASK(1); 243 | ... 244 | ``` 245 | 246 | ### 修改link.lds 247 | 248 | > ***注意:如果想使用IAP程序通过串口下载程序至目标机,需要执行此步。如果使用JLINK、ST-Link下载程序,跳过此步。*** 249 | 250 | ROM 的ORIGIN由0x8000000修改为0x8006000。LENGTH根据MCU实际ROM大小填写。 251 | 252 | ``` 253 | /* Program Entry, set to mark it as "used" and avoid gc */ 254 | MEMORY 255 | { 256 | ROM (rx) : ORIGIN = 0x8006000, LENGTH = 232K /* 232K flash */ 257 | RAM (rw) : ORIGIN = 0x20000000, LENGTH = 48k /* 48K sram */ 258 | } 259 | ``` 260 | 261 | --- 262 | ## 4. 复制并修改plccore代码 263 | 264 | ### 将plccore文件夹复制至RTT Studio工程目录下 265 | 266 | ### 修改plccore/port/plc_port.h各选项配置 267 | 268 | 根据目标板及实际需求进行配置: 269 | - 配置PLC专用串口设备名称(仅用于完整版移植) 270 | - 配置PLC专用定时器设备名称(仅用于完整版移植) 271 | - 配置输入管脚 272 | - 配置输出管脚 273 | - 配置I映像区大小 274 | - 配置Q映像区大小 275 | - 配置M映像区大小 276 | - 配置支持的数据类型 277 | - ... 278 | 279 | 例如: 280 | ``` 281 | /** 282 | * @file plc_port.h 283 | * @brief 资源处理器接口相关选项设置,制造商通过修改本文件对自己的处理器进行裁剪定制。 284 | * @author hyafz 285 | */ 286 | 287 | #ifndef PLC_PORT_H 288 | #define PLC_PORT_H 289 | 290 | #include 291 | #ifdef RT_USING_DEVICE 292 | #define PLC_UART_NAME "uart1" /* 串口设备名称 */ 293 | #define PLC_HWTIMER_DEV_NAME "timer3" /* 定时器设备名称 */ 294 | #endif 295 | 296 | /* 输入-输出管脚相关宏定义 */ 297 | /* 输入设备 */ 298 | #define RUN_SW_PIN GET_PIN(A, 0) 299 | #define IX0_PIN GET_PIN(B, 0) 300 | #define IX1_PIN GET_PIN(A, 7) 301 | #define IX2_PIN GET_PIN(A, 6) 302 | #define IX3_PIN GET_PIN(A, 5) 303 | #define IX4_PIN GET_PIN(A, 4) 304 | #define IX5_PIN GET_PIN(A, 3) 305 | #define IX6_PIN GET_PIN(A, 2) 306 | #define IX7_PIN GET_PIN(A, 1) 307 | 308 | #define DI_INIT_INFO \ 309 | { /* pin, default_state, prev_input_state, state, state_debounce_time, state_stay_time*/ \ 310 | { RUN_SW_PIN, 1, 1, 1, 0, 0}, /* RUN Switch */ \ 311 | { IX0_PIN, 1, 1, 1, 0, 0}, /* IX0_PIN */ \ 312 | { IX1_PIN, 1, 1, 1, 0, 0}, /* IX1_PIN */ \ 313 | { IX2_PIN, 1, 1, 1, 0, 0}, /* IX2_PIN */ \ 314 | { IX3_PIN, 1, 1, 1, 0, 0}, /* IX3_PIN */ \ 315 | { IX4_PIN, 1, 1, 1, 0, 0}, /* IX4_PIN */ \ 316 | { IX5_PIN, 1, 1, 1, 0, 0}, /* IX5_PIN */ \ 317 | { IX6_PIN, 1, 1, 1, 0, 0}, /* IX6_PIN */ \ 318 | { IX7_PIN, 1, 1, 1, 0, 0}, /* IX7_PIN */ \ 319 | } 320 | 321 | /* 输出设备 */ 322 | #define LED_RUN_PIN GET_PIN(C, 15) 323 | #define LED_STOP_PIN GET_PIN(C, 14) 324 | #define LED_ERR_PIN GET_PIN(C, 13) 325 | #define QX0_PIN GET_PIN(A, 15) 326 | #define QX1_PIN GET_PIN(B, 3) 327 | #define QX2_PIN GET_PIN(B, 4) 328 | #define QX3_PIN GET_PIN(B, 5) 329 | #define QX4_PIN GET_PIN(B, 6) 330 | #define QX5_PIN GET_PIN(B, 7) 331 | #define DO_INIT_INFO \ 332 | { /* pin, off_value, on_value, out_value */ \ 333 | { LED_RUN_PIN, 0 , 1 , 0 }, /* LED RUN */ \ 334 | { LED_STOP_PIN, 0 , 1 , 0 }, /* LED STOP */ \ 335 | { LED_ERR_PIN, 0 , 1 , 0 }, /* LED ERR */ \ 336 | { QX0_PIN, 0 , 1 , 0 }, /* QX0 */ \ 337 | { QX1_PIN, 0 , 1 , 0 }, /* QX1 */ \ 338 | { QX2_PIN, 0 , 1 , 0 }, /* QX2 */ \ 339 | { QX3_PIN, 0 , 1 , 0 }, /* QX3 */ \ 340 | { QX4_PIN, 0 , 1 , 0 }, /* QX4 */ \ 341 | { QX5_PIN, 0 , 1 , 0 }, /* QX5 */ \ 342 | } 343 | 344 | #define MAX_I_RANGE 256 /**< 输入映像区字节数 */ 345 | #define MAX_Q_RANGE 256 /**< 输出映像区字节数 */ 346 | #define MAX_M_RANGE 256 /**< 内存映像区字节数 */ 347 | 348 | #define LOC_DI_NUM 8 /**< 本地8点数字量输入 */ 349 | #define LOC_DQ_NUM 6 /**< 本地6点数字量输出 */ 350 | 351 | #define LOC_AI_NUM 1 352 | #define LOC_AQ_NUM 1 353 | 354 | /** 355 | * @brief 支持的数据类型使能选项 356 |
357 |   下列基本数据类型可以配置是否支持,其它基本数据类型默认支持。
358 | 	LINT
359 | 	ULINT
360 | 	REAL
361 | 	LREAL
362 | 	LWORD
363 | 	STRING
364 | 	WSTRING
365 | 	TIME
366 | 	DATE
367 | 	TOD
368 | 	DT
369 |   导出数据类型可以配置是否支持
370 |   
371 | */ 372 | #define DT_REAL_EN 1 373 | 374 | #define DT_64BIT_EN 0 /**< 支持64位长度数据类型的选项(0: 不支持, 1: 支持) */ 375 | #if (DT_64BIT_EN > 0) 376 | #define DT_LINT_EN 0 377 | #define DT_ULINT_EN 0 378 | #define DT_LREAL_EN 0 379 | #define DT_LWORD_EN 0 380 | #endif 381 | 382 | #define DT_STRING_EN 0 383 | #define DT_WSTRING_EN 0 384 | #define DT_TIME_EN 1 385 | #define DT_DATE_EN 0 386 | #define DT_TOD_EN 0 387 | #define DT_DT_EN 0 388 | 389 | #define DT_DVD_EN 0 /**< 支持导出数据类型的选项(0: 不支持, 1: 支持) ,目前必须为0*/ 390 | 391 | /*与配置相关的选项*/ 392 | 393 | /*与资源相关的选项*/ 394 | #define MAX_TASK_NUM_PER_RSC 4 /**< 每个资源中允许的最大任务数目*/ 395 | #define PLC_TASK_RUN_TASK_STK_SIZE 512 396 | #define PLC_TASK_HIGHEST_PRIORITY 2 397 | #define PLC_TASK_LOWEST_PRIORITY 30 398 | /*与POU相关的选项*/ 399 | 400 | /* 与数据类型相关的选项 */ 401 | 402 | /* 与编程语言相关的选项 */ 403 | 404 | /* 与IL语言相关的选项 */ 405 | 406 | /* 与LD语言相关的选项 */ 407 | 408 | /* 其它选项 */ 409 | 410 | #endif /* PLC_PORT_H */ 411 | 412 | ``` 413 | 414 | ### 修改plccore/port/plc_port.c文件 415 | > ***本文件基本上都是nano版本移植才需要修改*** 416 | 417 | 从Stm32CubeMX生成工程的src目录下的main.c文件中复制片上外设配置函数至plc_port.c,并实现各硬件相关的函数接口。例如: 418 | ``` 419 | /** 420 | * @file plc_port.c 421 | * @brief PLC处理器接口相关的实现 422 | * @author hyafz 423 | */ 424 | #include "board.h" 425 | #include "plc_port.h" 426 | 427 | #ifndef RT_USING_DEVICE 428 | #include "plc_comm.h" 429 | #include "plc_timer.h" 430 | #include "plc_io.h" 431 | 432 | TIM_HandleTypeDef htim3; 433 | UART_HandleTypeDef huart1; 434 | 435 | /** 436 | * @brief TIM3 Initialization Function 437 | * @param None 438 | * @retval None 439 | */ 440 | static void MX_TIM3_Init(void) 441 | { 442 | 443 | /* USER CODE BEGIN TIM3_Init 0 */ 444 | 445 | /* USER CODE END TIM3_Init 0 */ 446 | 447 | TIM_ClockConfigTypeDef sClockSourceConfig = {0}; 448 | TIM_MasterConfigTypeDef sMasterConfig = {0}; 449 | 450 | /* USER CODE BEGIN TIM3_Init 1 */ 451 | 452 | /* USER CODE END TIM3_Init 1 */ 453 | htim3.Instance = TIM3; 454 | htim3.Init.Prescaler = 83; 455 | htim3.Init.CounterMode = TIM_COUNTERMODE_UP; 456 | htim3.Init.Period = 1000; 457 | htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; 458 | htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; 459 | if (HAL_TIM_Base_Init(&htim3) != HAL_OK) 460 | { 461 | Error_Handler(); 462 | } 463 | sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; 464 | if (HAL_TIM_ConfigClockSource(&htim3, &sClockSourceConfig) != HAL_OK) 465 | { 466 | Error_Handler(); 467 | } 468 | sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; 469 | sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; 470 | if (HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig) != HAL_OK) 471 | { 472 | Error_Handler(); 473 | } 474 | /* USER CODE BEGIN TIM3_Init 2 */ 475 | 476 | /* USER CODE END TIM3_Init 2 */ 477 | 478 | } 479 | 480 | /** 481 | * @brief USART1 Initialization Function 482 | * @param None 483 | * @retval None 484 | */ 485 | static void MX_USART1_UART_Init(void) 486 | { 487 | 488 | /* USER CODE BEGIN USART1_Init 0 */ 489 | 490 | /* USER CODE END USART1_Init 0 */ 491 | 492 | /* USER CODE BEGIN USART1_Init 1 */ 493 | 494 | /* USER CODE END USART1_Init 1 */ 495 | huart1.Instance = USART1; 496 | huart1.Init.BaudRate = 115200; 497 | huart1.Init.WordLength = UART_WORDLENGTH_8B; 498 | huart1.Init.StopBits = UART_STOPBITS_1; 499 | huart1.Init.Parity = UART_PARITY_NONE; 500 | huart1.Init.Mode = UART_MODE_TX_RX; 501 | huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; 502 | huart1.Init.OverSampling = UART_OVERSAMPLING_16; 503 | if (HAL_UART_Init(&huart1) != HAL_OK) 504 | { 505 | Error_Handler(); 506 | } 507 | /* USER CODE BEGIN USART1_Init 2 */ 508 | 509 | /* USER CODE END USART1_Init 2 */ 510 | 511 | } 512 | 513 | /** 514 | * @brief GPIO Initialization Function 515 | * @param None 516 | * @retval None 517 | */ 518 | static void MX_GPIO_Init(void) 519 | { 520 | GPIO_InitTypeDef GPIO_InitStruct = {0}; 521 | 522 | /* GPIO Ports Clock Enable */ 523 | __HAL_RCC_GPIOC_CLK_ENABLE(); 524 | __HAL_RCC_GPIOH_CLK_ENABLE(); 525 | __HAL_RCC_GPIOA_CLK_ENABLE(); 526 | __HAL_RCC_GPIOB_CLK_ENABLE(); 527 | 528 | /*Configure GPIO pin Output Level */ 529 | HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15, GPIO_PIN_RESET); 530 | 531 | /*Configure GPIO pin Output Level */ 532 | HAL_GPIO_WritePin(GPIOA, GPIO_PIN_15, GPIO_PIN_RESET); 533 | 534 | /*Configure GPIO pin Output Level */ 535 | HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6 536 | |GPIO_PIN_7, GPIO_PIN_RESET); 537 | 538 | /*Configure GPIO pins : PC13 PC14 PC15 */ 539 | GPIO_InitStruct.Pin = GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15; 540 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; 541 | GPIO_InitStruct.Pull = GPIO_NOPULL; 542 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; 543 | HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); 544 | 545 | /*Configure GPIO pins : PA0 PA1 PA2 PA3 546 | PA4 PA5 PA6 PA7 */ 547 | GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3 548 | |GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7; 549 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT; 550 | GPIO_InitStruct.Pull = GPIO_NOPULL; 551 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 552 | 553 | /*Configure GPIO pin : PB0 */ 554 | GPIO_InitStruct.Pin = GPIO_PIN_0; 555 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT; 556 | GPIO_InitStruct.Pull = GPIO_NOPULL; 557 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); 558 | 559 | /*Configure GPIO pin : PA15 */ 560 | GPIO_InitStruct.Pin = GPIO_PIN_15; 561 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; 562 | GPIO_InitStruct.Pull = GPIO_NOPULL; 563 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; 564 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); 565 | 566 | /*Configure GPIO pins : PB3 PB4 PB5 PB6 567 | PB7 */ 568 | GPIO_InitStruct.Pin = GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6 569 | |GPIO_PIN_7; 570 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; 571 | GPIO_InitStruct.Pull = GPIO_NOPULL; 572 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; 573 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); 574 | 575 | } 576 | 577 | /** 578 | * @brief This function handles USART1 global interrupt. 579 | */ 580 | void USART1_IRQHandler(void) 581 | { 582 | /* USER CODE BEGIN USART1_IRQn 0 */ 583 | uint16_t rxCnt = huart1.RxXferCount; 584 | /* USER CODE END USART1_IRQn 0 */ 585 | HAL_UART_IRQHandler(&huart1); 586 | /* USER CODE BEGIN USART1_IRQn 1 */ 587 | if(rxCnt != huart1.RxXferCount){ 588 | plcCommDataReceived(); 589 | } 590 | /* USER CODE END USART1_IRQn 1 */ 591 | } 592 | 593 | /** 594 | * @brief Period elapsed callback in non-blocking mode 595 | * @param htim TIM handle 596 | * @retval None 597 | */ 598 | void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) 599 | { 600 | if(htim == &htim3){ 601 | plcTimeoutCallback(); 602 | } 603 | } 604 | 605 | /** 606 | * @brief This function handles TIM2 global interrupt. 607 | */ 608 | void TIM3_IRQHandler(void) 609 | { 610 | /* USER CODE BEGIN TIM2_IRQn 0 */ 611 | 612 | /* USER CODE END TIM2_IRQn 0 */ 613 | HAL_TIM_IRQHandler(&htim3); 614 | /* USER CODE BEGIN TIM2_IRQn 1 */ 615 | 616 | /* USER CODE END TIM2_IRQn 1 */ 617 | } 618 | 619 | void devCommInit(void) 620 | { 621 | MX_USART1_UART_Init(); 622 | } 623 | 624 | void devCommRxStart(void) 625 | { 626 | HAL_UART_AbortReceive_IT(&huart1); 627 | CommRxCnt = 0; 628 | HAL_UART_Receive_IT(&huart1, CommRxBuf, RX_DATA_BUF_SIZE); 629 | } 630 | 631 | void devCommSend(unsigned char* pbuf, unsigned int size) 632 | { 633 | HAL_UART_Transmit(&huart1, pbuf, size, 100); 634 | } 635 | 636 | void devTimerInit(void) 637 | { 638 | MX_TIM3_Init(); 639 | } 640 | 641 | void devTimerStart(void) 642 | { 643 | __HAL_TIM_SET_COUNTER(&htim3, 0); 644 | HAL_TIM_Base_Start_IT(&htim3); 645 | } 646 | 647 | void devTimerStop(void) 648 | { 649 | HAL_TIM_Base_Stop_IT(&htim3); 650 | } 651 | 652 | unsigned int devTimerCountGet(void) 653 | { 654 | return __HAL_TIM_GET_COUNTER(&htim3); 655 | } 656 | 657 | void devIOInit(void) 658 | { 659 | MX_GPIO_Init(); 660 | } 661 | 662 | #define GPIO_PORT(pin) ((GPIO_TypeDef *) (GPIOA_BASE + ((pin) / 16) * 0x0400UL)) 663 | #define GPIO_PIN(pin) ((uint16_t)(0x0001 << ((pin) % 16))) 664 | unsigned char devInputPinRead(unsigned int pin) 665 | { 666 | return (unsigned char)HAL_GPIO_ReadPin(GPIO_PORT(pin), GPIO_PIN(pin)); 667 | } 668 | 669 | void devOutputPinWrite(unsigned int pin, unsigned int val) 670 | { 671 | HAL_GPIO_WritePin(GPIO_PORT(pin), GPIO_PIN(pin), val); 672 | } 673 | 674 | #endif 675 | 676 | void iapModeEnter(void) 677 | { 678 | HAL_NVIC_SystemReset(); //复位则返回IAP程序入口 679 | } 680 | 681 | ``` 682 | 683 | ### 修改main.c文件 684 | 685 | 在main函数中添加如下代码: 686 | ```c 687 | int main(void) 688 | { 689 | extern void plcMain(void); 690 | plcMain(); 691 | 692 | while (1) 693 | { 694 | rt_thread_mdelay(1000); 695 | } 696 | 697 | return RT_EOK; 698 | } 699 | 700 | ``` 701 | 702 | ### 从examples/目录下剪切plcapp文件夹,粘贴到RT-Thread Studio工程目录下 703 | > 注意是剪切! 704 | 705 | plcapp存放了PLC集成开发环境软件根据用户逻辑程序(梯形图、指令表)生成的C语言代码文件,将其复制至RT-Thread Studio工程目录然后在RT-Thread Studio界面刷新项目树。 706 | 707 | ### 设置包含路径 708 | 709 | 在RT-Thread Studio主菜单“项目”->“属性”->“C/C++常规”->“路径和符号”中添加plccore、plctapp的包含路径。 710 | 711 | ### 修改目标文件名 712 | 713 | 在RT-Thread Studio主菜单“项目”->“属性”->“C/C++构建”->“设置”->“构建工件”->“Artifact name:”中写入新的名字。 714 | 715 | ### 编译RT-Thread Studio工程 716 | 717 | 编译成功则移植完成。 718 | 719 | --- 720 | ## 5. 与PLC IDE结合使用 721 | PLC IDE分为社区版与标准版,目前仅提供社区版免费使用,标准版正在开发中。 722 | - 社区版 723 | - 在PLC IDE中,用户可以建立PLC应用工程,使用PLC编程语言,比如指令表、梯形图等实现用户逻辑,然后生成C语言源代码文件,保存在工程目录的plctoc_output子目录中。 724 | - 将plctoc_output目录中的所有.c/.h文件复制至RTT移植工程的plcapp目录下,注意只复制文件,不复制目录结构。 725 | - 刷新RTT移植工程,然后编译生成目标代码,下载至目标板,即可实现用户逻辑控制。 726 | 727 | - 标准版 728 | - 移植完成后,将RT-Thread Studio工程文件夹整体复制至PLC IDE执行目录下的processors目录中,这样就可以作为一种新的PLC处理器使用。 729 | - 在PLC IDE中,用户可以建立PLC应用工程,使用PLC编程语言,比如指令表、梯形图等实现用户逻辑,然后直接编译、连接,再下载至目标板,即可实现逻辑控制。 730 | 731 | ### 关于PLC IDE 732 | 733 | PLC IDE是一款可编程控制器的集成开发环境,实现了符合IEC61131-3标准的软件模型和编程模型,编程简单、配置灵活、系统扩展性好。支持标准的指令表(IL)、结构化文本(ST)、梯形图(LD)等PLC编程语言,能够将PLC用户逻辑代码编译为目标硬件的二进制目标代码,实现编译型PLC。相比于传统的解释型PLC,指令执行效率更高,存储密度更高,且具有更高的可靠性。 734 | 735 | --- 736 | ## 结束 -------------------------------------------------------------------------------- /docs/IEC61131-3标准PLC编程参考手册.md: -------------------------------------------------------------------------------- 1 | IEC61131-3标准可编程逻辑控制器编程参考手册 2 | ======================================== 3 | 4 | # 修订历史 5 | 6 | 版本 | 日期 | 修订人 | 审核人 | 描述 7 | :-: | :-: | :-: | :-: | :- 8 | V0.1 | 2020.2.21 | 冯洲 | 冯洲 | 初次创建,部分功能还未实现,以实际为准。 9 |   10 | # 前言 11 | 本编程参考手册归纳总结了《中华人民共和国国家标准GB/T 15969.3——2005/IEC 61131-3:2002 可编程序控制器 第3部分:编程语言》的各项规定、要求与限制,使用户能准确把握标准的精髓,快速上手,完成PLC应用程序编写与系统组态。 12 | GB/T 15969.3标准等同翻译IEC 61131-3标准,下文统一称为IEC 61131-3标准,或简称为标准。 13 |   14 | #1 软件模型 15 | IEC 61131-3标准的软件模型用分层结构表示,每一层隐含其下层的许多特性,从而构成优于传统可编程控制器软件的理论基础。软件模型描述基本的高级软件元素及其相互关系,是现代PLC的软件基础。这些元素包括: 16 | - 程序组织单元,即程序、功能块和功能 17 | - 组态元素,即配置、资源、任务、全局变量和存取路径 18 | 19 | IEC61131-3标准的软件模型如图所示: 20 | ![软件模型](images/software_model.png) 21 | IEC 61131-3标准软件模型从理论上描述了如何将一个复杂程序分解为若干小的可管理部分,并在各分解部分之间有清晰和规范的接口方法。另外,软件模型还描述一台可编程控制器如何实现多个独立程序的同时装载和运行,如何实现对程序执行的完全控制等。 22 | 以下各节将按从上至下的顺序依次介绍软件模型中不同层级的元素的定义及作用。 23 | ##1.1 配置 24 | 配置(Configuration)位于软件模型的最上层,是可编程控制器系统的整个软件,用于定义特定应用的PLC系统的特性。对于大型复杂的应用,如整个产品线的自动化,可能需要几个PLC相互作用,一个配置可以与其它IEC配置通过通信接口实现通信。在这种情况下,每个PLC的软件可作为一个分离的配置。因此,可将配置认为是一个特定类型的控制系统,它包括硬件装置、处理资源、I/O通道的存储地址和系统能力,即等同于一个PLC的应用程序。 25 | 配置用关键字CONFIGURATION开始,随后是配置名称和配置声明,最后用关键字END_CONFIGURATION结束。配置声明包括定义该配置的有关类型和全局变量的声明、在配置内资源的声明、存取路径变量的声明和实例专用初始化变量声明等。 26 | 在PLC集成开发环境中,配置采用一个专门的页面进行管理,不需要手写代码,这种方式更直观,也更方便。下图为配置管理页面: 27 | ![配置管理页面](images/configuration_page.png) 28 | 在PLC系统中,配置将系统内的所有资源结合成组,在一个配置中,可定义在该PLC项目中全局有效使用的全局变量,作为资源之间数据交换的手段。 29 | 30 | ##1.2 资源 31 | 资源(Resource)位于软件模型的第二层,它为运行程序提供支持系统,是能执行IEC程序的处理手段。资源反映了可编程控制器的物理结构,为程序和PLC的物理输入输出通道提供了一个接口。 32 | 每个配置内可有一个或多个资源。资源提供对所有程序执行所需特性的支持。 33 | 一个程序只有在资源中实例化才能运行。资源的主要功能之一是提供程序和PLC物理I/O通道之间的界面。 34 | 每个资源可支持多于一个的程序。因此,资源使PLC能够加载、启动和执行许多总体独立的程序。 35 | 资源有资源名称,它被分配在一个PLC的CPU中。因此,可将资源理解为一个PLC中的微处理器单元。资源内定义的全局变量在该资源内部是有效的。资源可调用具有输入输出参数的运行期程序,给一个资源分配任务和程序,并声明直接表示变量。 36 | 资源用关键字RESOURCE开始,随后是资源名称和ON关键字、资源类型名和资源声明,最后用END_RESOURCE关键字结束。 37 | 资源名是一个符号名,它用于说明可编程控制器系统中的一个处理器。编程系统提供可编程控制器系统内该资源(即每个CPU的命名)的类型和数量,并检验这些资源类型和数量,使系统能够正确地使用这些资源。 38 | 资源声明包括在该资源内的全局变量、任务和程序声明等内容。在资源声明段中,ON关键字指定特定的处理器类型,每种处理器具有限定的“信号处理功能”、“人机接口”和“传感器和执行机构接口”。 39 | 在PLC集成开发环境中,资源采用一个专门的页面进行管理,如下图所示: 40 | ![资源管理页面](images/resource_page.png) 41 | 42 | ##1.3 任务 43 | 任务(Task)位于软件模型分层结构的第3层。任务用于规定程序组织单元(POU)在运行期的特性。任务是一个执行控制元素,它具有调用能力。 44 | 一个资源中可以有多个用户任务。一旦任务被设置,它就可控制一系列程序组织单元周期地执行,或者根据一个特定的事件触发来执行。 45 | 每个资源都有一个最低优先级(比所有声明的用户任务更低)的默认任务,不需要用户声明。如果声明的程序实例没有与任何任务结合,则自动与默认任务结合。 46 | 任务由关键字TASK开始,随后是任务名、任务初始化设置(用圆括号将任务的有关参数分列其中)。 47 | ###1.3.1 任务初始化设置 48 | 任务初始化设置有三个参数: 49 | - SIGNAL:触发任务执行的事件输入端,在该事件触发信号的上升沿,触发任务执行一次; 50 | - INTERVAL:任务周期执行的时间间隔。当其值不为零,且SIGNAL信号保持为0,则表示该任务被周期执行; 51 | - PRIORITY:任务优先级,0表示最高优先级,优先级越低,数值越高。 52 | 53 | 例如: 54 | ``` 55 | TASK slow_1 (INTERVAL := T#20ms, PRIORITY := 2); 56 | ``` 57 | 表示任务名为slow_1的任务是周期执行的任务,周期间隔时间20ms,优先级为2。 58 | 在资源管理页面使用表格化方式对任务进行设置,上述slow_1任务表示如下: 59 | ![任务示例](images/task_example.png) 60 | 61 | ###1.3.2 任务执行准则 62 | - 单任务输入SIGNAL不为零,表示该任务在SIGNAL上升沿时触发执行一次,是事件触发的单任务; 63 | - 当INTERVAL不为零,SIGNAL保持为零,则该任务周期执行,执行周期由INTERVAL数据确定; 64 | - 当多个任务执行时,立即中断正在执行的任务,使优先级高的任务先被执行; 65 | - 如果多个任务的优先级相同,则按时间片轮转执行; 66 | - 没有与任何任务结合的程序实例,默认结合至默认的最低优先级任务,在资源开始运行时立即开始执行,且执行完毕后立即重新启动。 67 | 68 | ##1.4 程序实例 69 | 一个程序只有在资源内部实例化后才能被调用。 70 | 程序实例化以PROGRAM关键字开始,随后是程序名,如果程序实例与特定任务结合,使用WITH关键字声明,最后是程序实例名及程序接口。例如: 71 | ``` 72 | PROGRAM P1 WITH slow_1 : F(x1 := %IX1.1); 73 | ``` 74 | 其中,P1是程序名,与slow_1任务结合,程序实例名为F,程序接口为实例传递实参数据。 75 | 在资源管理页面使用表格化方式对程序实例进行设置,上述程序实例F表示如下: 76 | ![程序实例示例](images/program_instance_example.png) 77 | 78 | ##1.5 全局变量 79 | 标准允许变量在不同的软件元素中被声明。变量的范围确定其在哪个程序组织单元中是可用的。范围可能是局部的或全局的。每个变量的范围由它被声明的位置和声明所使用的关键字所定义。 80 | 在配置中声明的全局变量可在整个配置范围内使用,在资源中声明的全局变量只能在该资源范围内使用。全局变量的声明格式如下: 81 | ``` 82 | VAR_GLOBAL 83 | 全局变量说明 84 | END_VAR 85 | ``` 86 | 87 | 全局变量能与其它网络进行数据交换。一个系统中不能有相同名称的两个全局变量。在每个使用全局变量的程序组织单元中,需要用VAR_EXTERNAL关键字来声明它。全局变量提供了在两个不同程序和功能块之间非常灵活的交换数据的方法。 88 | ##1.6 存取路径 89 | 存取路径用于将全局变量、直接表示变量和功能块的输入、输出和内部变量联系起来,实现信息的存取。它提供在不同配置之间交换数据和信息的方法。每一配置内的许多指定名称的变量可通过其他远程配置来存取。 90 | 有两种存取方法:读写方法和只读方法。读写(READ_WRITE)方式表示通信服务能够改变变量的值;只读(READ_ONLY)方式表示能够读取变量的值但不能改变变量的值。当不规定存取路径方法时,约定的存取方式是只读方式。 91 | 存取路径变量声明的方法: 92 | ``` 93 | VAR_ACCESS 94 | 存取路径名:外部存取路径:存取路径变量的数据类型和读写属性 95 | END_VAR 96 | ``` 97 | 外部存取路径采用串联方式表示。开始是资源名,然后是程序实例名,功能块实例名,最后是变量名。各名称之间用圆点分隔,中间没有的名称可以省略。 98 | ##1.7 实例专用的初始化 99 | 等待补充…… 100 | ##1.8 示例 101 | 软件模型的代码示例: 102 | ![软件模型的代码示例](images/software_model_example_code.png) 103 | 对应图形示例: 104 | ![软件模型的图形示例](images/software_model_example_graph.png) 105 | #2 编程模型 106 | 标准规定的PLC编程语言元素包括: 107 | - 数据类型 108 | - 变量 109 | - 程序组织单元(功能、功能块、程序) 110 | - 顺序功能图(SFC)元素 111 | - 配置元素(全局变量、资源、存取路径、任务) 112 | 113 | 这些语言元素的组合应遵守以下规则: 114 | - 导出数据类型应使用标准数据类型和先前导出的任何数据类型进行说明。 115 | - 导出功能使用标准或导出数据类型、标准功能和先前导出的任何功能进行说明。该说明应使用为IL、ST、LD或FBD语言定义的机制。 116 | - 导出功能块使用标准或导出数据类型和功能、标准功能块和先前导出的任何功能块进行说明。该说明应使用为IL、ST、LD或FBD语言定义的机制,并可包括顺序功能图(SFC)元素。 117 | - 程序使用标准或导出数据类型、功能和功能块进行说明。该说明应使用为IL、ST、LD或FBD语言定义的机制,并可包括顺序功能图(SFC)元素。 118 | - 使用全局变量、资源、任务和存取路径等元素,可将程序组合进配置。 119 | 120 | ![PLC语言元素的组合](images/plc_language_elements_combination.png) 121 | 122 | #3 通信模型 123 | IEC 61131-3标准定义了变量在不同层级的软件元素间通信的各种方法。 124 | ##3.1 程序内通信 125 | 在一个程序内的变量可以直接通信,只要将一个程序元素的输出连接到另一个程序元素的输入即可。如下图所示: 126 | ![程序内的数据流连接](images/data_flow_connection_whthin_a_program.png) 127 | 128 | ##3.2 通过全局变量进行通信 129 | 在同一个配置中的程序间,变量可以通过全局变量进行通信。如下图所示: 130 | ![通过全局变量通信](images/communication_via_global_variables.png) 131 | 132 | ##3.3 通过通信控制块通信 133 | 两个配置间、一个程序中不同部分之间或者PLC程序与非PLC系统之间可以使用GB/T 15969.5中定义的标准通信功能块,如下图所示: 134 | ![通信功能块](images/communication_function_blocks.png) 135 | 136 | ##3.4 通过存取路径通信 137 | 使用GB/T 15969.5定义的机制,PLC或非PLC系统可以通过存取路径传输可提供的数据。 138 | ![通过存取路径进行通信](images/communication_via_access_paths.png) 139 | 140 | #4 印刷字符的使用 141 | 根据国家标准GB/T 15969.3-2005,可编程控制器使用的文本和图形类编程语言中的文本元素应根据国家标准GB 1988字符集的“基本代码表”的3-7列的字符组成,并根据GB 2312-1980《信息交换用汉字编码字符集 基本集》来表示汉字。 142 | 支持小写字母时,字母的大小写不作区分,即control与CONTROL、Control具有相同的意义。 143 | 汉字只允许出现在注释与附注中,即不参与编写程序逻辑。 144 | ##4.1 引用字符集 145 | ![引用字符集](images/character_representations.png) 146 | 147 | ##4.2 标识符 148 | 标识符必须由字母、数字和下划线字符组成,标识符用于表示在IEC语言中的不同元素,包括变量、标号和函数、功能块、程序组织单元等名称。使用标识符的规则如下: 149 | - 标识符的第1个字符必须为字母或下划线; 150 | - 标识符中的大小写字母具有相同的意义; 151 | - 标识符中不允许有两个或两个以上连续的下划线; 152 | - 标识符的结尾不能用下划线; 153 | - 标识符至少应支持6个不同的字符,最大字符数与实现有关; 154 | 155 | ##4.3 分界符 156 | 157 | 分界符|应用场合|备注和示例 158 | :-: | :-: | :- 159 | 空格|允许在PLC程序中插入空格 160 | (* *)| 注释起始、结束符号|不允许嵌套注释 161 | { }| 附注起始、结束符号| 162 | +|十进制数字的前缀符号
加操作符号
交叉连接点|

图形编程语言中表示交叉连接点 163 | -|十进制数字的前缀符号
减操作符号
年-月-日的分隔符
水平线|


图形编程语言中表示水平连接线 164 | \#|基底数的分隔符
数据类型分隔符
时间文字的分隔符| 2#1111_1111或16#FF
SINT#234, INT#16000, BOOL#0
T#16ms, TOD#05:30:35.28 165 | .|整数与小数的分隔符
分级寻址分隔符
结构元素分隔符
功能块结构分隔符|3.14
%IW2.5.7.1
MOD_5_CONFIG.CHANNEL[5].RANGE
TMR_1.Q, SR_103.S1 166 | e或E|实指数分界符|1.0e+6, 1.2345E6 167 | ‘|单字节字符串开始与结束符号|‘hello world’ 168 | “|双字节字符串开始与结束符号|“你好,世界” 169 | \$|字符串中特殊字符的开始|‘\$L’表示换行
’\$R’表示回车
’\$P’表示换页等 170 | :|日时分隔符
类型名称/规范分隔符
变量/类型分隔符
步名称终止符
资源名称/类型分隔符
程序名称/类型分隔符
存取名称/路径/类型分隔符
指令标号终止符
网络标号终止符| 171 | :=|初始化操作符
输入连接操作符
赋值操作符| 172 | ( )|枚举表分界符
子范围分界符
多重初始化
指令表修改符、操作符
功能变元
子表达式分级
功能块输入表分界符 173 | [ ]|数组下标分界符
串长度分界符| 174 | ,|枚举表分隔符
初始值分隔符
数组下标分隔符
被说明变量分隔符
功能块初始值分隔符
功能块输入表分隔符
操作数表分隔符
功能变元表分隔符
CASE值表分隔符 175 | ;|类型说明分隔符
语句分隔符 176 | ..|子范围分隔符
CASE范围分隔符 177 | %|直接表示前缀 178 | =>|输出连接操作符 179 | \||垂直线 180 | 181 | ##4.4 关键字 182 | 表格 4 3关键字说明和示例 183 | 关键字 | 说明 | 示例 184 | :-: | :-: | :- 185 | CONFIGURATION
END_CONFIGURATION| 186 | RESOURCE
END_RESOURCE| 187 | TASK| 188 | PROGRAM
WITH| 189 | PROGRAM
END_PROGRAM| 190 | FUNCTION
END_FUNCTION| 191 | FUNCTION_BLOCK
END_FUNCTION_BLOCK| 192 | VAR
END_VAR| 193 | VAR_INPUT
END_VAR| 194 | VAR_OUTPUT
END_VAR| 195 | VAR_IN_OUT
END_VAR| 196 | VAR_GLOBAL
END_VAR| 197 | VAR_EXTERNAL
END_VAR| 198 | VAR_ACCESS
END_VAR| 199 | VAR_TEMP
END_VAR| 200 | VAR_CONFIG
END_VAR| 201 | RETAIN| 202 | NON_RETAIN| 203 | CONSTANT| 204 | ARRAY
OF| 205 | AT| 206 | EN| 207 | ENO| 208 | TRUE| 209 | FALSE| 210 | TYPE
END_TYPE| 211 | STRUCT
END_STRUCT| 212 | IF
THEN
ELSIF
ELSE
END_IF| 213 | CASE
OF
ELSE
END_CASE| 214 | REPEAT
UNTIL
END_REPEAT| 215 | WHILE
DO
END_WHILE| 216 | RETURN| 217 | OTTO| 218 | STEP
END_STEP| 219 | INITIAL_STEP
END_STEP| 220 | TRANSITION
FROM
TO
END_TRANSITION| 221 | ACTION
END_ACTION| 222 | R_EDGE| 223 | F_EDGE| 224 | READ_WRITE| 225 | READ_ONLY| 226 | BOOL
BYTE
WORD
DWORD
LWORD
SINT
INT
DINT
LINT
USINT
UINT
UDINT
ULINT
REAL
LREAL
TIME
DATE
TIME_OF_DAY/TOD
DATE_AND_TIME/DT
STRING
WSTRING|基本数据类型名称 227 | ANY
ANY_DERIVED
ANY_MAGNITUDE
ANY_NUM
ANY_INT
ANY_REAL
ANY_BIT
ANY_STRING
ANY_DATE|类属数据类型名称 228 | ||标准功能名称 229 | ||标准功能块名称 230 | LD/LDN
ST/STN
S
R
AND/ANDN
OR/ORN
XOR/XORN
NOT
ADD
SUB
MUL
DIV
MOD
GT
GE
EQ
NE
LE
LT
JMP/JMPC/JMPN
CAL/CALC/CALN
RET/RETC/RETN|指令表语言(IL)中的文本操作符 231 | ||结构化文本语言(ST)中的文本操作符 232 | 233 | ##4.5 空格的使用 234 | 空格定义为十进制数编码为32的SPACE字符以及如tab、newline等非打印字符。 235 | 标准规定在PLC文本的任何地方,应允许用户插入一个或多个空格,但在关键字、直接量、枚举值、标识符、直接表示变量,或在分界符组合内除外。 236 | 237 | ##4.6 注释 238 | 用户注释应分别在开头和结尾由特殊字符组合”(*”和”*)”来定界。在程序中允许使用空格的地方都应允许加入注释,但在字符串直接量内除外。注释没有语法或语义的意义。 239 | 不允许嵌套注释。 240 | 241 | ##4.7 附注 242 | 附注应分别在开头和结尾由花括号”{*”和”*}”来定界。在程序中允许使用空格的地方都应允许加入附注,但在字符串直接量内除外。附注没有语法或语义的意义。 243 | 不允许嵌套附注。 244 | 245 | #5 数据的外部表示 246 | 在各种PLC语言中,数据的外部表示由数字直接量、字符串和时间直接量组成。所谓直接量,即为平常所说的常量。 247 | 248 | ##5.1 数字直接量 249 | 数字直接量包括整数直接量和实数直接量,被定义为十进制数或基底数。插在数字直接量数字间的单下划线字符’_’是没有意义的,不允许有连续的两个下划线字符,且下划线不能出现在头尾。 250 | 十进制直接量以字符0~9组成的字符串表示,实数直接量以小数点的存在来区分。一个指数表示是十的整数幂乘以前面的数以获得所表示的值。十进制直接量及其指数可以包含一个前置符(+或-)。 251 | 整数直接量也可以2、8、16为基底表示。基底数就为十进制符号。对于基底是16的整数直接量,应使用由数字0~9以及字母A~F组成的一组扩展数字表示。基底数不应包含前置符(+或-)。 252 | 布尔数据应分别具有值0或1的整数直接量或关键字“FALSE”或“TRUE”来表示。 253 | 布尔或数字直接量的数据类型通过在直接量前加类型前缀来规定,该类型前缀由基本数据类型名和符号’#’组成。 254 | 数字直接量的特性和举例如下表所示: 255 | 序号|特性描述|举例 256 | :-:|:-:|:- 257 | 1|整数直接量|-12
0
123_456
+986 258 | 2|实数直接量|-12.0
0.0
0.4560
3.14159_26 259 | 3|带指数的实数直接量|-1.34E-12或-1.34e-12
1.0E+6或1.0e+6
1.234E6或1.234e6 260 | 4|基底为2的直接量|2#1111_1111(十进制255)
2#1110_0000(十进制240) 261 | 5|基底为8的直接量|8#377(十进制255)
8#340(十进制240) 262 | 6|基底为16的直接量|16#FF或16#ff(十进制255)
16#ED或16#ed(十进制240) 263 | 7|布尔0
布尔1|0
1 264 | 8|布尔FALSE
布尔TRUE|FALSE
TRUE 265 | 9|类型化的直接量|DINT#5(5的DINT表示)
UINT#16#9AF(十六进制值9AF的UINT表示)
BOOL#0
BOOL#1
BOOL#TRUE
BOOL#FALSE 266 | 267 | ##5.2 字符串直接量 268 | 字符串直接量包括单字节或双字节编码的字符串。 269 | 单字节字符串直接量以单引号’作为分界符,其中保存单字节字符。 270 | 双字节字符串直接量以双引号”作为分界符,其中保存双字节字符。 271 | ‘\$’提供字符转义操作,如下表所示: 272 | 组合|打印时的解释 273 | :-:|:- 274 | \$\$|美元符号 275 | \$’|单引号 276 | \$”|双引号 277 | \$L或\$l|换行 278 | \$N或\$n|新行 279 | \$P或\$p|换页 280 | \$R或\$r|回车 281 | \$T或\$t|制表 282 | 283 | 字符串直接量特性如下表所示。 284 | 单字节字符串示例|双字节字符串示例|说明 285 | :-:|:-:|:- 286 | ‘’|“”|长度为0的空串 287 | ‘A’|“A”|单字符A的长度为1的字符串 288 | ‘ ‘|“ “|空格字符的长度为1的字符串 289 | ‘\$’’|“’”|含单引号的长度为1的字符串 290 | ‘”’|“\$””|含双引号的长度为1的字符串 291 | ‘\$R\$L’|“\$R\$L”|含CR(回车)和LF(换行)的长度为2的字符串 292 | ‘\$\$5.00’|“\$\$5.00”|打印为\$5.00的长度为5的字符串 293 | STRING#’OK’|WSTRING#”OK”|字符为OK的长度为2的字符串 294 | ‘AE’
‘\$C4\$CB’|“AE”
“\$00C4\$00CB”|长度为2的字符串,C4和CB是字符A和E的ASCII码 295 | 296 | ##5.3 时间直接量 297 | 时间直接量用于表示时间,可以是持续的时间、一天中的时刻、日期、日期和时刻。 298 | 299 | #6 数据类型 300 | IEC61131-3标准支持的数据类型分为基本数据类型、类属数据类型和导出数据类型三类。数据类型与它在数据存储器中所占用的数据宽度有关。 301 | ##6.1 基本数据类型 302 | 数据类型|关键字|位数(N)|允许取值范围|约定初始值 303 | :-:|:-:|:-:|:-:|:-: 304 | 布尔|BOOL|1|0或1|0 305 | 8位长度的位串|BYTE|8|0 ~ 16#FF|16#00 306 | 16位长度的位串|WORD|16|0 ~ 16#FFFF|16#0000 307 | 32位长度的位串|DWORD|32|0 ~ 16#FFFF_FFFF|16#0000_0000 308 | 64位长度的位串|LWORD|64|0 ~ 16#FFFF_FFFF_FFFF_FFFF|16#0000_0000_0000_0000 309 | 短整数|SINT|8|- 2^7 ~ 2^7 - 1|0 310 | 整数|INT|16|-2^15 ~ 2^15 - 1|0 311 | 双整数|DINT|32|-2^31 ~ 2^31 – 1|0 312 | 长整数|LINT|64|-2^63 ~ 2^63 - 1|0 313 | 无符号短整数|USINT|8|0 ~ +2^8 - 1|0 314 | 无符号整数|UINT|16|0 ~ + 2^16 - 1|0 315 | 无符号双整数|UDINT|32|0 ~ +2^32 - 1|0 316 | 无符号长整数|ULINT|64|0 ~ +2^64 - 1|0 317 | 实数|REAL|32|按SJ/Z9071对单精度浮点数的取值范围|0.0 318 | 长实数|LREAL|64|按SJ/Z9071对双精度浮点数的取值范围|0.0 319 | 持续时间|T
TIME|||T#0 320 | 日期|D
DATE|||D#0001-01-01 321 | 时刻|TOD
TIME_OF_DAY|||TOD#00:00:00 322 | 日期和时刻|DT
DATE_AND_TIME|||DT#0001-01-01-00:00:00 323 | 单字节字符串|STRING |||‘’空单字节字符串 324 | 双字节字符串|WSTRING|||“”空双字节字符串 325 | 326 | ##6.2 类属数据类型 327 | 等待补充…… 328 | 329 | ##6.3 导出数据类型 330 | 等待补充…… 331 | 332 | #7 变量 333 | 与数据的外部表示(即直接量或称常量)相比,变量提供一种识别其内容可以更改的数据对象的方法,如与PLC的输入、输出或存储器相关的数据。一个变量可以被说明为基本数据类型之一或导出数据类型之一。 334 | 335 | ##7.1 变量的表示 336 | 变量分为单元素变量和多元素变量两种。 337 | 单元素变量是以下类型的变量: 338 | - 基本数据类型之一的单数据元素 339 | - 导出枚举类型或子范围类型的元素 340 | - 递归定义的导出数据类型,其“父”类型可追溯到基本类型、枚举类型或子范围类型的元素 341 | 342 | 单元素变量可以用标识符表示,或在PLC的输入、输出或存储器结构中用物理或逻辑位置直接表示,前者称为符号变量,后者称为直接表示变量。 343 | 多元素变量包括导出数据类型中的数组数据类型的变量和结构数据类型的变量。 344 | ###7.1.1 直接表示变量 345 | 直接表示变量又称直接变量,以百分数符号’%’开始,随后是位置前缀符号和大小前缀符号。如果有分级,则用无符号整数表示分级,并用小数点符号’.’分隔,最大级数由实现决定。 346 | 直接表示变量位置前缀符号的定义与特性如下表所示: 347 | 前缀符号|定义 348 | :-:|:-: 349 | I|输入单元位置 350 | Q|输出单元位置 351 | M|存储器单元位置 352 | 353 | 直接表示变量大小前缀的定义与特性如下表所示: 354 | 前缀符号|定义|默认数据类型 355 | :-:|:-:|:-: 356 | 无|单个位|BOOL 357 | X|单个位|BOOL 358 | B|8位字节|BYTE 359 | W|16位字|WORD 360 | D|32位双字|DWORD 361 | L|64位长字|LWORD 362 | *|表示还未确定位置的内部变量 363 | 364 | 直接表示变量示例: 365 | 示例|说明 366 | :-:|:- 367 | %IX1.3或%I1.3|表示输入单元1的第3位 368 | %IW4|表示输入字单元4(即输入单元8和9) 369 | %QX75和%Q75|表示输出位75 370 | %MD48|表示双字,位于存储器48 371 | %Q*|表示输出在一个未指定的位置 372 | %IW2.3.4.5|多级表示的输入,表示PLC系统第2块I/O总线的第3个机架上的第4模块的第5通道(字)输入 373 | 374 | ###7.1.2 符号变量 375 | 符号变量是用符号表示的变量,其地址对不同的可编程控制器可以不同,从而为程序的移植创造了条件。例如: 376 | ``` 377 | VAR_INPUT 378 | SW_1 AT %IX1.1 : BOOL; 379 | END_VAR 380 | ``` 381 | 在上述变量声明中,用符号变量SW_1表示从%IX1.1地址读取布尔值,当实际地址更改时,在程序的其他部分仍是该符号变量。因此,只需对该地址进行修改,就可完成整个程序的移植,实现程序的重复使用。AT是定位前缀关键字。 382 | 383 | ###7.1.3 数组变量 384 | 等待补充…… 385 | 386 | ###7.1.4 结构变量 387 | 等待补充…… 388 | 389 | ##7.2 变量分类及属性 390 | IEC61131-3标准根据应用范围对变量进行分类,通过设置变量属性将它们的有关性能赋予变量。变量分类如下表所示: 391 | 变量类型关键字|说明|外部读写|内部读写 392 | :-:|:-:|:-:|:-:| 393 | VAR|内部变量,程序组织单元内部的变量|不允许|读/写 394 | VAR_INPUT|输入变量,由外部提供,在程序组织单元内部不能修改|读/写|读 395 | VAR_OUTPUT|输出变量,由程序组织单元提供给外部实体使用|写|读/写 396 | VAR_IN_OUT|输入-输出变量,由外部实体提供,能在程序组织单元内部修改|读/写|读/写 397 | VAR_EXTERNAL|外部变量,能在程序组织单元内部修改,由全局变量组态VAR_GLOBAL提供|读/写|读/写 398 | VAR_GLOBAL|全局变量,能在对应的配置、资源内使用|读/写|读/写 399 | VAR_ACCESS|存取变量,用于与外部设备的不同程序间变量的传递|读/写|读/写 400 | VAR_TEMP|暂存变量,在程序或功能块中暂时存储的变量|读/写|读/写 401 | VAR_CONFIG|配置变量,实例规定的初始化和地址分配|不允许|读 402 | 变量附加属性如下表所示: 403 | 附加属性关键字|说明 404 | :-:|:- 405 | RETAIN|表示变量附加保持属性,即电源掉电时也能够保持该变量的值 406 | NON_RETAIN|表示变量附加不保持属性,即电源掉电时不具有掉电保持功能 407 | CONSTANT|表示该变量是一个常量,因此,程序执行时,该变量的值保持不变,不能修改 408 | AT|表示变量存取的地址 409 | R_EDGE|对输入变量设置上升沿边沿检测 410 | F_EDGE|对输入变量设置下降沿边沿检测 411 | READ_WRITE|对存取变量设置读写属性 412 | READ_ONLY|对存取变量设置只读属性 413 | 414 | ##7.3 变量初始化 415 | 当配置元素(资源或配置)“启动”时,与配置元素及其程序有关的每个变量可以取以下初始值之一: 416 | - 配置元素“停止”时,该变量具有的值(保持值) 417 | - 用户规定的初始值; 418 | - 变量的相关数据类型的缺省初始值; 419 | 420 | 变量的相关配置元素启动时,变量的初始值由下述规则确定: 421 | - 如果启动操作为“暖启动”,则具有RETAIN属性的变量初始值为其保持值; 422 | - 如果启动操作为“冷启动”,则具有RETAIN属性的变量初始值为用户规定的初始值,如果没有规定,则取相关数据类型的缺省初始值; 423 | - 非保持变量的初始值为用户规定的初始值,如果没有规定,则取相关数据类型的缺省初始值; 424 | - PLC系统输入的变量(处于I区的变量),初始值为0; 425 | - PLC系统输出的变量(处于Q区的变量),初始值为0; 426 | - PLC系统内部存储器的变量(处于M区的变量),初始值为0; 427 | 428 | ##7.4 变量声明 429 | 各种变量的声明及配置请参照《PLC集成开发环境用户手册》相关章节。 430 | 431 | #8 程序组织单元 432 | IEC61131-3定义的程序组织单元是功能、功能块和程序。它们是用户程序的最小软件单位。 433 | 程序组织单元不能够递归调用,即:一个程序组织单元的调用不应导致另一个相同类型的程序组织单元的调用。 434 | 程序组织单元的声明、参数定义和程序编写请参照《PLC集成开发环境用户手册》相关章节。 435 | 436 | ##8.1 功能 437 | 功能是一种可以赋予参数,但没有静态变量的程序组织单元,当用相同的输入参数调用一个功能时,该功能总是能够生成相同的输出结果。功能是可重复使用的软件元素,可以使用标准规定的各种编程语言编写。功能的重要特征是它们不能在内部存储数值,功能的调用结果可以作为表达式的一个操作数。 438 | 功能分为标准功能与用户定义功能两类。IEC61131-3标准定义了7类标准功能,分别是: 439 | - 类型转换功能 440 | - 数值运算功能 441 | - 位串操作功能 442 | - 选择与比较功能 443 | - 字符串功能 444 | - 时间数据类型的功能 445 | - 枚举数据类型的功能 446 | 447 | ##8.2 功能块 448 | 功能块是在执行时能够产生一个或多个值的程序组织单元。在控制系统中,功能块实际是某种控制算法,例如PID功能被用于闭环控制,其它功能块可用于计数器、斜坡和滤波等。 449 | 功能块具有记忆功能,因此,相同输入参数调用时,其输出变量的值取决于其内部变量和外部变量的状态。与功能不同,功能块的内部变量是持续的。在两个采样时间间隔内,这些变量能够保持其值。功能块实例的记忆功能表现在下列两方面: 450 | - 功能块实例的输入参数在下次调用前应保持不变; 451 | - 功能块实例的输出参数在两次调用之间应保持不变; 452 | 453 | 功能块必须在程序组织单元(程序、其它功能块)的参数中声明为功能块实例才能被调用。 454 | 功能块分为标准功能块与用户定义功能块两类。标准功能块有: 455 | - 双稳元素功能块 456 | - 边沿检测功能块 457 | - 计数器功能块 458 | - 定时器功能块 459 | - 通信功能块 460 | 461 | ##8.3 程序 462 | 程序是作为用户逻辑的调用入口的程序组织单元,程序的各种特性与功能块类似。 463 | 程序在资源说明中实例化,然后与特定任务结合起来,资源启动起来后,随着任务的调度,就会执行与之结合的程序实例,使用户逻辑运行起来。 464 | ##8.4 功能、功能块与程序的性能对比 465 | 性能|功能|功能块|程序 466 | :-:|:-:|:-:|:-: 467 | 允许使用VAR|是|是|是 468 | 允许使用VAR_INPUT|是|是|是 469 | 允许使用VAR_OUTPUT|否|是|是 470 | 允许使用VAR_IN_OUT|否|是|是 471 | 允许使用VAR_EXTERNAL|否|是|是 472 | 允许使用VAR_GLOBAL|否|否|是 473 | 允许使用VAR_ACCESS|否|否|是 474 | 允许使用VAR_TEMP|否|是|是 475 | 允许使用VAR_CONFIG|否|否|是 476 | 功能值|是|否|否 477 | 可调用功能|是|是|是 478 | 可调用功能块|否|是|是 479 | 可调用程序|否|否|否 480 | 可递归调用|否|否|否 481 | 可间接功能块调用|否|是|是 482 | 具有过载和可扩展性|是|否|否 483 | 具有边沿检测的可能性|否|是|是 484 | 具有局部和输出变量的保持功能|否|是|是 485 | 可对直接表示变量声明|否|否|是 486 | 可对局部变量声明|是|是|是 487 | 可对功能块实例声明|否|是|是 488 | 489 | #9 文本编程语言 490 | IEC61131-3标准规定了两种文本语言: 491 | - 指令表语言(Instruction List, IL),用一系列指令组成程序组织单元的本体部分。 492 | - 结构化文本语言(Structured Text, ST),用一系列语句组成程序组织单元的本体部分。 493 | 494 | ##9.1 指令表(IL) 495 | 指令表由一系列指令组成,每条指令从新的一行开始,由操作符和操作数组成,操作符可带修改符,操作数如果多于一个,可用逗号分隔。指令也可带标号和注释。指令的格式如下: 496 | ``` 497 | 标号: 操作符+修正符(可选) 操作数 (* 注释 *) 498 | ``` 499 | 指令执行结果保存在一个称为“当前结果”的变量中,指令对“当前结果”进行相应操作,例如: 500 | ``` 501 | LD BOOL#1 (* 加载布尔值1至当前结果,执行后当前结果为BOOL#1 *) 502 | AND BOOL#0 (* 将布尔值0与当前结果相与,执行后当前结果为 BOOL#0 *) 503 | ST %MX0 (* 将当前结果值存入直接表示变量%MX0中,执行后%MX0 = BOOL#0,当前结果值不变 *) 504 | ``` 505 | 大多数传统PLC都提供指令表编程语言。与传统PLC的指令表编程语言相比,IEC61131-3标准的指令表编程语言更为简单,因为采用了修正符、功能和功能块,一些原来用指令执行实现的操作可通过修正符、功能和功能块的调用方便地实现。而传统可编程控制器的操作指令很多,对不同的数据类型的同一类型运算要有不同的指令等。 506 | 指令表编程语言的主要特点是非常简单和容易学习,对于小型的简单过程控制问题是理想的编程语言。但对大型的复杂控制问题缺少有效工具,不太适用。 507 | 508 | IEC61131-3标准将指令表编程语言的操作符简化为24种,下表列出所有支持的操作符和每个操作符允许使用的修正符。 509 | 510 | 操作符|修正符|操作数|说明|示例 511 | :-:|:-:|:-:|:-:|:-: 512 | LD|N|ANY|设置当前结果等于操作数| 513 | ST|N|ANY|存储当前结果至操作数| 514 | S||BOOL|如果当前结果是布尔1,则操作数置位为1| 515 | R||BOOL|如果当前结果是布尔1,则操作数复位为0| 516 | AND
&|N, (|ANY|布尔逻辑与| 517 | OR|N, (|ANY|布尔逻辑或| 518 | XOR|N, (|ANY|布尔逻辑异或| 519 | NOT||ANY_BIT|逻辑取反| 520 | ADD|(|ANY|加| 521 | SUB|(|ANY|减| 522 | MUL|(|ANY|乘| 523 | DIV|(|ANY|除| 524 | MOD|(|ANY_INT|模除| 525 | GT|(|ANY|比较:大于| 526 | GE|(|ANY|比较:大于等于| 527 | EQ|(|ANY|比较:等于| 528 | NE|(|ANY|比较:不等于| 529 | LE|(|ANY|比较:小于等于| 530 | LT|(|ANY|比较:小于| 531 | JMP|C, N|指令标号名称|跳转至标号| 532 | CAL|C, N|功能块实例名称|调用功能块| 533 | RET|C, N||从被调用的功能、功能块或程序返回| 534 | )|||计算延缓操作,与(修正符配合使用| 535 | 536 | 修正符及其说明 537 | 修正符|说明 538 | :-:|:- 539 | C|仅当当前结果是布尔1时才执行相应指令
如果与'N'修正符结合使用,表示仅当当前结果是布尔0时才执行相应指令 540 | N|操作数按位取反 541 | (|将操作符的求值递延至右括号操作符")"处。 542 | 指令带括号表达式的递延执行示例如下: 543 | ``` 544 | AND( 545 | LD %IX1 546 | OR %IX2 547 | ) 548 | ``` 549 | 或更短的形式: 550 | ``` 551 | AND( %IX1 552 | OR %IX2 553 | ) 554 | ``` 555 | ###9.1.3 调用功能 556 | 有两种方式调用功能: 557 | - 具有形式变元表的功能调用,例如: 558 | ``` 559 | LIMIT( 560 | EN := COND, 561 | IN := B, 562 | MN := 1, 563 | MX := 5, 564 | ENO => TEMPL 565 | ) 566 | ST A 567 | ``` 568 | - 具有非形式变元表的功能调用,例如: 569 | ``` 570 | LD 1 571 | LIMIT B,5 572 | ST A 573 | ``` 574 | 575 | ###9.1.4 调用功能块 576 | 有三种形式调用功能块: 577 | - 具有非形式变元表的功能块调用,例如: 578 | ``` 579 | CAL C10(%IX0, FALSE, A, OUT, B) 580 | CAL CMD_TMR(%IX5, T#300ms, OUT, ELASPED) 581 | ``` 582 | - 具有形式变元表的功能块调用,例如: 583 | ``` 584 | CAL C10( 585 | CU := %IX10, 586 | Q => OUT 587 | ) 588 | CAL CMD_TMR( 589 | IN := %IX5, 590 | PT := T#300ms, 591 | Q => OUT, 592 | ET => ELAPSED, 593 | ENO => ERR 594 | ) 595 | ``` 596 | - 具有变元装载/存储的功能块调用,例如: 597 | ``` 598 | LD A 599 | ADD 5 600 | ST C10.PV 601 | LD %IX10 602 | ST C10.CU 603 | CAL C10 604 | ``` 605 | 上述举例中,假定程序组织单元中有如下说明: 606 | ``` 607 | VAR 608 | C10 : CTU; 609 | CMD_TMR : TON; 610 | A, B: INT; 611 | ELAPSED : TIME; 612 | OUT, ERR, TEMPL, COND : BOOL; 613 | END_VAR 614 | ``` 615 | 616 | ##9.2 结构化文本(ST) 617 | 结构化文本语言是高级编程语言,类似于PASCAL语言。它由一系列语句,例如:选择语句、循环语句、赋值语句等组成,用于实现一定功能。它不采用面向机器的操作符,而采用能描述复杂控制要求的功能性抽象语句,因此,具有清晰的程序结构,利于对程序的分析。它具有强有力的控制命令语句结构,使复杂控制问题变得容易解决。 618 | ###9.2.1 表达式 619 | 等待补充…… 620 | 621 | ###9.2.2 语句 622 | 等待补充…… 623 | 624 | #10 图形编程语言 625 | IEC61131-3标准规定了两种图形语言: 626 | - 梯形图(Ladder Diagram, LD) 627 | - 功能块图(Function Block Diagram, FBD) 628 | 629 | ##10.2 梯形图(LD) 630 | 梯形图编程语言是历史最久远的一种编程语言,源于电气系统的逻辑控制图,逻辑图采用继电器、触点、线圈和逻辑关系图等表示它们的逻辑关系。 631 | IEC61131-3标准规定梯形图可采用的图形元素包括电源轨线、连接线、触点、线圈、功能和功能块。梯形图程序借助这些标准化的图形元素使PLC能够检测和修改数据。这些符号以类似于继电器梯形逻辑图的“梯级”方式在网络中布局,呈现在一张画布上。梯形图网络左右由两条电源轨线界定,中间由行列排布的大小相同的矩形图元组成。如下图所示: 632 | ![梯形图程序示例](images/ld_example.PNG) 633 | 如果一个元件的大小超出了一个图元的范围,则它将占用多个图元,比如功能与功能块实例调用。 634 | 635 | ###10.2.1 梯形图组成元件 636 | - 左右电源轨线 637 | 梯形图左右分界的竖直线称为左右电源轨线,左电源轨线的状态始终为ON,右电源轨线的状态未定义,只作为梯形图网络统一的终止位置。 638 | 639 | - 触点 640 | 触点元件用于表述布尔变量状态的变化 ,是向其右侧水平连接元素传递一个状态的梯形图元素。触点传递的状态是其左侧水平连接元素状态与触点关联布尔变量状态进行布尔与运算的结果。触点不改变关联变量的值。 641 | 按静态特性分类,触点分为常开触点和常闭触点。常开触点指在正常工况下,触点断开,其状态为0.常闭触点指在正常工况下,触点闭合,其状态为1。 642 | 按动态特性分类,触点分为正转换-检测触点和负转换-检测触点。 643 | 触点关联的变量名称直接标注在触点的上方。 644 | 645 | 触点类型|
符号|说明 646 | :-:|:-:|:- 647 | 常开触点|\*\*\*
-\| \|-|如果\*\*\*指示的相关布尔变量状态为ON,则左边连接的状态复制到右边连接,否则,右边连接的状态是OFF。 648 | 常闭触点|\*\*\*
-\|/\|-|如果\*\*\*指示的相关布尔变量状态为OFF,则左边连接的状态复制到右边连接,否则,右边连接的状态是OFF。 649 | 正转换-检测触点|\*\*\*
-\|P\|-|当触点左边水平连接状态为ON,此时检测到关联变量状态由OFF转变为ON,则从本次检测至下一次检测期间,触点右边水平连接状态为ON,其它时候为OFF。 650 | 负转换-检测触点|\*\*\*
-\|N\|-|当触点左边水平连接状态为ON,此时检测到关联变量状态由ON转变为OFF,则从本次检测至下一次检测期间,触点右边水平连接状态为ON,其它时候为OFF。 651 | 652 | - 线圈 653 | 线圈把其左边连接的状态无修改地复制到右边的连接,并把左边连接的状态或转换的适当功能存储到关联的布尔变量。 654 | 655 | 线圈类型|
符号|说明 656 | :-:|:-:|:- 657 | 线圈|\*\*\*
-( )-|左边连接的状态复制给关联布尔变量和右边连接 658 | 取反线圈|\*\*\*
-(/)-|左边连接的状态复制给右边连接,其相反状态复制给关联的布尔变量 659 | 置位线圈|\*\*\*
-(S)-|当左边连接处于ON状态,关联布尔变量被置位为ON,并保持该状态直到被复位线圈复位。 660 | 复位线圈|\*\*\*
-(R)-|当左边连接处于ON状态,关联布尔变量被复位为OFF,并保持该状态直到被置位线圈置位 661 | 正转换-检测线圈|\*\*\*
-(P)-|当检测到左边连接状态从OFF到ON的转换时,关联布尔变量从本次检测到下一次检测期间保持为ON,左边连接的状态总是被复制给右边连接。 662 | 负转换-检测线圈|\*\*\*
-(N)-|当检测到左边连接状态从ON到OFF的转换时,关联布尔变量从本次检测到下一次检测期间保持为ON,左边连接的状态总是被复制给右边连接。 663 | 664 | - 功能调用 665 | 666 | - 功能块实例调用 667 | 668 | - 连接线 669 | 梯形图各种元件由水平和竖直的线条进行连接,水平连接线和竖直连接线还会相交,构成各种样式的交叉连接线,如下图所示: 670 | ![交叉连接线](images/cross_link.png) 671 | 672 | ###10.2.2 梯形图网络求值顺序 673 | 梯形图按从上到下,从左到右的顺序进行求值。 674 | 675 | ##10.3 功能块图(FBD) 676 | 等待补充…… 677 | 678 | #11 顺序功能图(SFC)编程语言 679 | 等待补充…… 680 | 681 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 2.1, February 1999 3 | 4 | Copyright (C) 1991, 1999 Free Software Foundation, Inc. 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | [This is the first released version of the Lesser GPL. It also counts 10 | as the successor of the GNU Library Public License, version 2, hence 11 | the version number 2.1.] 12 | 13 | Preamble 14 | 15 | The licenses for most software are designed to take away your 16 | freedom to share and change it. By contrast, the GNU General Public 17 | Licenses are intended to guarantee your freedom to share and change 18 | free software--to make sure the software is free for all its users. 19 | 20 | This license, the Lesser General Public License, applies to some 21 | specially designated software packages--typically libraries--of the 22 | Free Software Foundation and other authors who decide to use it. You 23 | can use it too, but we suggest you first think carefully about whether 24 | this license or the ordinary General Public License is the better 25 | strategy to use in any particular case, based on the explanations below. 26 | 27 | When we speak of free software, we are referring to freedom of use, 28 | not price. Our General Public Licenses are designed to make sure that 29 | you have the freedom to distribute copies of free software (and charge 30 | for this service if you wish); that you receive source code or can get 31 | it if you want it; that you can change the software and use pieces of 32 | it in new free programs; and that you are informed that you can do 33 | these things. 34 | 35 | To protect your rights, we need to make restrictions that forbid 36 | distributors to deny you these rights or to ask you to surrender these 37 | rights. These restrictions translate to certain responsibilities for 38 | you if you distribute copies of the library or if you modify it. 39 | 40 | For example, if you distribute copies of the library, whether gratis 41 | or for a fee, you must give the recipients all the rights that we gave 42 | you. You must make sure that they, too, receive or can get the source 43 | code. If you link other code with the library, you must provide 44 | complete object files to the recipients, so that they can relink them 45 | with the library after making changes to the library and recompiling 46 | it. And you must show them these terms so they know their rights. 47 | 48 | We protect your rights with a two-step method: (1) we copyright the 49 | library, and (2) we offer you this license, which gives you legal 50 | permission to copy, distribute and/or modify the library. 51 | 52 | To protect each distributor, we want to make it very clear that 53 | there is no warranty for the free library. Also, if the library is 54 | modified by someone else and passed on, the recipients should know 55 | that what they have is not the original version, so that the original 56 | author's reputation will not be affected by problems that might be 57 | introduced by others. 58 | 59 | Finally, software patents pose a constant threat to the existence of 60 | any free program. We wish to make sure that a company cannot 61 | effectively restrict the users of a free program by obtaining a 62 | restrictive license from a patent holder. Therefore, we insist that 63 | any patent license obtained for a version of the library must be 64 | consistent with the full freedom of use specified in this license. 65 | 66 | Most GNU software, including some libraries, is covered by the 67 | ordinary GNU General Public License. This license, the GNU Lesser 68 | General Public License, applies to certain designated libraries, and 69 | is quite different from the ordinary General Public License. We use 70 | this license for certain libraries in order to permit linking those 71 | libraries into non-free programs. 72 | 73 | When a program is linked with a library, whether statically or using 74 | a shared library, the combination of the two is legally speaking a 75 | combined work, a derivative of the original library. The ordinary 76 | General Public License therefore permits such linking only if the 77 | entire combination fits its criteria of freedom. The Lesser General 78 | Public License permits more lax criteria for linking other code with 79 | the library. 80 | 81 | We call this license the "Lesser" General Public License because it 82 | does Less to protect the user's freedom than the ordinary General 83 | Public License. It also provides other free software developers Less 84 | of an advantage over competing non-free programs. These disadvantages 85 | are the reason we use the ordinary General Public License for many 86 | libraries. However, the Lesser license provides advantages in certain 87 | special circumstances. 88 | 89 | For example, on rare occasions, there may be a special need to 90 | encourage the widest possible use of a certain library, so that it becomes 91 | a de-facto standard. To achieve this, non-free programs must be 92 | allowed to use the library. A more frequent case is that a free 93 | library does the same job as widely used non-free libraries. In this 94 | case, there is little to gain by limiting the free library to free 95 | software only, so we use the Lesser General Public License. 96 | 97 | In other cases, permission to use a particular library in non-free 98 | programs enables a greater number of people to use a large body of 99 | free software. For example, permission to use the GNU C Library in 100 | non-free programs enables many more people to use the whole GNU 101 | operating system, as well as its variant, the GNU/Linux operating 102 | system. 103 | 104 | Although the Lesser General Public License is Less protective of the 105 | users' freedom, it does ensure that the user of a program that is 106 | linked with the Library has the freedom and the wherewithal to run 107 | that program using a modified version of the Library. 108 | 109 | The precise terms and conditions for copying, distribution and 110 | modification follow. Pay close attention to the difference between a 111 | "work based on the library" and a "work that uses the library". The 112 | former contains code derived from the library, whereas the latter must 113 | be combined with the library in order to run. 114 | 115 | GNU LESSER GENERAL PUBLIC LICENSE 116 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 117 | 118 | 0. This License Agreement applies to any software library or other 119 | program which contains a notice placed by the copyright holder or 120 | other authorized party saying it may be distributed under the terms of 121 | this Lesser General Public License (also called "this License"). 122 | Each licensee is addressed as "you". 123 | 124 | A "library" means a collection of software functions and/or data 125 | prepared so as to be conveniently linked with application programs 126 | (which use some of those functions and data) to form executables. 127 | 128 | The "Library", below, refers to any such software library or work 129 | which has been distributed under these terms. A "work based on the 130 | Library" means either the Library or any derivative work under 131 | copyright law: that is to say, a work containing the Library or a 132 | portion of it, either verbatim or with modifications and/or translated 133 | straightforwardly into another language. (Hereinafter, translation is 134 | included without limitation in the term "modification".) 135 | 136 | "Source code" for a work means the preferred form of the work for 137 | making modifications to it. For a library, complete source code means 138 | all the source code for all modules it contains, plus any associated 139 | interface definition files, plus the scripts used to control compilation 140 | and installation of the library. 141 | 142 | Activities other than copying, distribution and modification are not 143 | covered by this License; they are outside its scope. The act of 144 | running a program using the Library is not restricted, and output from 145 | such a program is covered only if its contents constitute a work based 146 | on the Library (independent of the use of the Library in a tool for 147 | writing it). Whether that is true depends on what the Library does 148 | and what the program that uses the Library does. 149 | 150 | 1. You may copy and distribute verbatim copies of the Library's 151 | complete source code as you receive it, in any medium, provided that 152 | you conspicuously and appropriately publish on each copy an 153 | appropriate copyright notice and disclaimer of warranty; keep intact 154 | all the notices that refer to this License and to the absence of any 155 | warranty; and distribute a copy of this License along with the 156 | Library. 157 | 158 | You may charge a fee for the physical act of transferring a copy, 159 | and you may at your option offer warranty protection in exchange for a 160 | fee. 161 | 162 | 2. You may modify your copy or copies of the Library or any portion 163 | of it, thus forming a work based on the Library, and copy and 164 | distribute such modifications or work under the terms of Section 1 165 | above, provided that you also meet all of these conditions: 166 | 167 | a) The modified work must itself be a software library. 168 | 169 | b) You must cause the files modified to carry prominent notices 170 | stating that you changed the files and the date of any change. 171 | 172 | c) You must cause the whole of the work to be licensed at no 173 | charge to all third parties under the terms of this License. 174 | 175 | d) If a facility in the modified Library refers to a function or a 176 | table of data to be supplied by an application program that uses 177 | the facility, other than as an argument passed when the facility 178 | is invoked, then you must make a good faith effort to ensure that, 179 | in the event an application does not supply such function or 180 | table, the facility still operates, and performs whatever part of 181 | its purpose remains meaningful. 182 | 183 | (For example, a function in a library to compute square roots has 184 | a purpose that is entirely well-defined independent of the 185 | application. Therefore, Subsection 2d requires that any 186 | application-supplied function or table used by this function must 187 | be optional: if the application does not supply it, the square 188 | root function must still compute square roots.) 189 | 190 | These requirements apply to the modified work as a whole. If 191 | identifiable sections of that work are not derived from the Library, 192 | and can be reasonably considered independent and separate works in 193 | themselves, then this License, and its terms, do not apply to those 194 | sections when you distribute them as separate works. But when you 195 | distribute the same sections as part of a whole which is a work based 196 | on the Library, the distribution of the whole must be on the terms of 197 | this License, whose permissions for other licensees extend to the 198 | entire whole, and thus to each and every part regardless of who wrote 199 | it. 200 | 201 | Thus, it is not the intent of this section to claim rights or contest 202 | your rights to work written entirely by you; rather, the intent is to 203 | exercise the right to control the distribution of derivative or 204 | collective works based on the Library. 205 | 206 | In addition, mere aggregation of another work not based on the Library 207 | with the Library (or with a work based on the Library) on a volume of 208 | a storage or distribution medium does not bring the other work under 209 | the scope of this License. 210 | 211 | 3. You may opt to apply the terms of the ordinary GNU General Public 212 | License instead of this License to a given copy of the Library. To do 213 | this, you must alter all the notices that refer to this License, so 214 | that they refer to the ordinary GNU General Public License, version 2, 215 | instead of to this License. (If a newer version than version 2 of the 216 | ordinary GNU General Public License has appeared, then you can specify 217 | that version instead if you wish.) Do not make any other change in 218 | these notices. 219 | 220 | Once this change is made in a given copy, it is irreversible for 221 | that copy, so the ordinary GNU General Public License applies to all 222 | subsequent copies and derivative works made from that copy. 223 | 224 | This option is useful when you wish to copy part of the code of 225 | the Library into a program that is not a library. 226 | 227 | 4. You may copy and distribute the Library (or a portion or 228 | derivative of it, under Section 2) in object code or executable form 229 | under the terms of Sections 1 and 2 above provided that you accompany 230 | it with the complete corresponding machine-readable source code, which 231 | must be distributed under the terms of Sections 1 and 2 above on a 232 | medium customarily used for software interchange. 233 | 234 | If distribution of object code is made by offering access to copy 235 | from a designated place, then offering equivalent access to copy the 236 | source code from the same place satisfies the requirement to 237 | distribute the source code, even though third parties are not 238 | compelled to copy the source along with the object code. 239 | 240 | 5. A program that contains no derivative of any portion of the 241 | Library, but is designed to work with the Library by being compiled or 242 | linked with it, is called a "work that uses the Library". Such a 243 | work, in isolation, is not a derivative work of the Library, and 244 | therefore falls outside the scope of this License. 245 | 246 | However, linking a "work that uses the Library" with the Library 247 | creates an executable that is a derivative of the Library (because it 248 | contains portions of the Library), rather than a "work that uses the 249 | library". The executable is therefore covered by this License. 250 | Section 6 states terms for distribution of such executables. 251 | 252 | When a "work that uses the Library" uses material from a header file 253 | that is part of the Library, the object code for the work may be a 254 | derivative work of the Library even though the source code is not. 255 | Whether this is true is especially significant if the work can be 256 | linked without the Library, or if the work is itself a library. The 257 | threshold for this to be true is not precisely defined by law. 258 | 259 | If such an object file uses only numerical parameters, data 260 | structure layouts and accessors, and small macros and small inline 261 | functions (ten lines or less in length), then the use of the object 262 | file is unrestricted, regardless of whether it is legally a derivative 263 | work. (Executables containing this object code plus portions of the 264 | Library will still fall under Section 6.) 265 | 266 | Otherwise, if the work is a derivative of the Library, you may 267 | distribute the object code for the work under the terms of Section 6. 268 | Any executables containing that work also fall under Section 6, 269 | whether or not they are linked directly with the Library itself. 270 | 271 | 6. As an exception to the Sections above, you may also combine or 272 | link a "work that uses the Library" with the Library to produce a 273 | work containing portions of the Library, and distribute that work 274 | under terms of your choice, provided that the terms permit 275 | modification of the work for the customer's own use and reverse 276 | engineering for debugging such modifications. 277 | 278 | You must give prominent notice with each copy of the work that the 279 | Library is used in it and that the Library and its use are covered by 280 | this License. You must supply a copy of this License. If the work 281 | during execution displays copyright notices, you must include the 282 | copyright notice for the Library among them, as well as a reference 283 | directing the user to the copy of this License. Also, you must do one 284 | of these things: 285 | 286 | a) Accompany the work with the complete corresponding 287 | machine-readable source code for the Library including whatever 288 | changes were used in the work (which must be distributed under 289 | Sections 1 and 2 above); and, if the work is an executable linked 290 | with the Library, with the complete machine-readable "work that 291 | uses the Library", as object code and/or source code, so that the 292 | user can modify the Library and then relink to produce a modified 293 | executable containing the modified Library. (It is understood 294 | that the user who changes the contents of definitions files in the 295 | Library will not necessarily be able to recompile the application 296 | to use the modified definitions.) 297 | 298 | b) Use a suitable shared library mechanism for linking with the 299 | Library. A suitable mechanism is one that (1) uses at run time a 300 | copy of the library already present on the user's computer system, 301 | rather than copying library functions into the executable, and (2) 302 | will operate properly with a modified version of the library, if 303 | the user installs one, as long as the modified version is 304 | interface-compatible with the version that the work was made with. 305 | 306 | c) Accompany the work with a written offer, valid for at 307 | least three years, to give the same user the materials 308 | specified in Subsection 6a, above, for a charge no more 309 | than the cost of performing this distribution. 310 | 311 | d) If distribution of the work is made by offering access to copy 312 | from a designated place, offer equivalent access to copy the above 313 | specified materials from the same place. 314 | 315 | e) Verify that the user has already received a copy of these 316 | materials or that you have already sent this user a copy. 317 | 318 | For an executable, the required form of the "work that uses the 319 | Library" must include any data and utility programs needed for 320 | reproducing the executable from it. However, as a special exception, 321 | the materials to be distributed need not include anything that is 322 | normally distributed (in either source or binary form) with the major 323 | components (compiler, kernel, and so on) of the operating system on 324 | which the executable runs, unless that component itself accompanies 325 | the executable. 326 | 327 | It may happen that this requirement contradicts the license 328 | restrictions of other proprietary libraries that do not normally 329 | accompany the operating system. Such a contradiction means you cannot 330 | use both them and the Library together in an executable that you 331 | distribute. 332 | 333 | 7. You may place library facilities that are a work based on the 334 | Library side-by-side in a single library together with other library 335 | facilities not covered by this License, and distribute such a combined 336 | library, provided that the separate distribution of the work based on 337 | the Library and of the other library facilities is otherwise 338 | permitted, and provided that you do these two things: 339 | 340 | a) Accompany the combined library with a copy of the same work 341 | based on the Library, uncombined with any other library 342 | facilities. This must be distributed under the terms of the 343 | Sections above. 344 | 345 | b) Give prominent notice with the combined library of the fact 346 | that part of it is a work based on the Library, and explaining 347 | where to find the accompanying uncombined form of the same work. 348 | 349 | 8. You may not copy, modify, sublicense, link with, or distribute 350 | the Library except as expressly provided under this License. Any 351 | attempt otherwise to copy, modify, sublicense, link with, or 352 | distribute the Library is void, and will automatically terminate your 353 | rights under this License. However, parties who have received copies, 354 | or rights, from you under this License will not have their licenses 355 | terminated so long as such parties remain in full compliance. 356 | 357 | 9. You are not required to accept this License, since you have not 358 | signed it. However, nothing else grants you permission to modify or 359 | distribute the Library or its derivative works. These actions are 360 | prohibited by law if you do not accept this License. Therefore, by 361 | modifying or distributing the Library (or any work based on the 362 | Library), you indicate your acceptance of this License to do so, and 363 | all its terms and conditions for copying, distributing or modifying 364 | the Library or works based on it. 365 | 366 | 10. Each time you redistribute the Library (or any work based on the 367 | Library), the recipient automatically receives a license from the 368 | original licensor to copy, distribute, link with or modify the Library 369 | subject to these terms and conditions. You may not impose any further 370 | restrictions on the recipients' exercise of the rights granted herein. 371 | You are not responsible for enforcing compliance by third parties with 372 | this License. 373 | 374 | 11. If, as a consequence of a court judgment or allegation of patent 375 | infringement or for any other reason (not limited to patent issues), 376 | conditions are imposed on you (whether by court order, agreement or 377 | otherwise) that contradict the conditions of this License, they do not 378 | excuse you from the conditions of this License. If you cannot 379 | distribute so as to satisfy simultaneously your obligations under this 380 | License and any other pertinent obligations, then as a consequence you 381 | may not distribute the Library at all. For example, if a patent 382 | license would not permit royalty-free redistribution of the Library by 383 | all those who receive copies directly or indirectly through you, then 384 | the only way you could satisfy both it and this License would be to 385 | refrain entirely from distribution of the Library. 386 | 387 | If any portion of this section is held invalid or unenforceable under any 388 | particular circumstance, the balance of the section is intended to apply, 389 | and the section as a whole is intended to apply in other circumstances. 390 | 391 | It is not the purpose of this section to induce you to infringe any 392 | patents or other property right claims or to contest validity of any 393 | such claims; this section has the sole purpose of protecting the 394 | integrity of the free software distribution system which is 395 | implemented by public license practices. Many people have made 396 | generous contributions to the wide range of software distributed 397 | through that system in reliance on consistent application of that 398 | system; it is up to the author/donor to decide if he or she is willing 399 | to distribute software through any other system and a licensee cannot 400 | impose that choice. 401 | 402 | This section is intended to make thoroughly clear what is believed to 403 | be a consequence of the rest of this License. 404 | 405 | 12. If the distribution and/or use of the Library is restricted in 406 | certain countries either by patents or by copyrighted interfaces, the 407 | original copyright holder who places the Library under this License may add 408 | an explicit geographical distribution limitation excluding those countries, 409 | so that distribution is permitted only in or among countries not thus 410 | excluded. In such case, this License incorporates the limitation as if 411 | written in the body of this License. 412 | 413 | 13. The Free Software Foundation may publish revised and/or new 414 | versions of the Lesser General Public License from time to time. 415 | Such new versions will be similar in spirit to the present version, 416 | but may differ in detail to address new problems or concerns. 417 | 418 | Each version is given a distinguishing version number. If the Library 419 | specifies a version number of this License which applies to it and 420 | "any later version", you have the option of following the terms and 421 | conditions either of that version or of any later version published by 422 | the Free Software Foundation. If the Library does not specify a 423 | license version number, you may choose any version ever published by 424 | the Free Software Foundation. 425 | 426 | 14. If you wish to incorporate parts of the Library into other free 427 | programs whose distribution conditions are incompatible with these, 428 | write to the author to ask for permission. For software which is 429 | copyrighted by the Free Software Foundation, write to the Free 430 | Software Foundation; we sometimes make exceptions for this. Our 431 | decision will be guided by the two goals of preserving the free status 432 | of all derivatives of our free software and of promoting the sharing 433 | and reuse of software generally. 434 | 435 | NO WARRANTY 436 | 437 | 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO 438 | WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. 439 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR 440 | OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY 441 | KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE 442 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 443 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE 444 | LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME 445 | THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 446 | 447 | 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN 448 | WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY 449 | AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU 450 | FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR 451 | CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE 452 | LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING 453 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A 454 | FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF 455 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 456 | DAMAGES. 457 | 458 | END OF TERMS AND CONDITIONS 459 | 460 | How to Apply These Terms to Your New Libraries 461 | 462 | If you develop a new library, and you want it to be of the greatest 463 | possible use to the public, we recommend making it free software that 464 | everyone can redistribute and change. You can do so by permitting 465 | redistribution under these terms (or, alternatively, under the terms of the 466 | ordinary General Public License). 467 | 468 | To apply these terms, attach the following notices to the library. It is 469 | safest to attach them to the start of each source file to most effectively 470 | convey the exclusion of warranty; and each file should have at least the 471 | "copyright" line and a pointer to where the full notice is found. 472 | 473 | 474 | Copyright (C) 475 | 476 | This library is free software; you can redistribute it and/or 477 | modify it under the terms of the GNU Lesser General Public 478 | License as published by the Free Software Foundation; either 479 | version 2.1 of the License, or (at your option) any later version. 480 | 481 | This library is distributed in the hope that it will be useful, 482 | but WITHOUT ANY WARRANTY; without even the implied warranty of 483 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 484 | Lesser General Public License for more details. 485 | 486 | You should have received a copy of the GNU Lesser General Public 487 | License along with this library; if not, write to the Free Software 488 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 489 | USA 490 | 491 | Also add information on how to contact you by electronic and paper mail. 492 | 493 | You should also get your employer (if you work as a programmer) or your 494 | school, if any, to sign a "copyright disclaimer" for the library, if 495 | necessary. Here is a sample; alter the names: 496 | 497 | Yoyodyne, Inc., hereby disclaims all copyright interest in the 498 | library `Frob' (a library for tweaking knobs) written by James Random 499 | Hacker. 500 | 501 | , 1 April 1990 502 | Ty Coon, President of Vice 503 | 504 | That's all there is to it! 505 | --------------------------------------------------------------------------------