[go: up one dir, main page]

CN109032056A - Programmable logic controller (PLC) programming language conversion method - Google Patents

Programmable logic controller (PLC) programming language conversion method Download PDF

Info

Publication number
CN109032056A
CN109032056A CN201810609274.9A CN201810609274A CN109032056A CN 109032056 A CN109032056 A CN 109032056A CN 201810609274 A CN201810609274 A CN 201810609274A CN 109032056 A CN109032056 A CN 109032056A
Authority
CN
China
Prior art keywords
conversion
icil
language
programming language
intermediate structure
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN201810609274.9A
Other languages
Chinese (zh)
Other versions
CN109032056B (en
Inventor
史建琦
黄滟鸿
何积丰
李昂
蔡方达
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shanghai Formal Tech Information Technology Co ltd
Original Assignee
Shanghai Fenglei Information Technology Co Ltd
East China Normal University
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shanghai Fenglei Information Technology Co Ltd, East China Normal University filed Critical Shanghai Fenglei Information Technology Co Ltd
Priority to CN201810609274.9A priority Critical patent/CN109032056B/en
Publication of CN109032056A publication Critical patent/CN109032056A/en
Application granted granted Critical
Publication of CN109032056B publication Critical patent/CN109032056B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G05CONTROLLING; REGULATING
    • G05BCONTROL OR REGULATING SYSTEMS IN GENERAL; FUNCTIONAL ELEMENTS OF SUCH SYSTEMS; MONITORING OR TESTING ARRANGEMENTS FOR SUCH SYSTEMS OR ELEMENTS
    • G05B19/00Programme-control systems
    • G05B19/02Programme-control systems electric
    • G05B19/04Programme control other than numerical control, i.e. in sequence controllers or logic controllers
    • G05B19/05Programmable logic controllers, e.g. simulating logic interconnections of signals according to ladder diagrams or function charts
    • G05B19/056Programming the PLC
    • GPHYSICS
    • G05CONTROLLING; REGULATING
    • G05BCONTROL OR REGULATING SYSTEMS IN GENERAL; FUNCTIONAL ELEMENTS OF SUCH SYSTEMS; MONITORING OR TESTING ARRANGEMENTS FOR SUCH SYSTEMS OR ELEMENTS
    • G05B2219/00Program-control systems
    • G05B2219/10Plc systems
    • G05B2219/13Plc programming
    • G05B2219/13106Natural language, use simple words like move, rotate

Landscapes

  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Engineering & Computer Science (AREA)
  • Automation & Control Theory (AREA)
  • Programmable Controllers (AREA)

Abstract

本发明提供一种可编程逻辑控制器编程语言转换方法,包括:抽象语法树转换步骤、梯形图转换步骤、功能块图转换步骤、顺序功能表图转换步骤、结构化文本转换步骤、指令表转换步骤、ICIL中间结构转换步骤。本发明提出的可编程逻辑控制器编程语言转换方法能够实现IEC 61131‑3语言的统一转换,在不同厂商的PLC产品上进行开发和移植过程中,不必分别针对每种PLC语言编写相应的移植代码,且有利于后续深入开展基于该中间语言的形式化建模、分析及验证工作。

The invention provides a programming language conversion method for a programmable logic controller, comprising: an abstract syntax tree conversion step, a ladder diagram conversion step, a function block diagram conversion step, a sequential function table diagram conversion step, a structured text conversion step, and an instruction list conversion step step, ICIL intermediate structure conversion step. The programmable logic controller programming language conversion method proposed by the present invention can realize the unified conversion of the IEC 61131-3 language, and in the process of developing and transplanting PLC products from different manufacturers, it is not necessary to write corresponding transplant codes for each PLC language , and is conducive to the subsequent in-depth development of formal modeling, analysis and verification based on the intermediate language.

Description

可编程逻辑控制器编程语言转换方法Programmable logic controller programming language conversion method

技术领域technical field

本发明涉及计算机技术领域,具体涉及一种可编程逻辑控制器编程语言转换方法。The invention relates to the technical field of computers, in particular to a programming language conversion method for a programmable logic controller.

背景技术Background technique

早期的PLC(Programmable Logic Controller,可编程逻辑控制器)编程中,不同的电气设备提供商,包括西门子、三菱、倍福等厂商都有各自的PLC编程语言规范。这对不同厂商设备之间的PLC程序移植工作造成了巨大困难。1993年,国际电工委员会(International Electrotechnical Commission,IEC)颁布了PLC编程的国际标准IEC61131-3。该标准统一了五种PLC编程语言(梯形图、功能块图、顺序功能表图、结构化文本以及指令表语言)的规范,从而为解决不同设备间的PLC程序移植问题提出了解决方案。In the early PLC (Programmable Logic Controller, programmable logic controller) programming, different electrical equipment suppliers, including Siemens, Mitsubishi, Beckhoff and other manufacturers have their own PLC programming language specifications. This has caused great difficulties in the transplantation of PLC programs between different manufacturers' equipment. In 1993, the International Electrotechnical Commission (International Electrotechnical Commission, IEC) promulgated the international standard IEC61131-3 for PLC programming. This standard unifies the specifications of five PLC programming languages (ladder diagram, function block diagram, sequential function table diagram, structured text and instruction list language), thus proposing a solution to the problem of PLC program transplantation between different devices.

为了满足不同PLC编程人群的使用,以及适应不同的PLC应用场景,IEC61131-3的五类语言具有不同的特征。其中,梯形图语言源于电气系统逻辑控制图,功能块图源于信号处理领域,顺序功能表图用于描述顺序功能系统的过程、功能及特性,指令表语言与汇编语言类似,是一种较为底层的语言,而结构化文本语言是一种较高级的文本语言。由于各个语言的特征不同,开发人员在对PLC程序进行开发或迁移工作时,需要掌握多项PLC语言开发技能。目前已有一些不同PLC语言之间的转换工作,例如由顺序功能表图到梯形图的转换、由梯形图到结构化文本的转换、由梯形图到指令表语言的转换等,但其均为单类语言之间的转换,使用起来有很大的局限性。In order to meet the needs of different PLC programming groups and adapt to different PLC application scenarios, the five languages of IEC61131-3 have different characteristics. Among them, the ladder diagram language is derived from the logic control diagram of the electrical system, the function block diagram is derived from the signal processing field, and the sequential function table diagram is used to describe the process, function and characteristics of the sequential function system. The instruction list language is similar to the assembly language and is a A lower-level language, while a structured text language is a higher-level text language. Due to the different characteristics of each language, developers need to master multiple PLC language development skills when developing or migrating PLC programs. At present, there have been some conversion work between different PLC languages, such as the conversion from sequential function table diagram to ladder diagram, from ladder diagram to structured text, from ladder diagram to instruction list language, etc., but they are all The conversion between single-type languages has great limitations in use.

除了关于不同PLC语言之间的转换之外,为了对PLC应用程序进行形式化验证,目前也存在一些由单类PLC语言转换为时间状态自动机、Petri网(一种用于描述离散的、分布式系统的数学建模工具)、NuSMV输入模型(一种模型检测工具)等形式化模型的转换技术。形式化方法利用严格的数学语义检查软件开发的各个阶段,可用于保证得到正确实现了的可运行程序,被大量用于验证各种安全相关和生命攸关的系统。由于上述转化技术也是单类语言向形式化模型进行转换,同样具有较大的局限性。In addition to the conversion between different PLC languages, in order to formally verify PLC applications, there are currently some conversions from single-class PLC languages to time-state automata, Petri nets (a method used to describe discrete, distributed Formal system mathematical modeling tool), NuSMV input model (a model checking tool) and other formal model transformation techniques. Formal methods use strict mathematical semantics to check each stage of software development, which can be used to ensure that the runnable programs are correctly implemented, and are widely used to verify various safety-related and life-critical systems. Since the above-mentioned conversion technology is also a conversion from a single-class language to a formal model, it also has relatively large limitations.

鉴于上述问题,需要提供一种便于PLC程序进行移植、开发以及验证的PLC编程语言转换方法。In view of the above problems, it is necessary to provide a PLC programming language conversion method that facilitates transplantation, development and verification of PLC programs.

发明内容Contents of the invention

鉴于上述问题,本发明的目的是通过提供一种可编程逻辑控制器编程语言转换方法,以解决现有技术中不便于PLC程序进行移植、开发以及验证的问题。In view of the above problems, the purpose of the present invention is to solve the problem in the prior art that PLC programs are not convenient for transplantation, development and verification by providing a programmable logic controller programming language conversion method.

本发明提供一种可编程逻辑控制器编程语言转换方法,包括:The present invention provides a programmable logic controller programming language conversion method, including:

所述抽象语法树转换步骤,将文本类PLC编程语言转换为抽象语法树;The abstract syntax tree conversion step converts the text class PLC programming language into an abstract syntax tree;

所述梯形图转换步骤,将梯形图转换为ICIL中间结构;The ladder diagram conversion step is to convert the ladder diagram into an ICIL intermediate structure;

所述功能块图转换步骤,将功能块图转换为ICIL中间结构;The function block diagram conversion step is to convert the function block diagram into an ICIL intermediate structure;

所述顺序功能表图转换步骤,将顺序功能表图转换为ICIL中间结构;The sequential function chart conversion step is to convert the sequential function chart into an ICIL intermediate structure;

所述结构化文本转换步骤,将根据结构化文本转换得到的抽象语法树转换为ICIL中间结构;The structured text conversion step converts the abstract syntax tree obtained according to the structured text conversion into an ICIL intermediate structure;

所述指令表转换步骤,将根据指令表转换得到的抽象语法树转换为ICIL中间结构;The instruction list conversion step converts the abstract syntax tree obtained according to the instruction list conversion into an ICIL intermediate structure;

所述ICIL中间结构转换步骤,将所述ICIL中间结构转换为ICIL程序。The ICIL intermediate structure conversion step converts the ICIL intermediate structure into an ICIL program.

可选的,所述抽象语法树转换步骤,具体以文本类PLC编程语言作为输入,通过词法分析和语法分析将输入的所述文本类PLC编程语言转换为抽象语法树;Optionally, the abstract syntax tree converting step specifically takes a text-like PLC programming language as input, and converts the input text-like PLC programming language into an abstract syntax tree through lexical analysis and syntax analysis;

其中,所述文本类PLC编程语言包括:结构化文本语言或指令表语言。Wherein, the text-based PLC programming language includes: structured text language or instruction list language.

可选的,所述梯形图转换步骤包括:多线圈分解步骤、扫描顺序计算步骤、节点逻辑关系计算步骤和表达式优先级计算步骤;其中,Optionally, the ladder diagram conversion step includes: a multi-coil decomposition step, a scan sequence calculation step, a node logical relationship calculation step, and an expression priority calculation step; wherein,

所述多线圈分解步骤、扫描顺序计算步骤、节点逻辑关系计算步骤和表达式优先级计算步骤分别进行多线圈梯级的分解、节点扫描顺序计算、节点逻辑关系计算以及梯形图表达式优先级计算。The multi-coil decomposing step, scanning sequence calculating step, node logical relationship calculating step and expression priority calculating step respectively perform multi-coil step decomposition, node scanning sequence calculation, node logical relationship calculation and ladder diagram expression priority calculation.

可选的,所述功能块图转换步骤包括:功能块图解析步骤和功能块图转换规则步骤;Optionally, the function block diagram conversion step includes: a function block diagram analysis step and a function block diagram conversion rule step;

所述功能块图解析步骤,将功能块图程序对应的PLCOpen XML文件解析为第一数据结构,所述第一数据结构包括:功能块程序、功能块网络、功能块和网络输入输出连接数据;The function block diagram parsing step resolves the PLCOpen XML file corresponding to the function block diagram program into a first data structure, and the first data structure includes: function block program, function block network, function block and network input and output connection data;

所述功能块图转换规则步骤,根据所述功能块转换规则和网络表达式输入输出规则,将所述功能块图解析步骤输出的第一数据结构转换为ICIL中间结构。The function block diagram conversion rule step converts the first data structure output by the function block diagram analysis step into an ICIL intermediate structure according to the function block conversion rule and network expression input and output rules.

可选的,所述顺序功能表图转换步骤包括:顺序功能表图解析步骤和顺序功能表图转换规则步骤;Optionally, the sequential function chart conversion step includes: a sequential function chart analysis step and a sequential function chart conversion rule step;

所述顺序功能表图解析步骤,将顺序功能表图程序对应的PLCOpenXML文件解析为第二数据结构,所述第二数据结构包括:步、动作块、迁移、并发分支结构、并发合并结构、选择分支结构以及选择合并结构;Described sequential function diagram analysis step, resolves the corresponding PLCOpenXML file of sequential function diagram program into the second data structure, and described second data structure comprises: step, action block, migration, concurrent branch structure, concurrent merge structure, selection branch structure and select merge structure;

所述顺序功能表图转换规则步骤,根据所述步转换规则和动作块转换规则将所述第二数据结构转换为ICIL中间结构。The sequential function diagram conversion rule step converts the second data structure into an ICIL intermediate structure according to the step conversion rule and the action block conversion rule.

可选的,所述结构化文本转换步骤,具体根据所述结构化文本转换规则,将所述抽象语法树转换步骤根据结构化文本语言生成的抽象语法树转换为ICIL中间结构。Optionally, the structured text conversion step converts the abstract syntax tree generated in the structured text language into an ICIL intermediate structure specifically according to the structured text conversion rule.

可选的,所述指令表转换步骤,具体根据所述指令表转换规则,将所述抽象语法树转换步骤根据指令表语言生成的抽象语法树转换为ICIL中间结构。Optionally, the instruction list conversion step converts the abstract syntax tree generated by the instruction list language into an ICIL intermediate structure specifically according to the instruction list conversion rule.

可选的,所述ICIL中间结构转换步骤,具体包括对ICIL中间结构进行解析,以及根据解析结果生成ICIL程序中的代码。Optionally, the step of converting the ICIL intermediate structure specifically includes analyzing the ICIL intermediate structure, and generating codes in the ICIL program according to the analysis result.

可选的,所述ICIL为基于CSP语言进行扩展得到的工业控制器中间语言,其扩展内容包括模块元素、语句元素和周期式通道元素;其中,Optionally, the ICIL is an industrial controller intermediate language obtained by extending the CSP language, and its extended content includes module elements, statement elements and periodic channel elements; wherein,

所述模块元素,用于统一IEC 61131-3中对程序组织单元的定义,以通过模块的调用和运行来表示原PLC编程语言中的函数、功能块、程序的调用及运行;The module element is used to unify the definition of the program organization unit in IEC 61131-3, so as to represent the calling and running of functions, function blocks and programs in the original PLC programming language through calling and running of modules;

所述语句元素,用于表示赋值操作以及模块的调用操作;The statement element is used to represent the assignment operation and the calling operation of the module;

所述周期式通道元素,用于周期式传输通道上的消息。The periodic channel element is used for periodically transmitting messages on the channel.

可选的,所述模块元素包括:变量声明和进程定义两个部分;其中,Optionally, the module element includes two parts: variable declaration and process definition; wherein,

所述变量声明用于声明在模块中使用到的变量;The variable declaration is used to declare the variables used in the module;

所述进程定义用于通过进程表示模块的执行行为。The process definition is used to represent the execution behavior of the module through the process.

本发明的有益效果包括:The beneficial effects of the present invention include:

本发明提出的可编程逻辑控制器编程语言转换方法能够实现IEC 61131-3语言的统一转换,在不同厂商的PLC产品上进行开发和移植过程中,不必分别针对每种PLC语言编写相应的移植代码;此外,本发明提出的形式化建模语言ICIL及其转换方法,有利于后续深入开展基于该中间语言的形式化建模、分析及验证工作,由于IEC 61131-3标准本身没有提出过相应的形式化验证方法,因此本发明对提高关键领域工控程序的安全性和可靠性具有重要意义,在PLC编程环境中具有广阔应用前景;另外,本发明提出的形式化建模语言ICIL有利于未来统一PLC编程开发语言。The programmable logic controller programming language conversion method proposed by the present invention can realize the unified conversion of the IEC 61131-3 language, and it is not necessary to write corresponding transplantation codes for each PLC language during the development and transplantation process on PLC products of different manufacturers ; In addition, the formalized modeling language ICIL and its conversion method proposed by the present invention are conducive to the subsequent in-depth development of formalized modeling, analysis and verification work based on the intermediate language, because the IEC 61131-3 standard itself has not proposed a corresponding Formal verification method, so the present invention is of great significance to improving the safety and reliability of the industrial control program in the key field, and has broad application prospects in the PLC programming environment; PLC programming development language.

附图说明Description of drawings

通过阅读下文优选实施方式的详细描述,各种其他的优点和益处对于本领域普通技术人员将变得清楚明了。附图仅用于示出优选实施方式的目的,而并不认为是对本发明的限制。而且在整个附图中,用相同的参考符号表示相同的部件。在附图中:Various other advantages and benefits will become apparent to those of ordinary skill in the art upon reading the following detailed description of the preferred embodiment. The drawings are only for the purpose of illustrating a preferred embodiment and are not to be considered as limiting the invention. Also throughout the drawings, the same reference numerals are used to designate the same components. In the attached picture:

图1示出了本发明实施方式所提供的一种可编程逻辑控制器编程语言转换系统的示意图;FIG. 1 shows a schematic diagram of a programmable logic controller programming language conversion system provided by an embodiment of the present invention;

图2示出了本发明实施方式所提供的一种可编程逻辑控制器编程语言转换方法的流程图;Fig. 2 shows a flow chart of a programming language conversion method for a programmable logic controller provided by an embodiment of the present invention;

图3示出了本发明实施方式所提供的符合IEC 61131-3编程语言规范的一个梯形图的示意图;FIG. 3 shows a schematic diagram of a ladder diagram conforming to the IEC 61131-3 programming language specification provided by the embodiment of the present invention;

图4示出了本发明实施方式所提供的根据图3提供的梯形图转换得到的AOV图的示意图。FIG. 4 shows a schematic diagram of an AOV diagram converted from the ladder diagram provided in FIG. 3 provided by an embodiment of the present invention.

具体实施方式Detailed ways

下面将参照附图更详细地描述本公开的示例性实施方式。虽然附图中显示了本公开的示例性实施方式,然而应当理解,可以以各种形式实现本公开而不应被这里阐述的实施方式所限制。相反,提供这些实施方式是为了能够更透彻地理解本公开,并且能够将本公开的范围完整的传达给本领域的技术人员。Exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although exemplary embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure may be embodied in various forms and should not be limited by the embodiments set forth herein. Rather, these embodiments are provided for more thorough understanding of the present disclosure and to fully convey the scope of the present disclosure to those skilled in the art.

需要注意的是,除非另有说明,本发明使用的技术术语或者科学术语应当为本发明所属领域技术人员所理解的通常意义。It should be noted that, unless otherwise specified, the technical terms or scientific terms used in the present invention shall have the usual meanings understood by those skilled in the art to which the present invention belongs.

本发明实施方式提供了一种可编程逻辑控制器编程语言转换系统及其方法。下面结合附图对本发明的实施例进行说明。The embodiment of the present invention provides a programmable logic controller programming language conversion system and a method thereof. Embodiments of the present invention will be described below in conjunction with the accompanying drawings.

本发明实施例,首先在扩展CSP(Communicating Sequential Language,通信顺序进程)语言的基础上,提出了一种基于IEC 61131-3编程语言的中间语言ICIL(IndustrialController Intermediate Language,工业控制器中间语言),该语言的扩展元素包括模块元素、语句元素以及周期式通道元素。In the embodiment of the present invention, firstly, on the basis of extending the CSP (Communicating Sequential Language, communication sequence process) language, a kind of intermediate language ICIL (IndustrialController Intermediate Language, industrial controller intermediate language) based on the IEC 61131-3 programming language is proposed, The extension elements of the language include module elements, statement elements, and periodic channel elements.

其中,模块元素统一了IEC 61131-3中对程序组织单元的定义,即原PLC编程语言中的函数、功能块、程序的调用和运行均能通过模块的调用和运行来表示。并且,一个模块包含了变量声明和进程定义两个部分,变量声明部分用于声明在该模块中使用到的变量,一方面,变量声明可以确定这些变量的作用域,另一方面,可以方便在该模块中对这些变量的使用。进程定义用于通过进程表示该模块的执行行为。Among them, the module element unifies the definition of the program organization unit in IEC 61131-3, that is, the function, function block, program call and operation in the original PLC programming language can be expressed by the call and operation of the module. Moreover, a module includes two parts: variable declaration and process definition. The variable declaration part is used to declare the variables used in the module. On the one hand, the variable declaration can determine the scope of these variables; The use of these variables in this module. A process definition is used to represent the execution behavior of the module by a process.

语句元素作为源语言中的事件,可用于表示赋值操作以及模块的调用操作,从而扩展了原CSP语言中计算功能上的不足。As an event in the source language, the statement element can be used to represent the assignment operation and the call operation of the module, thus extending the lack of computing functions in the original CSP language.

周期式通道元素可用于周期式传输通道上的消息,相对于原有CSP语言中的通道,可以更准确地描述PLC程序周期扫描执行的行为。The periodic channel element can be used for messages on the periodic transmission channel. Compared with the channel in the original CSP language, it can more accurately describe the behavior of the periodic scan execution of the PLC program.

请参考图1,其示出了本发明实施方式所提供的一种可编程逻辑控制器编程语言转换系统的示意图,所述可编程逻辑控制器编程语言转换系统10用于将IEC 61131-3编程语言转换为ICIL中间语言,所述可编程逻辑控制器编程语言转换系统10包括:Please refer to FIG. 1, which shows a schematic diagram of a programmable logic controller programming language conversion system provided by an embodiment of the present invention, and the programmable logic controller programming language conversion system 10 is used to program IEC 61131-3 Language conversion is ICIL intermediate language, and described PLC programming language conversion system 10 comprises:

抽象语法树转换模块101、梯形图转换模块102、功能块图转换模块103、顺序功能表图转换模块104、结构化文本转换模块105、指令表转换模块106、ICIL中间结构转换模块107;其中,Abstract syntax tree conversion module 101, ladder diagram conversion module 102, function block diagram conversion module 103, sequential function table diagram conversion module 104, structured text conversion module 105, instruction list conversion module 106, ICIL intermediate structure conversion module 107; wherein,

所述抽象语法树转换模块101用于将文本类PLC编程语言转换为抽象语法树;The abstract syntax tree conversion module 101 is used to convert the text class PLC programming language into an abstract syntax tree;

所述梯形图转换模块102用于将梯形图转换为ICIL中间结构;The ladder diagram conversion module 102 is used to convert the ladder diagram into an ICIL intermediate structure;

所述功能块图转换模块103用于将功能块图转换为ICIL中间结构;The function block diagram conversion module 103 is used to convert the function block diagram into an ICIL intermediate structure;

所述顺序功能表图转换模块104用于将顺序功能表图转换为ICIL中间结构;The sequential function chart conversion module 104 is used to convert the sequential function chart into an ICIL intermediate structure;

所述结构化文本转换模块105用于将根据结构化文本转换得到的抽象语法树转换为ICIL中间结构;The structured text conversion module 105 is used to convert the abstract syntax tree obtained according to the structured text conversion into an ICIL intermediate structure;

所述指令表转换模块106用于将根据指令表转换得到的抽象语法树转换为ICIL中间结构;The instruction table conversion module 106 is used to convert the abstract syntax tree converted according to the instruction table into an ICIL intermediate structure;

所述ICIL中间结构转换模块107用于将所述ICIL中间结构转换为ICIL程序。The ICIL intermediate structure conversion module 107 is used to convert the ICIL intermediate structure into an ICIL program.

在一些实施方式中,所述抽象语法树转换模块101,具体用于以文本类PLC编程语言作为输入,通过词法分析和语法分析将输入的所述文本类PLC编程语言转换为抽象语法树;In some implementations, the abstract syntax tree conversion module 101 is specifically configured to use a text-like PLC programming language as input, and convert the input text-like PLC programming language into an abstract syntax tree through lexical analysis and syntax analysis;

其中,所述文本类PLC编程语言包括:结构化文本语言或指令表语言。Wherein, the text-based PLC programming language includes: structured text language or instruction list language.

具体的,所述抽象语法树转换模块101可以以结构化文本语言以及指令表语言的语法文件作为输入,通过ANTLR等语法解析框架将这两类语言编写的PLC程序转换为抽象语法树。Specifically, the abstract syntax tree conversion module 101 can take the syntax files of structured text language and instruction list language as input, and convert PLC programs written in these two types of languages into abstract syntax trees through a syntax analysis framework such as ANTLR.

在一些实施方式中,所述梯形图转换模块102包括:多线圈分解模块、扫描顺序计算模块、节点逻辑关系计算模块和表达式优先级计算模块;其中,In some implementations, the ladder diagram conversion module 102 includes: a multi-coil decomposition module, a scan sequence calculation module, a node logical relationship calculation module and an expression priority calculation module; wherein,

所述多线圈分解模块、扫描顺序计算模块、节点逻辑关系计算模块和表达式优先级计算模块分别用于多线圈梯级的分解、节点扫描顺序计算、节点逻辑关系计算以及梯形图表达式优先级计算。The multi-coil decomposition module, scanning order calculation module, node logic relationship calculation module and expression priority calculation module are respectively used for the decomposition of multi-coil steps, node scanning sequence calculation, node logic relationship calculation and ladder diagram expression priority calculation .

具体的,在本发明实施例提供的一种实施方式中,所述多线圈分解模块,可以用于对线圈数量大于1的梯级进行分解;Specifically, in an implementation manner provided by an embodiment of the present invention, the multi-coil decomposition module can be used to decompose steps with a number of coils greater than 1;

所述扫描顺序计算模块,可以用于将梯形图节点关系转换为AOV(Activity OnVertex,一种顶点表示活动的有向图)图,并基于AOV图对节点进行拓扑排序,从而获得梯形图中节点的扫描顺序;The scanning sequence calculation module can be used to convert the ladder diagram node relationship into an AOV (Activity OnVertex, a directed graph whose vertex represents activity) graph, and perform topological sorting on the nodes based on the AOV graph, thereby obtaining the nodes in the ladder diagram the scan sequence;

所述节点逻辑关系计算模块,可以用于基于节点之间的连接关系,制定相应的逻辑操作符计算规则,从而计算梯形图节点之间的逻辑关系;The node logical relationship calculation module can be used to formulate corresponding logical operator calculation rules based on the connection relationship between nodes, so as to calculate the logical relationship between the ladder diagram nodes;

所述表达式优先级计算模块,可以用于通过剪枝算法对AOV图中子节点数量大于2的节点进行剪枝操作,即通过插入虚拟节点连接子节点的方式使原AOV图中的每个节点的子节点个数不超过2,在剪枝后的图中计算不同节点之间的操作优先级关系,在梯形图表达式中加入优先级计算符(“(”,“)”)。The expression priority calculation module can be used to perform a pruning operation on nodes with a number of child nodes greater than 2 in the AOV graph through a pruning algorithm, that is, by inserting a virtual node to connect the child nodes, each node in the original AOV graph The number of child nodes of a node is not more than 2, and the operation priority relationship between different nodes is calculated in the pruned graph, and the priority calculator ("(", ")") is added to the ladder diagram expression.

在一些实施方式中,所述功能块图转换模块103包括:功能块图解析模块和功能块图转换规则模块;In some implementations, the function block diagram conversion module 103 includes: a function block diagram analysis module and a function block diagram conversion rule module;

所述功能块图解析模块用于将功能块图程序对应的PLCOpen XML文件解析为第一数据结构,所述第一数据结构包括:功能块程序、功能块网络、功能块和网络输入输出连接数据;The function block diagram analysis module is used to resolve the PLCOpen XML file corresponding to the function block diagram program into a first data structure, and the first data structure includes: function block program, function block network, function block and network input and output connection data ;

所述功能块图转换规则模块中配置有功能块转换规则和网络表达式输入输出规则,用于根据所述功能块转换规则和网络表达式输入输出规则,将所述功能块图解析模块输出的第一数据结构转换为ICIL中间结构。The function block diagram conversion rule module is configured with function block conversion rules and network expression input and output rules, which are used to output the function block diagram analysis module according to the function block conversion rules and network expression input and output rules. The first data structure is converted to an ICIL intermediate structure.

在一些实施方式中,所述顺序功能表图转换模块104包括:顺序功能表图解析模块和顺序功能表图转换规则模块;In some implementations, the sequential function chart conversion module 104 includes: a sequential function chart analysis module and a sequential function chart conversion rule module;

所述顺序功能表图解析模块用于将顺序功能表图程序对应的PLCOpenXML文件解析为第二数据结构,所述第二数据结构包括:步、动作块、迁移、并发分支结构、并发合并结构、选择分支结构以及选择合并结构;The sequential function diagram analysis module is used to parse the PLCOpenXML file corresponding to the sequential function diagram program into a second data structure, and the second data structure includes: step, action block, migration, concurrent branch structure, concurrent merge structure, Select branch structure and select merge structure;

所述顺序功能表图转换规则模块中配置有步转换规则和动作块转换规则(可以根据顺序功能块图中常用的12类限定符(N、R、S、L、D、P、SD、DS、SL、P1及P0)分别制定不同的转换操作),用于根据所述步转换规则和动作块转换规则将所述第二数据结构转换为ICIL中间结构。Step conversion rules and action block conversion rules (can be configured according to the 12 types of qualifiers commonly used in sequential function block diagrams (N, R, S, L, D, P, SD, DS) in the sequential function table diagram conversion rule module , SL, P1 and P0) respectively formulate different conversion operations) for converting the second data structure into an ICIL intermediate structure according to the step conversion rules and action block conversion rules.

