Pin-based ladder diagram language to ST language conversion method

Through pin-based recursive algorithms and merging similar term algorithms, the limitations of ladder diagram language to ST language conversion in the existing technology are solved, and effective conversion and free editing of multiple input and output pin block primitives are realized. Simplified ST code for a wider range of applications.

CN119002934APending Publication Date: 2024-11-22GUODIAN NANJING AUTOMATION
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202411024824.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-29
Publication Date
2024-11-22

AI Technical Summary

Technical Problem

The existing ladder language to ST language conversion method requires support from the ladder editor, and the smallest unit processed is an element, not a pin, and cannot be used for block elements containing multiple input and output pins, and virtual nodes This method results in increased editor functions and weakened free-moving connection capabilities of the primitives.

Method used

Using pin-based recursive algorithm, traces the input pins of each element through the traceability recursive algorithm, and optimizes the ST language using the merged similar term algorithm, supporting all element types in the IEC61131-3 standard, including contacts, coils, Jump, return element, power rail, block element, reduce the requirements for ladder editor, and realize free drag and connection of element.

Benefits of technology

It realizes effective conversion of all element types, supports a wider range of ST language applications, simplifies ST code, improves code readability, and is suitable for conversion of functional block diagram languages.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119002934A_ABST
    Figure CN119002934A_ABST
Patent Text Reader

Abstract

The invention provides a pin-based ladder diagram language to ST language conversion method, and relates to the technical field of language conversion, and the pin-based ladder diagram language to ST language conversion method comprises the following steps: obtaining a primitive queue in a ladder network and identifying the type of primitives; recursively tracing an input pin of each primitive by utilizing a traceability recursive algorithm, and converting each primitive into an initial ST language according to the primitive type; and performing optimization processing on the converted initial ST language through a similar item merging algorithm to obtain a final ST language. According to the method, extra virtual nodes do not need to be introduced, so that the requirement on a ladder diagram editor is reduced, the primitives in the ladder diagram can be freely dragged and connected, and a final product is an ST language with a wider application range.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of language conversion, and in particular to a method for converting a pin-based ladder diagram language into an ST language. Background Art

[0002] Among the methods that have been published to convert ladder diagram programs to text language, one is the virtual node method, which requires the support of the ladder diagram editor. In order to identify virtual nodes, the editor cancels the editing method of free movement and free connection of primitives on the one hand; on the other hand, the editor needs to add additional functions, such as inserting, moving, and deleting virtual nodes; in addition, since the smallest unit processed by this method is the ladder diagram primitive, not the pin, it is not suitable for processing block primitives containing multiple input and output pins. The other is to convert the ladder diagram language into the instruction list language. The instruction list language is a low-level language with limited application areas and is gradually being replaced by the ST language.

[0003] like Figure 4 As shown in the figure, it is a solution using virtual nodes. In order to reduce the complexity of converting ladder diagram to ST language, when drawing ladder diagram program, the ladder diagram editor will add virtual nodes at the intersection of parallel connections to obtain the ladder diagram storage structure; then according to Figure 4 In the steps shown, first the virtual nodes are processed (some redundant virtual nodes are merged), and then each node (including the virtual nodes) is converted from left to right and from top to bottom, and finally the ST code is obtained.

[0004] The method of converting a ladder program with virtual nodes requires the support of a ladder editor. Virtual nodes have no physical counterparts and are redundant primitives. In order to identify virtual nodes, the editor cancels the editing mode of free movement and free connection of primitives on the one hand; on the other hand, the editor needs to add additional functions, such as inserting, moving, and deleting virtual nodes. In addition, the minimum unit processed by this method is the ladder primitive, not the pin. It can only process primitives containing 1 input pin and 1 output pin. For block primitives containing multiple input and output pins, the above method is not applicable.

[0005] Currently, no effective solution has been proposed for the problems in the related technologies. Summary of the invention

[0006] In view of this, the present invention provides a pin-based conversion method from ladder diagram language to ST language to solve the above-mentioned problem.

[0007] In order to solve the above problems, the specific technical solutions adopted by the present invention are as follows: According to a first aspect of the present invention, a method for converting a pin-based ladder diagram language to an ST language is provided. The method for converting a pin-based ladder diagram language to an ST language comprises the following steps: S1, obtain the primitive queue in the ladder network and identify the type of primitive; S2, using the traceability recursive algorithm, recursively trace the input pins of each primitive, and convert each primitive into the initial ST language according to the primitive type; S3. Optimize the converted initial ST language by merging similar terms algorithm to obtain the final ST language.

[0008] Preferably, the following steps are included before obtaining the primitive queue in the ladder network and identifying the type of the primitive: S11, sorting and numbering the primitives in the ladder network based on the primitive types to obtain a primitive queue, where the primitive types include contacts, coils, jump primitives, return primitives, power rails, and block primitives, where the power rails include left power rails and right power rails; S12, respectively configuring a first-level enumeration variable for each graphic element in the ladder network, where the first-level enumeration variable is used to identify the type of the graphic element; S13. If the type of the graphic element is a power rail, a secondary enumeration variable is configured for the power rail, and the secondary enumeration variable is used to identify whether the power rail graphic element is a left power rail or a right power rail.

