CN102393670A - Method for realizing hybrid programming by embedding high-level language into ladder diagram - Google Patents
Method for realizing hybrid programming by embedding high-level language into ladder diagram Download PDFInfo
- Publication number
- CN102393670A CN102393670A CN2011103248683A CN201110324868A CN102393670A CN 102393670 A CN102393670 A CN 102393670A CN 2011103248683 A CN2011103248683 A CN 2011103248683A CN 201110324868 A CN201110324868 A CN 201110324868A CN 102393670 A CN102393670 A CN 102393670A
- Authority
- CN
- China
- Prior art keywords
- ladder diagram
- level language
- instruction
- plc
- module
- 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.)
- Pending
Links
Images
Landscapes
- Devices For Executing Special Programs (AREA)
- Programmable Controllers (AREA)
Abstract
The invention relates to a method for realizing hybrid programming by embedding a high-level language into a ladder diagram. In the method, a high-level language program taken as a module is inserted into the ladder diagram, and the inserted grogram module is stored in a file in a function type. The high-level language program file and a machine instruction code generated by the ladder diagram program are compiled into an executable file to be downloaded on a PLC (Programmable Logic Controller). In running, the high-level language program module is called from a machine instruction generated by the ladder diagram program so as to execute the high-level language program module. By embedding the algorithm module compiled by the high-level computer language in the ladder diagram, the method solves the problem that a complicated algorithm is difficult to realize; and by utilizing the advantages of stability and reliability of the ladder diagram, the development efficiency of a complicated control system is enhanced, and the aim of enhancing the functions of the ladder diagram can be realized by embedding an intelligent algorithm at the same time.
Description
Technical field
The invention belongs to the computer information technology field, relate to the implementation method that a kind of trapezoidal pattern embedded higher level lanquage is carried out hybrid programming.
Background technology
PLC has a wide range of applications at industrial control field for a long time, and ladder diagram is the main means of PLC program design, has to use simply simple and clear advantage.Yet PLC is used for logic control, so ladder diagram the time is simple and easy to usefulness carrying out the logic control program design, but along with the controlled device function becomes increasingly complex, simple logic control can't have been satisfied the needs of device control.Therefore in order to satisfy the actual needs that strengthens the PLC function, often need in original logic control, increase intelligent algorithm, but the process of ladder diagram implementation algorithm is too complicated.Computer advanced programming language (like the C language) has powerful characteristics when writing algorithm.Therefore if can the algorithm that the computer advanced programming language is write be embedded ladder diagram,, can strengthen the ladder diagram function with the ability that greatly improves the ladder diagram algorithm design.The intellectuality that can be apparatus control system through this technology offers convenience.
Summary of the invention
The objective of the invention is to be fit to realize the logic control program design to existing ladder diagram; And complicated algorithm realizes difficulty; For it provides a kind of trapezoidal pattern embedded method that computer advanced language is realized hybrid programming of going into; Realization embeds ladder diagram with the algoritic module of high level language, is reached the purpose that strengthens the ladder diagram function by calling of ladder diagram implementation algorithm module.
The technical scheme that technical solution problem of the present invention is taked is:
1. a trapezoidal pattern embedded higher level lanquage is carried out the implementation method of hybrid programming, it is characterized in that this method may further comprise the steps:
Step 1-1. increases an algoritic module control newly and it is added in the ladder diagram design environment, in use the algoritic module control is dragged to the position that needs the insertion algorithm module, and provides the function name that need call;
Step 1-2. is edit high-grade language module code hereof, and the function name of describing in function name and the ladder diagram algoritic module control must be consistent; All functions all do not have the shape ginseng, and data transfer is accomplished through public data area;
The pre-service of step 2. high-level language programs, specifically:
The data field is distributed among the step 2-1.PLC;
In the internal memory of PLC; Select the public data area of a special use to represent PLC soft element value; In the PLC engine program, defined a byte arrays and be used for representing this special-purpose public data area, shown the start address of Various types of data district in public data area through macro sheet;
Step 2-2. conversion byte categorical data
Byte categorical data in the program is converted to the mode of accessed data;
Step 2-3. converted categorical data
Position categorical data operation comprises assignment and place value judgement; For assign operation, assignment 0 and 1 is realizing with computing and exclusive disjunction through the position respectively;
The value of position judges through will corresponding position and 1 work and computing, the value that other is done with 0 and the result of computing judges;
Step 2-4. writes file with pretreated high-level language programs, thereby generates the high-level language programs file;
Step 3-1. converts the IL instruction to
In the IL instruction set, increase the algoritic module call instruction, convert trapezoid figure program to the IL instruction then;
Step 3-2. definition is used for the grand of translation algorithm module invokes instruction, and the grand shape ginseng that has is changed into the function name that need call by instance using when grand; The machine instruction that adopts PLC to support in the macro body of a definition realizes;
Step 3-3. generates machine instruction that PLC support through macro substitution with IL instruction translation Cheng Hong before compiling, specifically:
At first travel through all IL instructions, then the IL instruction translation is become the grand of correspondence, before compiling, realize macro substitution automatically by compiler;
Step 3-4. code compile
Compiler through any support target platform is unified compiling to the machine instruction set and the higher-level language code that generate, and the executable file after the compiling downloads among the PLC and can move.SHAPE \*?MERGEFORMAT
The invention has the beneficial effects as follows: through going into the algoritic module of writing by computer advanced language trapezoidal pattern embedded; Overcome the problem that complicated algorithm realizes difficulty; Utilized the reliable and stable advantage of ladder diagram simultaneously; Not only can improve the development efficiency of complex control system, and can reach the purpose that strengthens the ladder diagram function through embedding intelligent algorithm.
Description of drawings
Fig. 1 is trapezoidal pattern embedded to go into the method synoptic diagram that higher level lanquage is carried out hybrid programming;
Fig. 2 higher level lanquage and ladder diagram are through the synoptic diagram of public data area interaction data;
Function call implementation procedure synoptic diagram in Fig. 3 ladder diagram.
Embodiment
Of the present inventionly a kind ofly trapezoidal pattern embeddedly go into high-level programming language and realize hybrid programming, the method for unified compiling, its thought is that high-level language programs is inserted into ladder diagram as module, the program module of insertion is deposited hereof with functional form, and is as shown in Figure 1.High-level language programs file and be compiled into executable file together by the machine instruction code that trapezoid figure program generates and download to PLC.During operation, in the machine instruction that generates by trapezoid figure program, call the high-level language programs module, realize the execution of high-level language programs module.Be the implementation procedure of example illustration method below with the C language, concrete design procedure is following:
1, increases the high-level language programs module with the control mode in the ladder diagram design environment
1.1, a newly-increased graphical control and it is added in the ladder diagram design environment, be used for representing the high-level language programs module.In use high-level language programs module control is dragged to the position that needs to insert high-level language programs, and provides the function name that need call;
1.2, edit high-grade LISP program LISP hereof, the function name that provides in function name and the step 1.1 high-level language programs module control must be consistent.All functions all do not have the shape ginseng, and data transfer is accomplished through public data area, and promptly high-level language programs and trapezoid figure program all directly use the D district data in the PLC public data area to realize exchanges data, and be as shown in Figure 2.When writing function body, can define temporary variable, also can directly use D district data, must indicate data length during use.Function as with C language syntax and func by name is an example, and form is following:
#ifdef funcFlag
void?func()
{
if(M1000==1)
{
?(DWORD)VD2000?=?(DWORD)VD2000+1;
}
}
#endif
For convenient programming, also can use the mode of temporary variable to represent D district data, at first give temporary variable D district data value assignment, write back the data field to the temporary variable value again after having operated.Above-mentioned example can change to:
#ifdef funcFlag
void?func()
{
int?para1;
para1?=?(DWORD)VD2000;
if(M1000==1)
{
?para1++;
}
(DWORD)VD2000=para1;
}
#endif
FuncFlag is a macro definition in the last example, and form is " function name+Flag ", is used for realization condition compiling.When function is called in ladder diagram, grand funcFlag will be defined in header file, realize the compiling of called function.
VD2000 is the data address in D district among the PLC, the The data scale-of-eight of PLC, so VD2000 representes 1024 bytes of relative D district start address skew, and DWORD representes double word, expression begins to get 4 bytes from the address of VD2000.M1000 is a bit address.The content relevant with address function introduced in the back in detail.
2, high-level language programs pre-service
Before the trapezoid figure program compiling that embeds the high-level language programs module, need the high-level language programs code is carried out pre-service, mainly the plc data district data-switching of using in the high-level language programs is become to meet the data access mode of higher level lanquage syntax gauge.Be that example is explained preprocessing process with D district and M district below, concrete performing step is:
2.1, the data field is distributed among the PLC
In the internal memory of PLC; There is the public data area of a special use to represent PLC soft element value; A byte arrays CASSMem of definition [Length] representes this special-purpose public data area in the PLC engine program, is illustrated in the start addresses in public data area such as D district in the public data area, M district, C district, T district and S district through grand DStart, MStart, CStart, TStart, SStart.
Because the least unit of data is bytes in the byte arrays, therefore for bit data except the address offset amount, also need specified bytes bias internal amount.Like M2001 is the abbreviation of M200.1, and expression is with respect to squint the 1st of 128 bytes (128 are the value of octal numeral 200) data of M district start address.
2.2, conversion byte categorical data
Convert byte categorical data in the program to the accessed data mode, the purpose that converts the address to is in order to solve the length issue when fetching data.Total BYTE in program, WORD, three types of data types of DWORD are represented 1 byte respectively, 2 bytes and 4 byte datas.When conversion, convert char * respectively to, short * and int * type pointer, and through the pointer data.Like (DWORD) VD2000, will convert * ((int *) &CASSMem [DStart+1024]) to.
2.3, the converted categorical data
The position categorical data comprises district's data such as M, C, T, Q, S, and position categorical data operation comprises assignment and place value judgement.For assign operation, assignment 0 and 1 is realizing with computing and exclusive disjunction through the position respectively.Like M2003=1, will be converted into CASSMem [MStart+128] | (1 3).
The value of position judges and mainly to be used in the condition judgment, and through will corresponding position and 1 work and computing, the value that all the other are done with 0 and the result of computing judges will be converted into if (CASSMem [MStart+128] & (1 < < 3)) like if (M2003==1).
Other data field data are analogous to M district data-switching like conversion regimes such as C district, T district, Q district and S districts.
2.4, generate the high-level language programs file
Through the program code of pretreated code, code is write file with regard to is-symbol higher level lanquage syntax gauge.
3, embed the trapezoid figure program compiling of high-level language programs module, as shown in Figure 3
3.1, convert IL instruction to
At first in the IL instruction set, increase the FUNC instruction, be used for realizing calling of C programmer module, form is " a FUNC function name "; Trapezoid figure program converts the IL instruction set to then.
3.2, increase the grand CASSFunc be used for translating the FUNC instruction
The IL instruction is to translate into machine instruction through grand mode, and grand is one section independently program code.Its syntax format is:
MACRO
Macroname?{$?parameter1,?$parameter2,?……}
Instruction sequence
MEND
MACRO identifies macrodefined beginning, and MEND identifies macrodefined end.Wherein, Macroname is the title of institute's defmacro, like CassFunc.$ parameter1 , $parameter2 etc. is grand parameter, when grand being unfolded, will be replaced by corresponding value, is similar to the formal parameter in the function.
CassFunc instruction macro definition is:
MACRO
CassFUNC?$V,$L
bl?EnableFun
tst?r7,#1
beq?EndCassFUNC$L
bl?$V
nop
add?r0,pc,#3
bx?r0
EndCassFUNC$L
MEND
Qi Zhong $V is for will invoked high-level language programs function name , $L being the row of current high-level language programs module invokes instruction in the IL instruction set number, is used for confirming needing after present instruction is carried out next bar instruction address of carrying out.
3.3, with IL instruction translation Cheng Hong, before compiling, generate machine instruction through macro substitution
At first travel through all IL instruction, the IL instruction translation is become corresponding grand, translate into CASSFunc func () 10, wherein the row of 10 expression current I L instructions in the IL instruction set number like FUNC func ().
In the macro substitution process before compiling; Through the CASSFunc macro substitution is become some machine instructions; Realization is translated into machine instruction set with the IL instruction set that generates in 3.1 steps, concentrates in the machine instruction that generates to have comprised the instruction of high-level language programs function calls.
3.4, code compile
Compiler through any support target platform compiles machine instruction set and the higher-level language code that generates, and the executable file after the compiling downloads among the PLC and can move.When operation, call the high-level language programs function through machine instruction, realize the execution of high-level language programs module.
The above is merely one embodiment of the present of invention, is the implementation procedure that example has been explained the inventive method with the C language, and in fact any language can be as the implementation language of this method.Can not limit scope of the present invention with this, all according to the structural variation that the present invention did, only otherwise lose main idea of the present invention place, all should be regarded as falling within the protection domain of the present invention being restricted.
Claims (1)
1. a trapezoidal pattern embedded higher level lanquage is carried out the implementation method of hybrid programming, it is characterized in that this method may further comprise the steps:
Step 1. increases the higher level lanquage algoritic module with the control mode in the ladder diagram design environment, specifically:
Step 1-1. increases an algoritic module control newly and it is added in the ladder diagram design environment, in use the algoritic module control is dragged to the position that needs the insertion algorithm module, and provides the function name that need call;
Step 1-2. is edit high-grade language module code hereof, and the function name of describing in function name and the ladder diagram algoritic module control must be consistent; All functions all do not have the shape ginseng, and data transfer is accomplished through public data area;
The pre-service of step 2. high-level language programs, specifically:
The data field is distributed among the step 2-1.PLC;
In the internal memory of PLC; Select the public data area of a special use to represent PLC soft element value; In the PLC engine program, defined a byte arrays and be used for representing this special-purpose public data area, shown the start address of Various types of data district in public data area through macro sheet;
Step 2-2. conversion byte categorical data
Byte categorical data in the program is converted to the mode of accessed data;
Step 2-3. converted categorical data
Position categorical data operation comprises assignment and place value judgement; For assign operation, assignment 0 and 1 is realizing with computing and exclusive disjunction through the position respectively;
The value of position judges through will corresponding position and 1 work and computing, the value that other is done with 0 and the result of computing judges;
Step 2-4. writes file with pretreated high-level language programs, thereby generates the high-level language programs file;
Step 3. embeds the trapezoid figure program compiling of higher level lanquage module, specifically:
Step 3-1. converts the IL instruction to
In the IL instruction set, increase the algoritic module call instruction, convert trapezoid figure program to the IL instruction then;
Step 3-2. definition is used for the grand of translation algorithm module invokes instruction, and the grand shape ginseng that has is changed into the function name that need call by instance using when grand; The machine instruction that adopts PLC to support in the macro body of a definition realizes;
Step 3-3. generates machine instruction that PLC support through macro substitution with IL instruction translation Cheng Hong before compiling, specifically:
At first travel through all IL instructions, then the IL instruction translation is become the grand of correspondence, before compiling, realize macro substitution automatically by compiler;
Step 3-4. code compile
Compiler through any support target platform is unified compiling to the machine instruction set and the higher-level language code that generate, and the executable file after the compiling downloads among the PLC and can move.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN2011103248683A CN102393670A (en) | 2011-10-24 | 2011-10-24 | Method for realizing hybrid programming by embedding high-level language into ladder diagram |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN2011103248683A CN102393670A (en) | 2011-10-24 | 2011-10-24 | Method for realizing hybrid programming by embedding high-level language into ladder diagram |
Publications (1)
Publication Number | Publication Date |
---|---|
CN102393670A true CN102393670A (en) | 2012-03-28 |
Family
ID=45861008
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN2011103248683A Pending CN102393670A (en) | 2011-10-24 | 2011-10-24 | Method for realizing hybrid programming by embedding high-level language into ladder diagram |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN102393670A (en) |
Cited By (9)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102736551A (en) * | 2012-06-20 | 2012-10-17 | 深圳市矩形科技有限公司 | Software problem solving method for ladder diagram codes of programmable logic controller (PLC) |
CN104407861A (en) * | 2014-11-20 | 2015-03-11 | 杭州电子科技大学 | Method for achieving combined command in ePLC (embedded programmable logic controller) figure programming platform |
CN104753639A (en) * | 2015-03-02 | 2015-07-01 | 北京精诚铂阳光电设备有限公司 | Data transfer method and data transfer device |
CN107024900A (en) * | 2015-10-21 | 2017-08-08 | Ls 产电株式会社 | The method of optimal compiling PLC orders |
CN107291038A (en) * | 2017-07-27 | 2017-10-24 | 浙江奇赛其自动化科技有限公司 | A kind of PLC software instruction parsing execution method |
CN111026382A (en) * | 2019-12-13 | 2020-04-17 | 深圳市杰美康机电有限公司 | Hybrid programming method, terminal device, and computer-readable storage medium |
CN111158317A (en) * | 2019-12-25 | 2020-05-15 | 深圳市显控科技股份有限公司 | Numerical control machining control method, device, system, equipment and storage medium |
CN113419723A (en) * | 2021-05-12 | 2021-09-21 | 南京南瑞继保电气有限公司 | Ladder diagram compiling method, ladder diagram debugging method, electronic device and storage medium |
CN113454546A (en) * | 2019-04-16 | 2021-09-28 | 西门子股份公司 | Program module calling method and device in PLC ladder diagram programming environment |
-
2011
- 2011-10-24 CN CN2011103248683A patent/CN102393670A/en active Pending
Cited By (15)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102736551B (en) * | 2012-06-20 | 2015-11-25 | 深圳市矩形科技有限公司 | The soft solution approach of a kind of PLC ladder diagram code |
CN102736551A (en) * | 2012-06-20 | 2012-10-17 | 深圳市矩形科技有限公司 | Software problem solving method for ladder diagram codes of programmable logic controller (PLC) |
CN104407861A (en) * | 2014-11-20 | 2015-03-11 | 杭州电子科技大学 | Method for achieving combined command in ePLC (embedded programmable logic controller) figure programming platform |
CN104753639B (en) * | 2015-03-02 | 2018-03-13 | 北京精诚铂阳光电设备有限公司 | Data transferring method and device |
CN104753639A (en) * | 2015-03-02 | 2015-07-01 | 北京精诚铂阳光电设备有限公司 | Data transfer method and data transfer device |
CN107024900A (en) * | 2015-10-21 | 2017-08-08 | Ls 产电株式会社 | The method of optimal compiling PLC orders |
US10445074B2 (en) | 2015-10-21 | 2019-10-15 | Lsis Co., Ltd. | Method of optimally compiling PLC command |
CN107291038A (en) * | 2017-07-27 | 2017-10-24 | 浙江奇赛其自动化科技有限公司 | A kind of PLC software instruction parsing execution method |
CN107291038B (en) * | 2017-07-27 | 2019-04-02 | 浙江奇赛其自动化科技有限公司 | A kind of PLC software instruction parsing execution method |
CN113454546A (en) * | 2019-04-16 | 2021-09-28 | 西门子股份公司 | Program module calling method and device in PLC ladder diagram programming environment |
CN111026382A (en) * | 2019-12-13 | 2020-04-17 | 深圳市杰美康机电有限公司 | Hybrid programming method, terminal device, and computer-readable storage medium |
CN111026382B (en) * | 2019-12-13 | 2024-01-16 | 深圳市杰美康机电有限公司 | Hybrid programming method, terminal device and computer readable storage medium |
CN111158317A (en) * | 2019-12-25 | 2020-05-15 | 深圳市显控科技股份有限公司 | Numerical control machining control method, device, system, equipment and storage medium |
CN111158317B (en) * | 2019-12-25 | 2022-11-11 | 深圳市显控科技股份有限公司 | Numerical control machining control method, device, system, equipment and storage medium |
CN113419723A (en) * | 2021-05-12 | 2021-09-21 | 南京南瑞继保电气有限公司 | Ladder diagram compiling method, ladder diagram debugging method, electronic device and storage medium |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN102393670A (en) | Method for realizing hybrid programming by embedding high-level language into ladder diagram | |
Weeks | Whole-program compilation in MLton | |
Hartel et al. | Benchmarking implementations of functional languages with ‘Pseudoknot’, a float-intensive benchmark | |
Keryell et al. | Khronos SYCL for OpenCL: a tutorial | |
Cohen et al. | Processor virtualization and split compilation for heterogeneous multicore embedded systems | |
McCreight et al. | A certified framework for compiling and executing garbage-collected languages | |
WO2012083266A2 (en) | Fusing debug information from different compiler stages | |
Garg et al. | Compiling python to a hybrid execution environment | |
EP3465428A1 (en) | Sample driven profile guided optimization with precise correlation | |
Lee et al. | A study on the smart virtual machine for executing virtual machine codes on smart platforms | |
CN111814202A (en) | Method for executing intelligent contract, block chain node and storage medium | |
CN109799971A (en) | A kind of file creating apparatus and method | |
CN111770116A (en) | Method for executing intelligent contract, block chain node and storage medium | |
Leinenbach et al. | Pervasive compiler verification–from verified programs to verified systems | |
Ball et al. | Static TypeScript: an implementation of a static compiler for the TypeScript language | |
Thoman et al. | Sylkan: towards a Vulkan compute target platform for SYCL | |
CN103942082A (en) | Complier optimization method for eliminating redundant storage access operations | |
Chevalier-Boisvert et al. | Bootstrapping a self-hosted research virtual machine for javascript: an experience report | |
CN1920771A (en) | Processing method for special register supporting regular record variables access | |
CN103777997A (en) | JAVA virtual machine hardware independency platform based on MIPS and independency improvement method thereof | |
Kim et al. | Output-based intermediate representation for translation of test-pattern program | |
Van Es et al. | A performant scheme interpreter in asm. js | |
Barnett et al. | BCT: A translator from MSIL to Boogie | |
Zhao | Formalizing the SSA-based compiler for verified advanced program transformations | |
CN103019801B (en) | A kind of compiler being applied to high speed digital I/O waveform engine |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
C12 | Rejection of a patent application after its publication | ||
RJ01 | Rejection of invention patent application after publication |
Application publication date: 20120328 |