在一些实施方式中,所述结构化文本转换模块105中配置有结构化文本转换规则;In some implementation manners, structured text conversion rules are configured in the structured text conversion module 105;

所述结构化文本转换模块105具体用于根据所述结构化文本转换规则,将所述抽象语法树转换模块101根据结构化文本语言生成的抽象语法树转换为ICIL中间结构。The structured text conversion module 105 is specifically configured to convert the abstract syntax tree generated by the abstract syntax tree conversion module 101 according to the structured text language into an ICIL intermediate structure according to the structured text conversion rules.

具体的,由于结构化文本中的语句与ICIL语句比较类似,该模块中的规则主要用于将结构化文本中的case语句以及三类循环语句转换为进程之间的条件选择关系。Specifically, since the statements in the structured text are similar to the ICIL statements, the rules in this module are mainly used to convert the case statements and the three types of loop statements in the structured text into conditional selection relationships between processes.

在一些实施方式中,所述指令表转换模块106中配置有指令表转换规则;In some implementations, the instruction table conversion module 106 is configured with instruction table conversion rules;

所述指令表转换模块106具体用于根据所述指令表转换规则,将所述抽象语法树转换模块101根据指令表语言生成的抽象语法树转换为ICIL中间结构。The instruction list conversion module 106 is specifically configured to convert the abstract syntax tree generated by the abstract syntax tree conversion module 101 according to the instruction list language into an ICIL intermediate structure according to the instruction list conversion rule.