[0009] Preferably, using a source tracing recursive algorithm to recursively trace the input pins of each primitive, and converting each primitive into an initial ST language according to the primitive type includes the following steps: S21, based on the primitive queue in the ladder network, selecting primitives one by one according to the primitive numbers in the primitive queue and determining the types of the selected primitives; S22, if the primitive type is a right power rail or a block primitive, perform ST language conversion of the primitive through a source tracing recursive algorithm until all primitives are converted; S23. If the primitive type is not a right power rail or a block primitive, repeat step S21 until all primitives are selected.

[0010] Preferably, if the primitive type is a right power rail or a block primitive, performing ST language conversion of the primitive by a source tracing recursive algorithm until all primitives are converted includes the following steps: S221, performing ST language conversion on the selected graphic element based on the ST language conversion algorithm library according to the graphic element type; S222, using the output pin of the primitive as the index cache result, marking the primitive after ST language conversion as processed; S223, selecting the next graphic element by tracing back according to the pin relationship of the graphic element, and storing the traced traceability route; S224. Repeat steps S221-S224 until it is determined whether the tracing route reaches the left power rail.

[0011] Preferably, according to the type of the graphic element, before performing ST language conversion on the selected graphic element based on the ST language conversion algorithm library, the following steps are included: S2211. For each primitive type, establish a corresponding ST language conversion algorithm; S2212, testing and verifying the ST language conversion algorithm for each primitive type, and determining that the ST language conversion algorithm can convert the primitive into the expected ST language; S2213. Encapsulate all tested and verified ST language conversion algorithms into an ST language conversion algorithm library; S2214. Construct a mapping table and associate each primitive type with the corresponding ST language conversion algorithm in the ST language conversion algorithm library.

[0012] Preferably, according to the pin relationship of the primitives, selecting the next primitive by tracing forward, and storing the traced traceability route includes the following steps: S2231, obtaining the input pin of the primitive, and identifying the next primitive associated with the primitive according to the pin relationship. If there is a primitive connected to multiple primitives, select the next primitive according to the operation rules of the ladder diagram; S2232, adding the next identified element to the traceability route, and marking the element as visited; S2233. Take the newly identified primitive as the current primitive, repeat steps S2231 and S2232 until the preset termination condition is reached, and summarize and record all traceability routes.

[0013] Preferably, optimizing the converted initial ST language by merging similar terms algorithm to obtain the final ST language includes the following steps: S31, evaluating the converted initial ST language code, and identifying the same operands existing in the initial ST language; S32, using the AND operator as a multiplication operator in the algorithm for combining similar items, and using the OR operator as an addition operator in the algorithm for combining similar items; S33. Apply the algorithm of merging similar items to merge the identified identical operands to obtain the final ST language.

[0014] According to a second aspect of the present invention, there is provided a pin-based ladder diagram language to ST language conversion system, the pin-based ladder diagram language to ST language conversion system comprising: a type identification module, a language conversion module and a language optimization module; A type identification module, used for obtaining a queue of graphics elements in a ladder network and identifying the type of graphics elements; A language conversion module, used for recursively tracing the input pins of each primitive using a traceability recursive algorithm, and converting each primitive into an initial ST language according to the primitive type; The language optimization module is used to optimize the converted initial ST language by merging similar terms algorithm to obtain the final ST language.

[0015] According to a third aspect of the present invention, there is provided a computer device, comprising a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the above method when executing the computer program.

[0016] According to a fourth aspect of the present invention, there is provided a computer-readable storage medium having a computer program stored thereon, which implements the steps of the above method when the computer program is executed by a processor.

[0017] The beneficial effects of the present invention are: 1. The present invention proposes a method for converting ladder diagram language to text language. The method supports all the primitives of the ladder diagram defined in the IEC61131-3 standard, including contacts, coils, jumps, return primitives, power rails, and block primitives. There is no need to introduce additional virtual nodes, which reduces the requirements for the ladder diagram editor. The primitives in the ladder diagram can be freely dragged and connected, and the final product is the ST language with a wider range of applications.

[0018] 2. The present invention is a method for converting a PLC graphic language into a text language based on a pin connection relationship (i.e., the input and output of a graphic element). This conversion method based on the graphic element pin connection relationship makes the method not only applicable to the conversion of a ladder diagram language into an ST language, but also applicable to the conversion of a function block diagram language into an ST language.

[0019] 3. The present invention first uses the AND+OR algorithm to merge similar terms, regards the AND in the ST code of each path as a multiplication operator in mathematical operations, and then regards OR as an addition operator to merge the same operands in each path, thereby achieving the purpose of simplifying the ST code and improving the readability of the ST code. BRIEF DESCRIPTION OF THE DRAWINGS

