Method for embedding C language into PLC ladder diagram

文档序号:1936766 发布日期:2021-12-07 浏览:21次 中文

阅读说明:本技术 一种在plc梯形图中内嵌入c语言的方法 (Method for embedding C language into PLC ladder diagram ) 是由 龙敦梅 于 2021-09-09 设计创作,主要内容包括:本发明公开了PLC领域的一种在PLC梯形图中内嵌入C语言的方法,包括在组态软件里提供一个C语言函数的编写界面,使用编译工具将C语言的编译成可以在嵌入式系统里头使用的机器语言,并获取到C函数的入口地址;使用组态软件将生成的机器码与映射关系下载到PLC;在PLC中,将机器码放入相应的物理地址,然后通过分散加载的方式加载入了PLC;用户程序在PLC的梯形图调用C语言函数时,PLC通过下载的映射关系得到C函数的入口地址,并将入口地址转换成函数指针,通过函数指针跳转到用户C函数中执行,该在PLC梯形图中内嵌入C语言的方法,使得用户可在PLC系统中通过C语言进行复杂的算法,运行效率高,简化了编程,无需重新开发编译器系统和移植开源编译器。(The invention discloses a method for embedding C language in a PLC ladder diagram in the field of PLC, which comprises the steps of providing a compiling interface of a C language function in configuration software, compiling the C language into a machine language which can be used in an embedded system by using a compiling tool, and acquiring an entry address of the C function; downloading the generated machine code and the mapping relation to a PLC by using configuration software; in the PLC, the machine code is put into a corresponding physical address, and then the machine code is loaded into the PLC in a scattered loading mode; when a user program calls a C-language function in a ladder diagram of the PLC, the PLC obtains an entry address of the C-function through a downloaded mapping relation, converts the entry address into a function pointer, jumps to the C-function of the user through the function pointer and executes the C-language function.)

1. A method for embedding C language in PLC ladder diagram is characterized in that: the method comprises the following steps:

the method comprises the following steps: providing a compiling interface of a C language function in configuration software, compiling the C language into a machine language which can be used in an embedded system by using a compiling tool, and acquiring an entry address of the C function;

step two: downloading the generated machine code and the mapping relation to a PLC by using configuration software;

step three: in the PLC, the machine code is put into a corresponding physical address, which is equivalent to that a program written by a user is regarded as a part of PLC firmware, and then the PLC is loaded in a scattered loading mode;

step four: when the user program calls the C language function in the ladder diagram of the PLC, the PLC obtains the entry address of the C function through the downloaded mapping relation, converts the entry address into a function pointer, and jumps to the user C function through the function pointer for execution.

2. The method of claim 1, wherein the language C is embedded in the PLC ladder diagram, and the method comprises the following steps: providing a C language function writing interface in the first step, wherein the specific flow comprises the following steps: and providing a C function writing interface, then writing a C function by a user, and finally calling the C function in the ladder diagram.

Technical Field

The invention relates to the field of PLC (programmable logic controller), in particular to a method for embedding C language in a PLC ladder diagram.

Background

The Programmable Logic Controller (PLC) and the industrial control field have wide application, the Ladder Diagram (LD) is the programming language which is most used by the PLC, has the advantages of simple use, intuition and clearness, but is not suitable for realizing complex algorithm, the C language has high operation efficiency compared with the ladder diagram language, when the relatively complex algorithm is made, the programming is relatively simple, the C language is added into the PLC to be executed, the C language is required to be converted into machine codes, the steps of 1 Preprocessing (Preprocessing),2 compiling (compiling), 3 assembling (assembling), 4 Linking (Linking) and the like are required, namely, a compiler system is required to be made by the user, the engineering quantity is huge, and if a main chip needs to be replaced, the compiler system needs to be redeveloped, if the open source compiler such as Gcc and the like is transplanted into PLC firmware, the Gcc code quantity is huge, the transplanting difficulty is high, the sizes of the PLC RAM and the ROM are increased, the hardware cost of the PLC is increased, and therefore a method for embedding C language in a PLC ladder diagram is provided.

Disclosure of Invention

The invention aims to provide a method for embedding C language in a PLC ladder diagram, which aims to solve the problems of large engineering quantity of redevelopment of a compiling system, high transplanting difficulty and hardware cost increase in the background technology.

In order to achieve the purpose, the invention provides the following technical scheme: a method for embedding C language in a PLC ladder diagram comprises the following steps:

the method comprises the following steps: providing a compiling interface of a C language function in configuration software, compiling the C language into a machine language which can be used in an embedded system by using a compiling tool, and acquiring an entry address of the C function;

step two: downloading the generated machine code and the mapping relation to a PLC by using configuration software;

step three: in the PLC, the machine code is put into a corresponding physical address, which is equivalent to that a program written by a user is regarded as a part of PLC firmware, and then the PLC is loaded in a scattered loading mode;

step four: when the user program calls the C language function in the ladder diagram of the PLC, the PLC obtains the entry address of the C function through the downloaded mapping relation, converts the entry address into a function pointer, and jumps to the user C function through the function pointer for execution.

Preferably, the step one provides a writing interface of a C language function, and the specific flow includes: and providing a C function writing interface, then writing a C function by a user, and finally calling the C function in the ladder diagram.

Compared with the prior art, the invention has the beneficial effects that: according to the method for embedding the C language into the PLC ladder diagram, the C language is compiled into the machine language which can be used in the PLC system by using the compiling tool, and the C language is embedded into the PLC ladder diagram, so that a user can carry out a complex algorithm in the PLC system through the C language, the operation efficiency is high, the programming is simplified, and the compiler system does not need to be re-developed and the open source compiler does not need to be transplanted.

Drawings

FIG. 1 is a schematic flow chart of the method of the present invention.

Detailed Description

The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.

The invention provides a method for embedding C language in a PLC ladder diagram, please refer to FIG. 1, which comprises the following steps;

the method comprises the following steps: providing a compiling interface of a C language function in configuration software, compiling the C language into a machine language which can be used in an embedded system by using a compiling tool, and acquiring an entry address of the C function;

step two: downloading the generated machine code and the mapping relation to a PLC by using configuration software;

step three: in the PLC, the machine code is put into a corresponding physical address, which is equivalent to that a program written by a user is regarded as a part of PLC firmware, and then the PLC is loaded in a scattered loading mode;

step four: when the user program calls the C language function in the ladder diagram of the PLC, the PLC obtains the entry address of the C function through the downloaded mapping relation, converts the entry address into a function pointer, and jumps to the user C function through the function pointer for execution.

Wherein, a C language function writing interface is provided in the first step, and the specific flow comprises: and providing a C function writing interface, then writing a C function by a user, and finally calling the C function in the ladder diagram.

In summary, in the present invention, the C language is compiled into the machine language that can be used in the PLC system by using the compiling tool, and the C language is embedded in the PLC ladder diagram, so that the user can perform a complex algorithm in the PLC system through the C language, the operation efficiency is high, the programming is simplified, and it is not necessary to re-develop the compiler system and transplant the open source compiler.

It is noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus.

While the invention has been described above with reference to an embodiment, various modifications may be made and equivalents may be substituted for elements thereof without departing from the scope of the invention. In particular, the various features of the embodiments disclosed herein may be used in any combination, provided that there is no structural conflict, and the combinations are not exhaustively described in this specification merely for the sake of brevity and conservation of resources. Therefore, it is intended that the invention not be limited to the particular embodiments disclosed, but that the invention will include all embodiments falling within the scope of the appended claims.

5页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:还款计划生成方法及系统

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!