具体的,所述指令表转换模块106中,主要针对指令表语言的每种操作符、修饰符以及两者之间的组合关系定义相应的指令表转换规则,其中延迟计算修饰符需要单独进行计算,本发明中的圆括号延迟计算操作中,采用相应的优先级计算算法,通过优先级计算符(“(”,“)”)将指令中的延迟计算转换为表达式中的优先运算关系。Specifically, in the instruction table conversion module 106, corresponding instruction table conversion rules are mainly defined for each operator and modifier of the instruction table language and the combination relationship between the two, wherein the delay calculation modifier needs to be calculated separately , in the parentheses delay calculation operation in the present invention, the corresponding priority calculation algorithm is adopted to convert the delay calculation in the instruction into the priority operation relationship in the expression through the priority calculator ("(", ")").

在一些实施方式中,所述ICIL中间结构转换模块107用于对ICIL中间结构进行解析,以及根据解析结果生成ICIL程序中的代码。具体的,所述ICIL中间结构转换模块107通过对ICIL中间结构的解析,完成ICIL程序中的自动代码生成工作,其中包括了ICIL语言的生成以及缩进与段落管理的生成。In some implementations, the ICIL intermediate structure conversion module 107 is configured to analyze the ICIL intermediate structure, and generate codes in the ICIL program according to the analysis result. Specifically, the ICIL intermediate structure conversion module 107 completes the automatic code generation in the ICIL program by analyzing the ICIL intermediate structure, including the generation of ICIL language and the generation of indentation and paragraph management.