[0020] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work. In the drawings: Figure 1is a flow chart of a pin-based conversion method from ladder diagram language to ST language according to an embodiment of the present invention; Figure 2 It is a principle block diagram of a pin-based ladder diagram language to ST language conversion system according to an embodiment of the present invention; Figure 3 is a schematic diagram of the structure of a computer device according to an embodiment of the present invention; Figure 4 It is a processing flow chart of virtual nodes in the prior art in a pin-based ladder diagram language to ST language conversion method according to an embodiment of the present invention; Figure 5 It is an example diagram of a ladder diagram in the prior art in a pin-based ladder diagram language to ST language conversion method according to an embodiment of the present invention; Figure 6 It is one of the ladder diagram program example diagrams in a pin-based ladder diagram language to ST language conversion method according to an embodiment of the present invention; Figure 7 It is a schematic diagram of an algorithm for merging similar items in a pin-based ladder diagram language to ST language conversion method according to an embodiment of the present invention; Figure 8 This is the second example diagram of a ladder diagram program in a pin-based ladder diagram language to ST language conversion method according to an embodiment of the present invention.

[0021] In the figure: 1. Type identification module; 2. Language conversion module; 3. Language optimization module. DETAILED DESCRIPTION

[0022] In order to enable those skilled in the art to better understand the technical solutions in this application, the technical solutions in the embodiments of this application will be clearly and completely described below in conjunction with the drawings in the embodiments of this application. Obviously, the described embodiments are only part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of this application.

[0023] According to an embodiment of the present invention, a method for converting a pin-based ladder diagram language to an ST language is provided.

[0024] Specifically, the pin-based ladder diagram to ST conversion algorithm is a recursive nested algorithm. The smallest processing unit of the algorithm is the pin of the primitive. The pin-based conversion algorithm is actually an algorithm based on the input and output relationship of the primitive. The algorithm entry is the end block primitive or the right power rail in the ladder diagram network.

[0025] This algorithm has three core algorithms: a source tracing recursive algorithm, an AND+OR-oriented merge similar term algorithm, and an ST conversion algorithm for each graphic element (power rail, contact, coil, jump graphic element, return graphic element, block graphic element). The source tracing recursive algorithm has a scheduling function. When executing the source tracing recursive algorithm, when tracing back to the graphic element, the ST conversion algorithm of the graphic element will be executed, and the source tracing route will be recorded. After completing the source tracing of a certain graphic element, according to the optimization strategy, the AND+OR-oriented merge similar term algorithm will be executed in time to reduce the complexity of the ST statement and reduce the subsequent recursive depth. After all the graphic elements are processed, the ST code after the ladder diagram program is converted is obtained. The present invention proposes a conversion method from ladder diagram language to text language. The method supports all graphic elements of the ladder diagram defined in the IEC61131-3 standard, including contacts, coils, jump graphic elements, return graphic elements, power rails, and block graphic elements, reduces the requirements for the ladder diagram editor, and the graphic elements in the ladder diagram can be freely dragged and connected, and the final product is ST language.

[0026] The present invention is further described with reference to the accompanying drawings and specific embodiments. Figure 1 As shown, according to a first embodiment of the present invention, a method for converting a pin-based ladder diagram language to an ST language is provided, and the method for converting a pin-based ladder diagram language to an ST language comprises the following steps: S1, obtain the primitive queue in the ladder network and identify the type of primitive; As a preferred embodiment, the following steps are included before obtaining the primitive queue in the ladder network and identifying the type of the primitive: S11, sorting and numbering the primitives in the ladder network based on the primitive types to obtain a primitive queue, where the primitive types include contacts, coils, jump primitives, return primitives, power rails, and block primitives, where the power rails include left power rails and right power rails; S12, respectively configuring a first-level enumeration variable for each graphic element in the ladder network, where the first-level enumeration variable is used to identify the type of the graphic element; S13. If the type of the graphic element is a power rail, a secondary enumeration variable is configured for the power rail, and the secondary enumeration variable is used to identify whether the power rail graphic element is a left power rail or a right power rail.

[0027] S2, using the traceability recursive algorithm, recursively trace the input pins of each primitive, and convert each primitive into the initial ST language according to the primitive type; As a preferred implementation, using a source tracing recursive algorithm, recursively tracing the input pins of each primitive, and converting each primitive into an initial ST language according to the primitive type includes the following steps: S21, based on the primitive queue in the ladder network, selecting primitives one by one according to the primitive numbers in the primitive queue and determining the types of the selected primitives; S22, if the primitive type is a right power rail or a block primitive, perform ST language conversion of the primitive through a source tracing recursive algorithm until all primitives are converted; As a preferred implementation, if the primitive type is a right power rail or a block primitive, performing ST language conversion of the primitive by a source tracing recursive algorithm until all primitives are converted includes the following steps: S221, performing ST language conversion on the selected graphic element based on the ST language conversion algorithm library according to the graphic element type; As a preferred implementation, according to the primitive type, before performing ST language conversion on the selected primitive based on the ST language conversion algorithm library, the following steps are included: S2211. For each primitive type, establish a corresponding ST language conversion algorithm; S2212, testing and verifying the ST language conversion algorithm for each primitive type, and determining that the ST language conversion algorithm can convert the primitive into the expected ST language; S2213. Encapsulate all tested and verified ST language conversion algorithms into an ST language conversion algorithm library; S2214. Construct a mapping table and associate each primitive type with the corresponding ST language conversion algorithm in the ST language conversion algorithm library.

[0028] S222, using the output pin of the primitive as the index cache result, marking the primitive after ST language conversion as processed; S223, selecting the next graphic element by tracing back according to the pin relationship of the graphic element, and storing the traced traceability route; As a preferred implementation, according to the pin relationship of the primitive, selecting the next primitive by tracing forward, and storing the traced traceability route includes the following steps: S2231, obtaining the input pin of the primitive, and identifying the next primitive associated with the primitive according to the pin relationship. If there is a primitive connected to multiple primitives, select the next primitive according to the operation rules of the ladder diagram; S2232, adding the next identified element to the traceability route, and marking the element as visited; S2233. Take the newly identified primitive as the current primitive, repeat steps S2231 and S2232 until the preset termination condition is reached, and summarize and record all traceability routes.

[0029] S224. Repeat steps S221-S224 until it is determined whether the tracing route reaches the left power rail.

[0030] S23. If the primitive type is not a right power rail or a block primitive, repeat step S21 until all primitives are selected.

[0031] It should be noted that the purpose of the tracing recursive algorithm is to find all the paths to the input pins of the primitive. The tracing recursive algorithm is to trace from right to left, with a certain input pin as the entry of the tracing algorithm, and recursively layer by layer according to the direct connection relationship of the pins until the left power rail is reached (each primitive has an enumeration variable to identify the type of the primitive (specific types include contacts, coils, jumps, return primitives, power rails, block primitives). If the primitive is a power rail, there is also an enumeration variable inside to identify whether the primitive is a left power rail or a right power rail). As shown in the following example: Figure 6 Take the ladder diagram program shown as an example, to find all the paths of the input pin of the param9 coil, the specific implementation steps are as follows: Step 1: Get the input pin of the param9 coil, and find out that the next primitive is the param8 contact according to the pin association relationship; (this information is stored in each primitive, so you can get it directly. The following is a detailed explanation: each primitive stores the input pin and output pin data. The connection between the pins indicates that there is an association between the pins. It can be seen from the figure that the input pin of the param9 coil is connected to the output pin of the param8 contact, and each pin also stores the information of the primitive to which it belongs. Therefore, the search step is that the param9 coil first finds its own input pin, finds that the input pin is connected to the output pin of the param8 contact, and then knows that the next primitive of the param9 coil is the param8 contact through the primitive information stored in the output pin).

[0032] Step 2: Trace back from the param8 contact to find the param6 contact and the param7 contact.

[0033] Step 3: Process the param6 contact first, and trace back from the param6 contact to get the param5 contact; (wherein, when the param6 contact and the param7 contact need to be processed at the same time, the param6 contact is processed first, and the processing method is to trace back from the param6 contact first, because the operation rule of the ladder diagram is from top to bottom, and the param6 contact is processed first according to the principle of top to bottom, and then the param7 contact is processed).

[0034] Step 4: Trace back from the param5 contact to find the param3 contact and the param4 contact.

[0035] Step 5: Process the param3 contact first, and trace back from the param3 contact to get the param2 contact.

[0036] Step 6: Trace back from the param2 contact to find the param1 contact.

[0037] Step 7: Trace back from the param1 contact to find the left power rail; so far, find the first path: left power rail à param1 contact à param2 contact à param3 contact à param5 contact à param6 contact à param8 contact.

[0038] Step 8: Then process the param4 contact according to the above process and find the second path: left power rail à param1 contact à param4 contact à param5 contact à param6 contact à param8 contact.

[0039] Following this step, after exiting the recursion layer by layer, 4 paths are obtained, as shown below: Path 1: left power rail à param1 contact à param2 contact à param3 contact à param5 contact à param6 contact à param8 contact.

[0040] Path 2: left power rail à param1 contact à param4 contact à param5 contact à param6 contact à param8 contact.

[0041] Path 3: left power rail à param1 contact à param2 contact à param3 contact à param5 contact à param7 contact à param8 contact.

[0042] Path 4: left power rail à param1 contact à param4 contact à param5 contact à param7 contact à param8 contact.

[0043] These channels will eventually be converted into ST code. The conversion results of each channel are as follows: Path 1: param1 AND param2 AND param3 AND param5 AND param6 AND param8.

[0044] Path 2: param1 AND param4 AND param5 AND param6 AND param8.

[0045] Path 3: param1 AND param2 AND param3 AND param5 AND param7 AND param8.