在一些实施方式中,所述ICIL为基于CSP语言进行扩展得到的工业控制器中间语言,其扩展内容包括模块元素、语句元素和周期式通道元素;其中,In some embodiments, the ICIL is an industrial controller intermediate language obtained by extending the CSP language, and its extended content includes module elements, statement elements and periodic channel elements; wherein,

所述模块元素,用于统一IEC 61131-3中对程序组织单元的定义,以通过模块的调用和运行来表示原PLC编程语言中的函数、功能块、程序的调用及运行;The module element is used to unify the definition of the program organization unit in IEC 61131-3, so as to represent the calling and running of functions, function blocks and programs in the original PLC programming language through calling and running of modules;

所述语句元素,用于表示赋值操作以及模块的调用操作;The statement element is used to represent the assignment operation and the calling operation of the module;

所述周期式通道元素,用于周期式传输通道上的消息。The periodic channel element is used for periodically transmitting messages on the channel.

在一些实施方式中,所述模块元素包括:变量声明和进程定义两个部分;其中,In some implementations, the module element includes: two parts: variable declaration and process definition; wherein,

所述变量声明用于声明在模块中使用到的变量;The variable declaration is used to declare the variables used in the module;

所述进程定义用于通过进程表示模块的执行行为。The process definition is used to represent the execution behavior of the module through the process.

以上,为本发明实施例所提供的可编程逻辑控制器编程语言转换系统10的示例性说明,本发明提出的可编程逻辑控制器编程语言转换系统10能够实现IEC 61131-3语言的统一转换,在不同厂商的PLC产品上进行开发和移植过程中,不必分别针对每种PLC语言编写相应的移植代码;此外,本发明提出的形式化建模语言ICIL及其转换系统10,有利于后续深入开展基于该中间语言的形式化建模、分析及验证工作,由于IEC 61131-3标准本身没有提出过相应的形式化验证方法,因此本发明对提高关键领域工控程序的安全性和可靠性具有重要意义,在PLC编程环境中具有广阔应用前景;另外,本发明提出的形式化建模语言ICIL有利于未来统一PLC编程开发语言。The above is an exemplary description of the programmable logic controller programming language conversion system 10 provided by the embodiment of the present invention. The programmable logic controller programming language conversion system 10 proposed by the present invention can realize the unified conversion of IEC 61131-3 language, In the process of developing and transplanting PLC products from different manufacturers, it is not necessary to write corresponding transplant codes for each PLC language; in addition, the formal modeling language ICIL and its conversion system 10 proposed by the present invention are conducive to subsequent in-depth development Based on the formal modeling, analysis and verification work of the intermediate language, since the IEC 61131-3 standard itself has not proposed a corresponding formal verification method, the present invention is of great significance for improving the security and reliability of industrial control programs in key areas , has broad application prospects in the PLC programming environment; in addition, the formalized modeling language ICIL proposed by the present invention is beneficial to unifying PLC programming development languages in the future.