[0046] Path 4: param1 AND param4 AND param5 AND param7 AND param8.

[0047] S3. Optimize the converted initial ST language by merging similar terms algorithm to obtain the final ST language.

[0048] As a preferred implementation, the initial ST language converted is optimized by merging similar terms algorithm to obtain the final ST language, including the following steps: S31, evaluating the converted initial ST language code, and identifying the same operands existing in the initial ST language; S32, using the AND operator as a multiplication operator in the algorithm for combining similar items, and using the OR operator as an addition operator in the algorithm for combining similar items; S33. Apply the algorithm of merging similar items to merge the identified identical operands to obtain the final ST language.

[0049] Specifically, the tracing algorithm obtains all the paths of the ladder diagram program. The more parallel lines in the ladder diagram, the more paths are obtained. Simply merging the ST codes of all paths will result in low similarity and poor readability in the conversion between the ladder diagram and the ST code. Therefore, an AND+OR-oriented merging similar terms algorithm is designed to optimize the ST codes of each path. The optimization idea is to regard AND as a multiplication operator in mathematical operations and OR as an addition operator, and introduce the OR operator to merge the same operands in each path (both OR and AND operators are operators in the ST language. The AND operator in ST is used to connect two Boolean expressions. The result of the entire expression is true only when both expressions are true (TRUE). Similar to && in C language, the OR operator in ST is used to connect two Boolean expressions. As long as one of the expressions on both sides is true, the result of the entire expression is true. Similar to || in C language, such as Figure 7 The algorithm for merging similar items is shown in the figure), which simplifies the ST code and improves the readability of the ST code. The algorithm for merging similar items for AND+OR is a recursive process. The ST codes of the four paths above are obtained after the algorithm for merging similar items for AND+OR: ST code: param1 AND (param2 AND param3 OR param4) AND param5 AND (param6 OR param7) AND param8.

[0050] Ladder diagram program such as Figure 6 As shown in the figure, while executing the source tracing recursive algorithm, executing the AND+OR-oriented merge similar items algorithm can reduce the number of paths, reduce the recursive depth, and reduce the complexity of merging similar items. For example, when the source tracing algorithm is executed to the param5 contact, the merge similar items algorithm is executed, and the path before the param5 contact is converted into ST language and expressed as param1 AND (param2 AND param3 OR param4) AND param5. In this way, when the source tracing algorithm is executed to the param8 contact, only two paths will be calculated. One is param5 contact à param6 contact à param8 contact, and the other is param5 contact à param7 contact à param8 contact, instead of the previous 4 paths. In this way, the purpose of the optimization algorithm can be achieved.

[0051] The conversion algorithms of various types of primitives to ST language are as follows: (1) Conversion algorithm from power rail to ST language: The power rail is divided into left power rail and right power rail. The left power rail is directly converted to TRUE. The right power rail has no corresponding ST statement and does not need to be converted. The traceability algorithm is directly called to find the next primitive for processing based on the pin connection relationship. TRUE indicates logical true, indicating that the circuit at this position is connected. FALSE indicates logical false, indicating that the circuit at this position is disconnected. The left power rail is connected by default and can be directly converted to TRUE.

[0052] (2) Algorithm for converting contacts to ST language: Ladder diagram program such as Figure 6 As shown in the figure, the contact in the ladder diagram represents the on-off of the circuit and plays the role of a switch. When switching contacts, the on-off status of the circuit at the contact element is determined according to the on-off status of the left side of the contact and the variable bound to the contact itself (such as Figure 8As shown, -||- represents the contact primitive, and the var0 above is the variable bound to the contact primitive. The contact can only bind a Boolean variable. Whether the Boolean variable is TRUE or FALSE represents the on-off status of the circuit at the contact position. -||- represents the contact primitive, and the var0 above is the variable bound to the contact primitive. The contact can only bind a Boolean variable. Whether the Boolean variable is TRUE or FALSE represents the on-off status of the circuit at the contact position. First, call the traceability algorithm to obtain the ST statements of all paths on the left side of the contact, and merge these ST statements into similar items. For example, when converting the param5 contact, the ST statement of the left path is expressed as param1 AND (param2 AND param3 ORparam4). Then, by superimposing "AND param5", the ST statement corresponding to the contact param5 is obtained: param1 AND (param2AND param3 OR param4) AND param5. In addition to ordinary contacts, there are also normally closed contacts, rising edge contacts, and falling edge contacts. Normally closed contacts are represented as param1 AND (param2 AND param3 OR param4) AND NOT (param5). If it is a rising edge contact (or falling edge), create a temporary variable TEMP_TRIG of type R_TRIG (or F_TRIG), and the contact param5 is converted to param1 AND (param2 AND param3 OR param4) AND TEMP_TRIG.Q.

[0053] Among them, R_TRIG (Rising Edge Trigger), that is, the rising edge trigger, is a built-in function block. This trigger will trigger the execution of the corresponding operation when the input signal changes from a low level to a high level (from FALSE to TRUE).

[0054] F_TRIG (Falling Edge Trigger), also known as the falling edge trigger, is a built-in function block. This trigger will trigger the execution of the corresponding operation when the input signal changes from a high level to a low level (i.e., TRUE changes to FALSE).

[0055] In addition, contact conversion optimization strategies: such as Figure 8 The ladder diagram example program shown.

[0056] The conversion algorithm transforms this ladder diagram into: VAR3:= VAR0 AND VAR1 AND VAR2; VAR4:= VAR0 AND VAR1 AND VAR2; The above ST statements have redundancy problems. The purpose of the optimization strategy is to make the converted ST language concise and easy to understand. If the output pin of the contact primitive is connected to multiple pins, the conversion algorithm will create a BOOL type temporary variable TEMP_OUT; BOOL is a data type representing a Boolean value (Boolean Value), which is used to represent true (TRUE) or false (FALSE), and the following ST statement is obtained: TEMP_OUT:=VAR0 AND VAR1 AND VAR2; VAR3:=TEMP_OUT; VAR4:=TEMP_OUT; (3) The conversion algorithm from coil to ST language: the coil corresponds to an assignment expression. The right value of the assignment expression is given by the traceability algorithm. The input pin of the coil is passed to the traceability algorithm to obtain the ST expression corresponding to the input pin of the coil. The left value of the assignment expression is determined by the coil. Different coil types will result in different ST expressions after conversion.

[0057] Case 1: param9 coil is a normal coil; param9:=param1 AND (param2 AND param3 OR param4) AND param5 AND (param6 OR param7) AND param8; Case 2: If the param9 coil is a negation coil, then NOT negation is called; param9:=NOT(param1 AND (param2 AND param3 OR param4) AND param5 AND (param6 OR param7) AND param8); Case 3: If the param9 coil is a set coil, it is expressed by an IF statement, which is a programming control structure used to execute a section of code when a certain condition is met. It is one of the most basic conditional statements, allowing the program to choose different execution paths depending on the result of the condition (true or false).

[0058] IF param1 AND (param2 AND param3 OR param4) AND param5 AND (param6 ORparam7) AND param8 THEN; param9:=TRUE; END_IF; Case 4: The param9 coil is a reset coil, which is expressed by an IF statement, specifically: IF param1 AND (param2 AND param3 OR param4) AND param5 AND (param6 ORparam7) AND param8 THEN; param9:=FALSE; END_IF; Case 5: If the param9 coil is a rising edge coil, create a temporary variable of type R_TRIG and convert the following ST expression; VAR TEMP_TRIG:R_TRIG; END_VAR; TEMP_TRIG (CLK:=param1 AND (param2 AND param3 OR param4) AND param5AND (param6 OR param7) AND param8); param9:=TEMP_TRIG.Q; Case 6: If the param9 coil is a falling edge coil, create a temporary variable of type F_TRIG and convert the following ST expression; VAR TEMP_TRIG:F_TRIG; END_VAR; TEMP_TRIG(CLK:=param1 AND (param2 AND param3 OR param4) AND param5AND (param6 OR param7) AND param8); param9:=TEMP_TRIG.Q; (3) Conversion algorithm from jump primitives to ST language; The jump primitive corresponds to the goto syntax in C language, but there is no such syntax in ST language. Since ST language will be further converted to C language, the present invention directly converts the jump primitive into the goto statement of C language and uses {{}} to distinguish them. The outside of the curly braces is ST language, and the inside is C language. For example, {{goto label_net1;}}, where label_net1 is the network label.

[0059] (4) Return the primitive to ST language conversion algorithm; The return primitive is converted to RETURN in ST language. In programming, RETURN statement stands for "return" and is used to return from a function or method to the caller. When execution reaches the RETURN statement, the execution of the function stops immediately and the calculation result (if any) is passed back to the caller.

[0060] (5) Conversion algorithm from block primitives to ST language; The core of the conversion block primitive is to convert all the pins of the block primitive. Input pins are converted to assignment expressions similar to IN1:= PARM0, where IN1 is the input pin name and PARM0 is the variable used by the pin; output pins are converted to expressions similar to ENO=>TEMP_ENO, where ENO is the input pin name and TEMP_ENO is the variable used by the pin; the call block uses an explicit call method (explicit call is a method of adding the name of the parameter when calling, such as MYRS(EN:=PARM0,S:= PARM6,R1:=PARM1,ENO=>TEMP_ENO); where EN, S, R1, and ENO are all parameters). This call method will identify the pin name in the call statement, and there is no need to pay attention to the conversion order of the pin code. When converting input pins, since the right value of the expression is not known yet, it is necessary to call the tracing algorithm to calculate the path expression of the pin connection. When processing the output pins of the block primitive, the cache technology must be used to cache the calculation results of the pin to avoid re-conversion when tracing to the pin next time.

[0061] If the block primitive is a function, and the function does not have data storage characteristics, there are two ways to cache the output pin.

[0062] Case 1: If an output pin is directly bound to a variable, the data cached for the pin is the name of the bound variable; Case 2: If an output pin is connected to another pin, a temporary variable is created and the result of the pin is assigned to the temporary variable. The data cached for the pin is the created temporary variable.

[0063] If the block element is a function block (such as an RS type block element named MYRS), since the function block has data storage characteristics, MYRS.A (where A is the pin name) can be used as the cache result of pin A.

[0064] For example, a block element of RS type (the name of the block element is MYRS) is converted into ST language expression as follows: MYRS(EN:=PARM0,S:=PARM6,R1:=PARM1,ENO=>TEMP_ENO).

[0065] According to a second embodiment of the present invention, Figure 2As shown, a pin-based ladder diagram language to ST language conversion system is provided, and the pin-based ladder diagram language to ST language conversion system includes: a type identification module 1, a language conversion module 2 and a language optimization module 3; Type identification module 1, used to obtain the primitive queue in the ladder network and identify the type of the primitive; The language conversion module 2 is used to recursively trace the input pins of each primitive using a traceability recursive algorithm, and convert each primitive into an initial ST language according to the primitive type; The language optimization module 3 is used to optimize the converted initial ST language by merging similar terms algorithm to obtain the final ST language.

[0066] According to a third embodiment of the present invention, a computer device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the above method when executing the computer program.

[0067] The computer device may be a server, and its internal structure diagram may be as follows: Figure 3 As shown. The computer device includes a processor, a memory and a network interface connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store static information and dynamic information data. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, the steps in the above method embodiment are implemented.

[0068] Those skilled in the art will understand that Figure 3 The structure shown in the figure is only a block diagram of a part of the structure related to the scheme of the present invention, and does not constitute a limitation on the computer device to which the scheme of the present invention is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0069] According to a fourth embodiment of the present invention, there is provided a computer-readable storage medium having a computer program stored thereon, wherein the computer program implements the steps of the above method when executed by a processor.