与上述可编程逻辑控制器编程语言转换系统对应的,本发明还提供一种可编程逻辑控制器编程语言转换方法,请参考图2,其示出了本发明实施方式所提供的一种可编程逻辑控制器编程语言转换方法的流程示意图,所述可编程逻辑控制器编程语言转换方法用于将IEC 61131-3编程语言转换为ICIL中间语言,所述可编程逻辑控制器编程语言转换方法包括:Corresponding to the above programmable logic controller programming language conversion system, the present invention also provides a programmable logic controller programming language conversion method, please refer to Figure 2, which shows a programmable logic controller provided by the embodiment of the present invention A schematic flow chart of a logic controller programming language conversion method, the programmable logic controller programming language conversion method is used to convert the IEC 61131-3 programming language into an ICIL intermediate language, and the programmable logic controller programming language conversion method includes:

抽象语法树转换步骤S101,将文本类PLC编程语言转换为抽象语法树;The abstract syntax tree conversion step S101 is to convert the text-like PLC programming language into an abstract syntax tree;

梯形图转换步骤S102,将梯形图转换为ICIL中间结构;Ladder diagram conversion step S102, converting the ladder diagram into an ICIL intermediate structure;

功能块图转换步骤S103,将功能块图转换为ICIL中间结构;Function block diagram conversion step S103, converting the function block diagram into an ICIL intermediate structure;

顺序功能表图转换步骤S104,将顺序功能表图转换为ICIL中间结构;The sequential function table diagram conversion step S104 is to convert the sequential function table diagram into an ICIL intermediate structure;

结构化文本转换步骤S105,将根据结构化文本转换得到的抽象语法树转换为ICIL中间结构;The structured text conversion step S105 is to convert the abstract syntax tree obtained according to the structured text conversion into an ICIL intermediate structure;

指令表转换步骤S106,将根据指令表转换得到的抽象语法树转换为ICIL中间结构;Instruction table conversion step S106, converting the abstract syntax tree obtained according to the instruction table conversion into an ICIL intermediate structure;

ICIL中间结构转换步骤S107,将所述ICIL中间结构转换为ICIL程序。ICIL intermediate structure converting step S107, converting the ICIL intermediate structure into an ICIL program.

在一些实施方式中,在步骤S101之前,还可以包括步骤S100:获取待转换的PLC编程语言,根据所述PLC编程语言的类别跳转到相应的步骤,例如,若所述PLC编程语言为梯形图,则由步骤S101跳转到步骤S102;若所述PLC编程语言为结构化文本图,则由步骤S101跳转到步骤S101,再由S101跳转到步骤S105;若所述PLC编程语言为指令表,则跳转到步骤S101,再由S101跳转到步骤S106。In some embodiments, before step S101, step S100 may also be included: obtain the PLC programming language to be converted, and jump to the corresponding step according to the category of the PLC programming language, for example, if the PLC programming language is ladder Figure, then jump to step S102 by step S101; If described PLC programming language is a structured text graph, then jump to step S101 by step S101, then jump to step S105 by S101; If described PLC programming language is instruction table, jump to step S101, and then jump to step S106 from S101.

在一些实施方式中,所述抽象语法树转换步骤S101,具体以文本类PLC编程语言作为输入,通过词法分析和语法分析将输入的所述文本类PLC编程语言转换为抽象语法树;In some implementations, the abstract syntax tree conversion step S101 specifically takes a text-like PLC programming language as input, and converts the input text-like PLC programming language into an abstract syntax tree through lexical analysis and syntax analysis;

其中,所述文本类PLC编程语言包括:结构化文本语言或指令表语言。Wherein, the text-based PLC programming language includes: structured text language or instruction list language.

具体的,所述抽象语法树转换步骤S101可以以结构化文本语言以及指令表语言的语法文件作为输入,通过ANTLR等语法解析框架将这两类语言编写的PLC程序转换为抽象语法树。Specifically, the abstract syntax tree converting step S101 may take a structured text language and a syntax file of an instruction list language as input, and convert PLC programs written in these two languages into an abstract syntax tree through a syntax analysis framework such as ANTLR.

在一些实施方式中,所述梯形图转换步骤S102可以包括:多线圈分解步骤、扫描顺序计算步骤、节点逻辑关系计算步骤和表达式优先级计算步骤;其中,In some implementations, the ladder diagram conversion step S102 may include: a multi-coil decomposition step, a scan sequence calculation step, a node logical relationship calculation step, and an expression priority calculation step; wherein,

所述多线圈分解步骤、扫描顺序计算步骤、节点逻辑关系计算步骤和表达式优先级计算步骤分别进行多线圈梯级的分解、节点扫描顺序计算、节点逻辑关系计算以及梯形图表达式优先级计算。The multi-coil decomposing step, scanning sequence calculating step, node logical relationship calculating step and expression priority calculating step respectively perform multi-coil step decomposition, node scanning sequence calculation, node logical relationship calculation and ladder diagram expression priority calculation.

具体的,在本发明实施例提供的一种实施方式中,所述多线圈分解步骤,可以包括:对线圈数量大于1的梯级进行分解;Specifically, in an implementation manner provided by an embodiment of the present invention, the multi-coil decomposing step may include: decomposing steps with a number of coils greater than 1;

所述扫描顺序计算步骤,可以包括:将梯形图节点关系转换为AOV(Activity OnVertex,一种顶点表示活动的有向图)图,并基于AOV图对节点进行拓扑排序,从而获得梯形图中节点的扫描顺序;The scanning sequence calculation step may include: converting the ladder diagram node relationship into an AOV (Activity OnVertex, a directed graph whose vertex represents activity) graph, and carrying out topological sorting to the nodes based on the AOV graph, thereby obtaining the nodes in the ladder diagram the scan sequence;

所述节点逻辑关系计算步骤,可以包括:基于节点之间的连接关系,制定相应的逻辑操作符计算规则,从而计算梯形图节点之间的逻辑关系;The step of calculating the logical relationship between nodes may include: formulating corresponding logical operator calculation rules based on the connection relationship between the nodes, so as to calculate the logical relationship between the nodes of the ladder diagram;

所述表达式优先级计算步骤,可以包括:通过剪枝算法对AOV图中子节点数量大于2的节点进行剪枝操作,即通过插入虚拟节点连接子节点的方式使原AOV图中的每个节点的子节点个数不超过2,在剪枝后的图中计算不同节点之间的操作优先级关系,在梯形图表达式中加入优先级计算符(“(”,“)”)。The expression priority calculation step may include: performing a pruning operation on nodes with a number of sub-nodes greater than 2 in the AOV diagram through a pruning algorithm, that is, by inserting virtual nodes to connect sub-nodes, each node in the original AOV diagram The number of child nodes of a node is not more than 2, and the operation priority relationship between different nodes is calculated in the pruned graph, and the priority calculator ("(", ")") is added to the ladder diagram expression.

在一些实施方式中,所述功能块图转换步骤S103可以包括:功能块图解析步骤和功能块图转换规则步骤;In some implementations, the function block diagram conversion step S103 may include: a function block diagram analysis step and a function block diagram conversion rule step;

所述功能块图解析步骤,可以包括:将功能块图程序对应的PLCOpen XML文件解析为第一数据结构,所述第一数据结构包括:功能块程序、功能块网络、功能块和网络输入输出连接数据;The function block diagram analysis step may include: parsing the PLCOpen XML file corresponding to the function block diagram program into a first data structure, the first data structure comprising: function block program, function block network, function block and network input and output connection data;

所述功能块图转换规则步骤,可以包括:根据功能块转换规则和网络表达式输入输出规则,将所述功能块图解析步骤输出的第一数据结构转换为ICIL中间结构。The function block diagram conversion rule step may include: converting the first data structure output by the function block diagram analysis step into an ICIL intermediate structure according to the function block conversion rule and network expression input and output rules.

在一些实施方式中,所述顺序功能表图转换步骤S104包括:顺序功能表图解析步骤和顺序功能表图转换规则步骤;In some implementations, the sequential function chart conversion step S104 includes: a sequential function chart analysis step and a sequential function chart conversion rule step;

所述顺序功能表图解析步骤,可以包括:将顺序功能表图程序对应的PLCOpenXML文件解析为第二数据结构,所述第二数据结构包括:步、动作块、迁移、并发分支结构、并发合并结构、选择分支结构以及选择合并结构;The step of analyzing the sequential function table diagram may include: the PLCOpenXML file corresponding to the sequential function table diagram program is parsed into a second data structure, and the second data structure includes: step, action block, migration, concurrent branch structure, concurrent merging structure, select branch structure, and select merge structure;

所述顺序功能表图转换规则步骤,可以包括:根据步转换规则和动作块转换规则(可以根据顺序功能块图中常用的12类限定符(N、R、S、L、D、P、SD、DS、SL、P1及P0)分别制定不同的转换操作)将所述第二数据结构转换为ICIL中间结构。The step of the conversion rule of the sequential function table diagram may include: according to the step conversion rule and the action block conversion rule (can be based on the 12 types of qualifiers commonly used in the sequential function block diagram (N, R, S, L, D, P, SD , DS, SL, P1 and P0) formulate different conversion operations respectively) convert the second data structure into an ICIL intermediate structure.