[0070] In addition, it should be noted that PLC, or programmable logic controller, can be imagined as an intelligent switch device, but it is much more complicated than an ordinary switch. In daily life, you may have encountered such a situation: when you turn on the electrical appliances at home, you need to press the switch, which tells the appliances when to start working. In industrial production, there are many such switches, and they need to work in coordination, which requires PLC to help. PLC is like a brain in industrial production. It receives signals from various sensors, such as temperature, pressure, speed, etc., and then judges these signals according to our pre-programmed programs and responds accordingly, such as controlling the start and stop of the machine, or adjusting the production process. PLC can be compared to a conductor, which coordinates and controls the various parts of the entire production line to ensure that they can work in an orderly manner. For example, in an automobile manufacturing plant, PLC can control robots to weld and paint, while ensuring that all parts are assembled in the correct order.

[0071] Ladder diagram is a PLC programming language, also known as ladder logic. It is called ladder diagram because it is composed of horizontal lines, which looks like a ladder. Ladder diagram was invented by electrical engineers and is a graphical programming language.

[0072] In PLC programming, pins usually refer to the physical connection points on the PLC input / output modules. These pins are responsible for connecting external devices (such as sensors, actuators, etc.) to the internal circuits of the PLC. When programming, pins are usually identified by numbers or letters. For example, the number 1 represents the first input pin, the number 2 represents the second input pin, and so on. In logic programming, these pins are used to represent specific input or output points, and programmers can monitor and control the status of these pins by writing programs. In programming, the small short horizontal line at the red mark is the pin, and the pin can be bound to a variable or dragged to connect to other pins.

[0073] In summary, with the help of the above technical solution of the present invention, the present invention proposes a method for converting ladder diagram language to text language. The method supports all the primitives of the ladder diagram defined in the IEC61131-3 standard, including contacts, coils, jumps, return primitives, power rails, and block primitives. There is no need to introduce additional virtual nodes, which reduces the requirements for the ladder diagram editor. The primitives in the ladder diagram can be freely dragged and connected, and the final product is an ST language with a wider range of applications. The present invention is a method for converting a PLC graphic language to a text language based on a pin connection relationship (i.e., the input and output of the primitive). This conversion method based on the primitive pin connection relationship makes the method not only applicable to the conversion of ladder diagram language to ST language, but also applicable to the conversion of function block diagram language to ST language. The present invention uses the AND+OR merging like terms algorithm to regard the AND in the ST code of each path as a multiplication operator in mathematical operations. By introducing the OR operator, OR is regarded as an addition operator, and the same operands in each path are merged, so as to simplify the ST code and improve the readability of the ST code.

[0074] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided by the present invention can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory or optical memory, etc. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM).

[0075] The specific embodiments described above further illustrate the objectives, technical solutions and beneficial effects of the present invention in detail. It should be understood that the above description is only a specific embodiment of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.

Claims