在一些实施方式中,所述结构化文本转换步骤S105,可以包括:根据所述结构化文本转换规则,将所述抽象语法树转换步骤S101根据结构化文本语言生成的抽象语法树转换为ICIL中间结构。In some implementations, the structured text conversion step S105 may include: according to the structured text conversion rules, converting the abstract syntax tree generated in the structured text language in the step S101 into an ICIL intermediate structure.

具体的,由于结构化文本中的语句与ICIL语句比较类似,该步骤中的规则主要用于将结构化文本中的case语句以及三类循环语句转换为进程之间的条件选择关系。Specifically, since the statements in the structured text are similar to the ICIL statements, the rules in this step are mainly used to convert the case statements and the three types of loop statements in the structured text into conditional selection relationships between processes.

在一些实施方式中,所述指令表转换步骤S106,可以包括:根据所述指令表转换规则,将所述抽象语法树转换步骤S101根据指令表语言生成的抽象语法树转换为ICIL中间结构。In some implementations, the instruction list conversion step S106 may include: according to the instruction list conversion rules, converting the abstract syntax tree generated in the instruction list language in the step S101 into an ICIL intermediate structure.

具体的,所述指令表转换步骤S106中,主要针对指令表语言的每种操作符、修饰符以及两者之间的组合关系定义相应的指令表转换规则,其中延迟计算修饰符需要单独进行计算,本发明中的圆括号延迟计算操作中,采用相应的优先级计算算法,通过优先级计算符(“(”,“)”)将指令中的延迟计算转换为表达式中的优先运算关系。Specifically, in the instruction table conversion step S106, the corresponding instruction table conversion rules are mainly defined for each operator and modifier of the instruction table language and the combination relationship between the two, wherein the delay calculation modifier needs to be calculated separately , in the parentheses delay calculation operation in the present invention, the corresponding priority calculation algorithm is adopted to convert the delay calculation in the instruction into the priority operation relationship in the expression through the priority calculator ("(", ")").

在一些实施方式中,所述ICIL中间结构转换步骤S107,可以包括:对ICIL中间结构进行解析,以及根据解析结果生成ICIL程序中的代码。具体的,所述ICIL中间结构转换步骤S107通过对ICIL中间结构的解析,完成ICIL程序中的自动代码生成工作,其中包括了ICIL语言的生成以及缩进与段落管理的生成。In some embodiments, the ICIL intermediate structure conversion step S107 may include: analyzing the ICIL intermediate structure, and generating codes in the ICIL program according to the analysis result. Specifically, the ICIL intermediate structure conversion step S107 completes the automatic code generation in the ICIL program by analyzing the ICIL intermediate structure, including the generation of ICIL language and the generation of indentation and paragraph management.

在一些实施方式中,所述ICIL为基于CSP语言进行扩展得到的工业控制器中间语言,其扩展内容包括模块元素、语句元素和周期式通道元素;其中,In some embodiments, the ICIL is an industrial controller intermediate language obtained by extending the CSP language, and its extended content includes module elements, statement elements and periodic channel elements; wherein,

所述模块元素,用于统一IEC 61131-3中对程序组织单元的定义,以通过模块的调用和运行来表示原PLC编程语言中的函数、功能块、程序的调用及运行;The module element is used to unify the definition of the program organization unit in IEC 61131-3, so as to represent the calling and running of functions, function blocks and programs in the original PLC programming language through calling and running of modules;

所述语句元素,用于表示赋值操作以及模块的调用操作;The statement element is used to represent the assignment operation and the calling operation of the module;

所述周期式通道元素,用于周期式传输通道上的消息。The periodic channel element is used for periodically transmitting messages on the channel.

在一些实施方式中,所述模块元素包括:变量声明和进程定义两个部分;其中,In some implementations, the module element includes: two parts: variable declaration and process definition; wherein,

所述变量声明用于声明在模块中使用到的变量;The variable declaration is used to declare the variables used in the module;

所述进程定义用于通过进程表示模块的执行行为。The process definition is used to represent the execution behavior of the module through the process.

下面结合附图3、4对本发明实施例提供的一个具体实施例进行说明,图3示出了本发明实施方式所提供的符合IEC 61131-3编程语言规范的一个梯形图的示意图,图4示出了本发明实施方式所提供的根据图3提供的梯形图转换得到的AOV图的示意图,结合前述具体实施方式中对梯形图转换模块102及梯形图转换步骤S102的描述,利用本发明实施例提供的可编程逻辑控制器编程语言转换系统10对梯形图进行转换的过程如下:A specific embodiment provided by the embodiment of the present invention will be described below in conjunction with accompanying drawings 3 and 4. Fig. 3 shows a schematic diagram of a ladder diagram conforming to the IEC 61131-3 programming language specification provided by the embodiment of the present invention, and Fig. 4 shows A schematic diagram of the AOV map obtained by converting the ladder diagram provided in FIG. 3 provided in the embodiment of the present invention is shown, and in combination with the description of the ladder diagram conversion module 102 and the ladder diagram conversion step S102 in the foregoing specific embodiments, the embodiment of the present invention is used The process that the provided PLC programming language conversion system 10 converts the ladder diagram is as follows:

步骤S1:通过对梯形图导出的PLCOpen XML进行解析,从而得到相应的梯形图数据结构。Step S1: Obtain the corresponding ladder diagram data structure by parsing the PLCOpen XML exported from the ladder diagram.

步骤S2:根据梯形图数据结构之间的关系,得到如图4所示的AOV图,AOV图可表示为一个有向图G(V,E),其中V节点集合表示任务或者行为活动,E边集合表示这些任务之间的优先级关系,任意一个节点vi到vj的关系,可以使用节点对(vi,vj)表示,任意节点v的前驱节点比节点v的优先级高。Step S2: According to the relationship between the data structures of the ladder diagram, the AOV graph shown in Figure 4 is obtained. The AOV graph can be expressed as a directed graph G(V, E), where the set of V nodes represents tasks or behaviors, and E The edge set represents the priority relationship between these tasks. The relationship between any node vi and vj can be represented by a node pair (vi, vj). The predecessor node of any node v has a higher priority than node v.

步骤S3:在AOV图(图4)的基础上根据拓扑排序算法进行排序,可得到的序列为(n1,n2,n5,n6,n7,n10,n11,n8,n12,n13,n15,n14,n3,n9,n4)。Step S3: On the basis of the AOV graph (Figure 4), sort according to the topological sorting algorithm, and the sequence that can be obtained is (n1,n2,n5,n6,n7,n10,n11,n8,n12,n13,n15,n14, n3,n9,n4).

为了说明梯形图的转换效果,拟列出如下梯形图转换规则,通过顺序遍历上述拓扑排序、并应用如下规则产生最终的ICIL语言表达式:In order to illustrate the conversion effect of the ladder diagram, the following ladder diagram conversion rules are proposed, and the final ICIL language expression is generated by sequentially traversing the above-mentioned topological sorting and applying the following rules:

1)若当前节点为拓扑排序中的第一个节点,则当前产生的操作符为空,即操作符为“”;1) If the current node is the first node in the topological sort, the currently generated operator is empty, that is, the operator is "";

2)若当前节点与上一个节点位于同一行,则当前产生的操作符为“&&”;2) If the current node is on the same line as the previous node, the currently generated operator is "&&";

3)若当前节点与上一个节点不位于同一行,且在AOV图中,存在上一个节点到当前节点的连接线,则当前操作符为“&&”;3) If the current node is not on the same line as the previous node, and there is a connection line from the previous node to the current node in the AOV diagram, the current operator is "&&";

4)若当前节点与上一个节点不位于同一行,且在AOV图中,不存在上一个节点到当前节点的连接线,则当前操作符为“||”。4) If the current node is not located in the same row as the previous node, and there is no connecting line from the previous node to the current node in the AOV graph, then the current operator is "||".

步骤S4:通过应用上述规则遍历上述拓扑序列,得到最终的ICIL语句为n4=n1&&n2||n5&&n6&&n7||n10&&n11||n12&&n13||n15&&n14&&n3||n9;Step S4: Traverse the above topological sequence by applying the above rules, and obtain the final ICIL statement as n4=n1&&n2||n5&&n6&&n7||n10&&n11||n12&&n13||n15&&n14&&n3||n9;

步骤S5:通过剪枝算法对AOV图进行剪枝操作,并在此基础上利用优先级计算算法计算上一步中表达式的计算优先级,从而得到如下ICIL语句:Step S5: Pruning the AOV graph through the pruning algorithm, and on this basis, using the priority calculation algorithm to calculate the calculation priority of the expression in the previous step, so as to obtain the following ICIL statement:

n4=(n1&&n2||n5&&((n6&&n7||n10&&n11)&&n8||n12&&(n13||n15)&&n14))&&(n3||n9)。n4=(n1&&n2||n5&&((n6&&n7||n10&&n11)&&n8||n12&&(n13||n15)&&n14))&&(n3||n9).

以上,为本发明实施例所提供的可编程逻辑控制器编程语言转换方法的示例性说明,本发明提出的可编程逻辑控制器编程语言转换方法能够实现IEC61131-3语言的统一转换,在不同厂商的PLC产品上进行开发和移植过程中,不必分别针对每种PLC语言编写相应的移植代码;此外,本发明提出的形式化建模语言ICIL及其转换方法,有利于后续深入开展基于该中间语言的形式化建模、分析及验证工作,由于IEC 61131-3标准本身没有提出过相应的形式化验证方法,因此本发明对提高关键领域工控程序的安全性和可靠性具有重要意义,在PLC编程环境中具有广阔应用前景;另外,本发明提出的形式化建模语言ICIL有利于未来统一PLC编程开发语言。The above is an exemplary description of the programmable logic controller programming language conversion method provided by the embodiment of the present invention. The programmable logic controller programming language conversion method proposed by the present invention can realize the unified conversion of the IEC61131-3 language, and can be used by different manufacturers. In the process of developing and transplanting on PLC products, it is not necessary to write corresponding transplanting codes for each PLC language; in addition, the formal modeling language ICIL and its conversion method proposed by the present invention are conducive to subsequent in-depth development based on the intermediate language Since the IEC 61131-3 standard itself has not proposed a corresponding formal verification method, the present invention is of great significance for improving the safety and reliability of industrial control programs in key areas. In PLC programming It has broad application prospects in the environment; in addition, the formalized modeling language ICIL proposed by the present invention is beneficial to unifying the PLC programming development language in the future.

需要说明的是,附图中的流程图和框图显示了根据本发明的多个实施例的系统、方法和计算机程序产品的可能实现的体系架构、功能和操作。在这点上,流程图或框图中的每个方框可以代表一个模块、程序段或代码的一部分,所述模块、程序段或代码的一部分包含一个或多个用于实现规定的逻辑功能的可执行指令。也应当注意,在有些作为替换的实现中,方框中所标注的功能也可以以不同于附图中所标注的顺序发生。例如,两个连续的方框实际上可以基本并行地执行,它们有时也可以按相反的顺序执行,这依所涉及的功能而定。也要注意的是,框图和/或流程图中的每个方框、以及框图和/或流程图中的方框的组合,可以用执行规定的功能或动作的专用的基于硬件的系统来实现,或者可以用专用硬件与计算机指令的组合来实现。It should be noted that the flowcharts and block diagrams in the accompanying drawings show the architecture, functions and operations of possible implementations of systems, methods and computer program products according to multiple embodiments of the present invention. In this regard, each block in a flowchart or block diagram may represent a module, program segment, or part of code that includes one or more Executable instructions. It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks in succession may, in fact, be executed substantially concurrently, or they may sometimes be executed in the reverse order, depending upon the functionality involved. It should also be noted that each block of the block diagrams and/or flowchart illustrations, and combinations of blocks in the block diagrams and/or flowchart illustrations, can be implemented by a dedicated hardware-based system that performs the specified function or action , or may be implemented by a combination of dedicated hardware and computer instructions.

所属领域的技术人员可以清楚地了解到,为描述的方便和简洁,上述描述的系统、装置和单元的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。Those skilled in the art can clearly understand that for the convenience and brevity of the description, the specific working process of the above-described system, device and unit can refer to the corresponding process in the foregoing method embodiment, which will not be repeated here.

在本发明所提供的几个实施例中,应该理解到,所揭露的装置和方法,可以通过其它的方式实现。以上所描述的装置实施例仅仅是示意性的,例如,所述单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,又例如,多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些通信接口,装置或单元的间接耦合或通信连接,可以是电性,机械或其它的形式。In the several embodiments provided by the present invention, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are only illustrative. For example, the division of the units is only a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components can be combined or May be integrated into another system, or some features may be ignored, or not implemented. In another point, the mutual coupling or direct coupling or communication connection shown or discussed may be through some communication interfaces, and the indirect coupling or communication connection of devices or units may be in electrical, mechanical or other forms.

所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部单元来实现本实施例方案的目的。The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place, or may be distributed to multiple network units. Part or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.

另外,在本发明各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。In addition, each functional unit in each embodiment of the present invention may be integrated into one processing unit, each unit may exist separately physically, or two or more units may be integrated into one unit.

所述功能如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本发明的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行本发明各个实施例所述方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(ROM,Read-Only Memory)、随机存取存储器(RAM,Random Access Memory)、磁碟或者光盘等各种可以存储程序代码的介质。If the functions described above are realized in the form of software function units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the essence of the technical solution of the present invention or the part that contributes to the prior art or the part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including Several instructions are used to make a computer device (which may be a personal computer, a server, or a network device, etc.) execute all or part of the steps of the methods described in various embodiments of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), magnetic disk or optical disk and other media that can store program codes. .

最后应说明的是:以上各实施例仅用以说明本发明的技术方案,而非对其限制;尽管参照前述各实施例对本发明进行了详细的说明,本领域的普通技术人员应当理解:其依然可以对前述各实施例所记载的技术方案进行修改,或者对其中部分或者全部技术特征进行等同替换;而这些修改或者替换,并不使相应技术方案的本质脱离本发明各实施例技术方案的范围,其均应涵盖在本发明的权利要求和说明书的范围当中。Finally, it should be noted that: the above embodiments are only used to illustrate the technical solutions of the present invention, rather than limiting them; although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that: It is still possible to modify the technical solutions described in the foregoing embodiments, or perform equivalent replacements for some or all of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the technical solutions of the various embodiments of the present invention. All of them should be covered by the scope of the claims and description of the present invention.

Claims (10)

1. A method for converting a programming language of a Programmable Logic Controller (PLC), comprising:
an abstract syntax tree conversion step, which is to convert the text PLC programming language into an abstract syntax tree;
a ladder diagram conversion step, converting the ladder diagram into an ICIL intermediate structure;
a functional block diagram conversion step, namely converting the functional block diagram into an ICIL intermediate structure;
a sequence function table diagram conversion step, namely converting the sequence function table diagram into an ICIL intermediate structure;
a step of structural text conversion, which is to convert an abstract syntax tree obtained according to the structural text conversion into an ICIL intermediate structure;
an instruction table conversion step, namely converting the abstract syntax tree obtained by conversion according to the instruction table into an ICIL intermediate structure;
and an ICIL intermediate structure conversion step, namely converting the ICIL intermediate structure into an ICIL program.
2. The PLC programming language conversion method according to claim 1, wherein the abstract syntax tree conversion step converts the inputted text-based PLC programming language into an abstract syntax tree by lexical analysis and syntactic analysis, using a text-based PLC programming language as an input;
wherein the text type PLC programming language comprises: a structured text language or an instruction sheet language.
3. The plc programming language conversion method according to claim 1, wherein the ladder diagram conversion step includes: the method comprises the steps of multi-coil decomposition, scanning sequence calculation, node logic relationship calculation and expression priority calculation; wherein,
the multi-coil decomposition step, the scanning sequence calculation step, the node logic relationship calculation step and the expression priority calculation step are respectively used for carrying out multi-coil step decomposition, node scanning sequence calculation, node logic relationship calculation and ladder diagram expression priority calculation.
4. The plc programming language conversion method according to claim 1, wherein the function block diagram conversion step includes: a function block diagram analyzing step and a function block diagram conversion rule step;
the function block diagram parsing step is to parse the PLCOpen XML file corresponding to the function block diagram program into a first data structure, where the first data structure includes: function block programs, function block networks, function blocks and network input/output connection data;
and the step of the functional block diagram conversion rule is used for converting the first data structure output by the step of analyzing the functional block diagram into an ICIL intermediate structure according to the functional block conversion rule and the network expression input and output rule.
5. The plc programming language conversion method according to claim 1, wherein the sequential function chart conversion step includes: a step of analyzing a sequential function table diagram and a step of converting the sequential function table diagram into rules;
analyzing the sequence function table diagram, namely analyzing the PLCOPenXML file corresponding to the sequence function table diagram program into a second data structure, wherein the second data structure comprises: step, action block, migration, concurrent branch structure, concurrent merge structure, selective branch structure and selective merge structure;
and the step of converting the sequential function table diagram into a rule, namely converting the second data structure into an ICIL intermediate structure according to a step conversion rule and an action block conversion rule.
6. The plc programming language conversion method according to claim 1, wherein the structured text conversion step converts the abstract syntax tree generated by the abstract syntax tree conversion step according to a structured text language into an ICIL intermediate structure according to the structured text conversion rule.
7. The plc programming language conversion method according to claim 1, wherein the instruction table conversion step converts the abstract syntax tree generated by the instruction table language in the abstract syntax tree conversion step into the ICIL intermediate structure, specifically according to the instruction table conversion rule.
8. The method for converting programming languages of a programmable logic controller according to claim 1, wherein the ICIL intermediate structure converting step specifically includes parsing the ICIL intermediate structure, and generating a code in the ICIL program according to a result of the parsing.
9. The method for converting programming languages of a programmable logic controller according to any one of claims 1 to 8, wherein the ICIL is an intermediate language of the industrial controller that is extended based on a CSP language, and the extension content of the ICIL includes a module element, a statement element, and a periodic channel element; wherein,
the module elements are used for unifying the definition of the program organization unit in IEC61131-3 to express the calling and running of functions, function blocks and programs in the original PLC programming language through the calling and running of the module;
the statement element is used for expressing assignment operation and module calling operation;
and the periodic channel element is used for periodically transmitting the messages on the channel.
10. The plc programming language conversion method according to claim 9, wherein the module element includes: variable declaration and process definition; wherein,
the variable declaration is used for declaring variables used in the module;
the process definition is used to represent the execution behavior of the module by the process.
CN201810609274.9A 2018-06-13 2018-06-13 Programmable logic controller programming language conversion method Active CN109032056B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201810609274.9A CN109032056B (en) 2018-06-13 2018-06-13 Programmable logic controller programming language conversion method

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201810609274.9A CN109032056B (en) 2018-06-13 2018-06-13 Programmable logic controller programming language conversion method