1. A pin-based ladder diagram language to ST language conversion method, characterized in that: The pin-based ladder diagram language to ST language conversion method comprises the following steps: S1, obtain the primitive queue in the ladder network and identify the type of primitive; S2, using the traceability recursive algorithm, recursively trace the input pins of each primitive, and convert each primitive into the initial ST language according to the primitive type; S3. Optimize the converted initial ST language by merging similar terms algorithm to obtain the final ST language.

2. The method for converting a pin-based ladder diagram language to an ST language according to claim 1, characterized in that: The steps of obtaining the primitive queue in the ladder network and identifying the type of the primitive include: S11, sorting and numbering the primitives in the ladder network based on the primitive types to obtain a primitive queue, wherein the primitive types include contacts, coils, jump primitives, return primitives, power rails, and block primitives, and the power rails include left power rails and right power rails; S12, respectively configuring a first-level enumeration variable for each graphic element in the ladder network, wherein the first-level enumeration variable is used to identify the type of the graphic element; S13. If the type of the graphic element is a power rail, a secondary enumeration variable is configured for the power rail, where the secondary enumeration variable is used to identify whether the power rail graphic element is a left power rail or a right power rail.

3. The method for converting a pin-based ladder diagram language to an ST language according to claim 1, characterized in that: The method of using the source tracing recursive algorithm to recursively trace the input pins of each primitive and converting each primitive into the initial ST language according to the primitive type includes the following steps: S21, based on the primitive queue in the ladder network, selecting primitives one by one according to the primitive numbers in the primitive queue and determining the types of the selected primitives; S22, if the primitive type is a right power rail or a block primitive, perform ST language conversion of the primitive through a source tracing recursive algorithm until all primitives are converted; S23. If the primitive type is not a right power rail or a block primitive, repeat step S21 until all primitives are selected.

4. The method for converting a pin-based ladder diagram language to an ST language according to claim 3, characterized in that: If the primitive type is a right power rail or a block primitive, performing ST language conversion of the primitive by a source tracing recursive algorithm until all primitives are converted includes the following steps: S221, performing ST language conversion on the selected graphic element based on the ST language conversion algorithm library according to the graphic element type; S222, using the output pin of the primitive as the index cache result, marking the primitive after ST language conversion as processed; S223, selecting the next graphic element by tracing back according to the pin relationship of the graphic element, and storing the traced traceability route; S224. Repeat steps S221-S224 until it is determined whether the tracing route reaches the left power rail.

5. The method for converting a pin-based ladder diagram language to an ST language according to claim 4, characterized in that: The step of converting the selected graphic element into ST language based on the ST language conversion algorithm library according to the graphic element type includes the following steps: S2211. For each primitive type, establish a corresponding ST language conversion algorithm; S2212, testing and verifying the ST language conversion algorithm for each primitive type, and determining that the ST language conversion algorithm can convert the primitive into the expected ST language; S2213. Encapsulate all tested and verified ST language conversion algorithms into an ST language conversion algorithm library; S2214. Construct a mapping table and associate each primitive type with the corresponding ST language conversion algorithm in the ST language conversion algorithm library.

6. The method for converting a pin-based ladder diagram language to an ST language according to claim 4, characterized in that: The step of selecting the next graphic element by tracing back according to the pin relationship of the graphic element and storing the traced traceability route comprises the following steps: S2231, obtaining the input pin of the primitive, and identifying the next primitive associated with the primitive according to the pin relationship. If there is a primitive connected to multiple primitives, select the next primitive according to the operation rules of the ladder diagram; S2232, adding the next identified element to the traceability route, and marking the element as visited; S2233. Take the newly identified primitive as the current primitive, repeat steps S2231 and S2232 until the preset termination condition is reached, and summarize and record all traceability routes.

7. The method for converting a pin-based ladder diagram language to an ST language according to claim 1, characterized in that: The step of optimizing the converted initial ST language by merging similar terms algorithm to obtain the final ST language comprises the following steps: S31, evaluating the converted initial ST language code, and identifying the same operands existing in the initial ST language; S32, using the AND operator as a multiplication operator in the algorithm for combining similar items, and using the OR operator as an addition operator in the algorithm for combining similar items; S33. Apply the algorithm of merging similar items to merge the identified identical operands to obtain the final ST language.

8. A pin-based ladder diagram language to ST language conversion system, characterized in that: The pin-based ladder diagram language to ST language conversion system includes: a type identification module, a language conversion module and a language optimization module; The type identification module is used to obtain the primitive queue in the ladder network and identify the type of the primitive; The language conversion module is used to recursively trace the input pins of each primitive using a source tracing recursive algorithm, and convert each primitive into an initial ST language according to the primitive type; The language optimization module is used to optimize the converted initial ST language by merging similar terms algorithm to obtain the final ST language.

9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.

Citation Information

Cited By

  • Method, system and device for converting ladder diagram language into ST language

    CN116661806A

  • Method, system and device for converting ladder language to st language

    CN116661806B