Publications (2)

Publication Number Publication Date
CN109032056A true CN109032056A (en) 2018-12-18
CN109032056B CN109032056B (en) 2020-01-10

Family

ID=64609574

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201810609274.9A Active CN109032056B (en) 2018-06-13 2018-06-13 Programmable logic controller programming language conversion method

Country Status (1)

Country Link
CN (1) CN109032056B (en)

Cited By (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
EP3715975A1 (en) * 2019-03-28 2020-09-30 Mitsubishi Electric R&D Centre Europe B.V. Method and apparatus for analysing a programmable logic controller program
CN113433885A (en) * 2021-07-22 2021-09-24 上海繁易信息科技股份有限公司 Method for converting ladder diagram of PLC programming system into structured text
EP3889703A1 (en) * 2020-03-31 2021-10-06 Mitsubishi Electric R&D Centre Europe B.V. Method and apparatus for expressing and verifying functional specifications of a programmable logic controller program
CN115291853A (en) * 2022-10-09 2022-11-04 浙江中控研究院有限公司 Method and device for exporting and importing LD (laser diode) language in PLC (programmable logic controller) programming software
CN115391173A (en) * 2022-07-06 2022-11-25 北京交通大学 Method for converting Simulink-Stateflow model into NuSMV model
CN119415097A (en) * 2024-10-31 2025-02-11 重庆邮电大学 A method for converting PLC ladder diagram into instruction table
CN119689969A (en) * 2024-12-20 2025-03-25 浙江中控信息产业股份有限公司 Programming method, device and storage medium of programmable logic controller

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101382783A (en) * 2007-09-03 2009-03-11 台达电子工业股份有限公司 Program machine code compiling method for programmable logic controller
US20100245857A1 (en) * 2009-03-27 2010-09-30 Konica Minolta Systems Laboratory, Inc. Systems and Methods for Processing Color Data
CN101957745A (en) * 2009-07-16 2011-01-26 沈阳高精数控技术有限公司 Method for converting ladder diagram language into structure text language
JP2011108070A (en) * 2009-11-19 2011-06-02 Koyo Electronics Ind Co Ltd Scale transformation method of analog data
CN104503816A (en) * 2014-12-30 2015-04-08 西安电子科技大学 System for automatically converting hardware language VHDL (Vhsic Hardware Description Language) into MSVL (Modeling, Simulation and Verification Language)
CN104977892A (en) * 2014-04-10 2015-10-14 株式会社捷太格特 Programming assist device for programmable logic controller program and programming assist method for the program

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101382783A (en) * 2007-09-03 2009-03-11 台达电子工业股份有限公司 Program machine code compiling method for programmable logic controller
US20100245857A1 (en) * 2009-03-27 2010-09-30 Konica Minolta Systems Laboratory, Inc. Systems and Methods for Processing Color Data
CN101957745A (en) * 2009-07-16 2011-01-26 沈阳高精数控技术有限公司 Method for converting ladder diagram language into structure text language
JP2011108070A (en) * 2009-11-19 2011-06-02 Koyo Electronics Ind Co Ltd Scale transformation method of analog data
CN104977892A (en) * 2014-04-10 2015-10-14 株式会社捷太格特 Programming assist device for programmable logic controller program and programming assist method for the program
CN104503816A (en) * 2014-12-30 2015-04-08 西安电子科技大学 System for automatically converting hardware language VHDL (Vhsic Hardware Description Language) into MSVL (Modeling, Simulation and Verification Language)

Cited By (13)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2020195313A1 (en) * 2019-03-28 2020-10-01 Mitsubishi Electric Corporation Method, computer program and apparatus for analysing a programmable logic controller program
CN113632018A (en) * 2019-03-28 2021-11-09 三菱电机株式会社 Method, computer program and device for analyzing a programmable logic controller program
EP3715975A1 (en) * 2019-03-28 2020-09-30 Mitsubishi Electric R&D Centre Europe B.V. Method and apparatus for analysing a programmable logic controller program
CN115398358B (en) * 2020-03-31 2025-06-06 三菱电机株式会社 Method for analyzing a programmable logic controller program
EP3889703A1 (en) * 2020-03-31 2021-10-06 Mitsubishi Electric R&D Centre Europe B.V. Method and apparatus for expressing and verifying functional specifications of a programmable logic controller program
WO2021199552A1 (en) * 2020-03-31 2021-10-07 Mitsubishi Electric Corporation Method for analyzing a programmable logic controller program
CN115398358A (en) * 2020-03-31 2022-11-25 三菱电机株式会社 Method for analyzing a programmable logic controller program
CN113433885A (en) * 2021-07-22 2021-09-24 上海繁易信息科技股份有限公司 Method for converting ladder diagram of PLC programming system into structured text
CN115391173A (en) * 2022-07-06 2022-11-25 北京交通大学 Method for converting Simulink-Stateflow model into NuSMV model
CN115291853A (en) * 2022-10-09 2022-11-04 浙江中控研究院有限公司 Method and device for exporting and importing LD (laser diode) language in PLC (programmable logic controller) programming software
CN119415097A (en) * 2024-10-31 2025-02-11 重庆邮电大学 A method for converting PLC ladder diagram into instruction table
CN119415097B (en) * 2024-10-31 2025-10-21 重庆邮电大学 A method for converting PLC ladder diagram into instruction table
CN119689969A (en) * 2024-12-20 2025-03-25 浙江中控信息产业股份有限公司 Programming method, device and storage medium of programmable logic controller

Also Published As

Publication number Publication date
CN109032056B (en) 2020-01-10

Similar Documents

Publication Publication Date Title
CN109143952B (en) Programmable logic controller programming language conversion system
CN109032056B (en) Programmable logic controller programming language conversion method
CN106648662B (en) Report generation device and method based on project cost calculation description language BCL
US20220066409A1 (en) Method and system for generating an artificial intelligence model
Julius et al. Transformation of GRAFCET to PLC code including hierarchical structures
CN108037913B (en) Conversion method from xUML4MC model to MSVL language program, computer readable storage medium
Cengic et al. On formal analysis of IEC 61499 applications, Part A: Modeling
CN106371887A (en) System and method for MSVL compiling
CN108446218A (en) A kind of automatic Verification device of structured text program
CN110825433B (en) Design method of edge control equipment
CN111208991A (en) Workflow-based program development method, electronic device, and storage medium
CN110347588B (en) Software verification method, device, computer equipment and storage medium
CN118760042A (en) A method for automatically generating PLC control code based on SysML model
Kamburjan et al. A hybrid programming language for formal modeling and verification of hybrid systems
Gotti et al. UML executable: A comparative study of UML compilers and interpreters
Schönberger et al. Algorithmic support for model transformation in object‐oriented software development
CN117519850B (en) AI model arranging method and device, electronic equipment and medium
Werner et al. From iec 61131-3 function block diagrams to sequentially constructive statecharts
Lee et al. Object oriented BDD and executable human-language module specification
CN118551555A (en) Graphical modeling method and device based on discrete event simulation engine
CN118426764A (en) Flow chart language and code interconversion, system, electronic device and storage medium
CN117312153A (en) Code static detection methods, tools, devices, storage media and equipment
Dust et al. A model-based approach to automation of formal verification of ROS 2-based systems
Shiratori et al. Using artificial intelligence in communication system design
CN115097776A (en) PLC sequential function flow chart language implementation system and implementation method

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant
TR01 Transfer of patent right

Effective date of registration: 20210806

Address after: Room 801, no.6, Lane 600, Yunling West Road, Putuo District, Shanghai 200062

Patentee after: SHANGHAI FORMAL TECH INFORMATION TECHNOLOGY Co.,Ltd.

Address before: 200062 No. 3663, Putuo District, Shanghai, Zhongshan North Road

Patentee before: EAST CHINA NORMAL University

Patentee before: SHANGHAI FORMAL TECH INFORMATION TECHNOLOGY Co.,Ltd.

TR01 Transfer of patent right