Graphical programming code generation method

By generating dependency trees and depth-first traversal in DDC devices and edge intelligent devices, the problem of difficulty in determining the order of function block execution in graphical programming is solved, and the effect of generating function block call codes that meet users' expectations is achieved.

CN119536113AActive Publication Date: 2025-02-28TONGFANG TECHNOVATOR INT (BEIJING) CO LTD
View PDF 12 Cites 0 Cited by

Patent Information

Application Number
CN202411574549.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-06
Publication Date
2025-02-28
Estimated Expiration
2044-11-06

AI Technical Summary

Technical Problem

In DDC devices and edge smart devices, although graphical programming is friendly, it is difficult to determine the execution order of the function blocks and generate code that meets the user's expected execution results.

Method used

By generating a dependency tree based on a collection of function block instances, the dependency tree is traversed in depth first, the function blocks are arranged in the order of traversal, and the code to call the function blocks is generated based on the traversal results.

Benefits of technology

Effectively determine the execution order of function blocks, generate appropriate function block call code, reduce the threshold for use and improve programming efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119536113A_ABST
    Figure CN119536113A_ABST
Patent Text Reader

Abstract

The invention provides a code generation method for graphical programming. The method comprises the steps of generating a dependency tree based on a function block instance set, performing depth-first traversal on the dependency tree, arranging all function blocks in a traversal sequence, and generating codes for calling the function blocks according to the sequence of traversal results. According to the method, necessary information can be extracted from the programming result of the user, the execution sequence of all the function blocks is determined, the appropriate function block calling codes are generated, and use is convenient.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of graphical programming, and in particular to a code generation method for graphical programming. Background Art

[0002] In DDC devices and edge smart devices, a large number of devices require secondary programming to meet the application of specific scenarios on site. The programming method has also evolved from table lookup programming and text code programming to graphical programming. What is different from the graphical programming such as IEEE61131-3 of industrial PLC is that PLC programming presets many rules that users need to learn, and has clear input and output and function block execution order requirements. In DDC devices and edge smart devices, in order to support the construction of more complex program logic and lower the threshold for use, free topology graphical programming is often used. This relatively free programming method is more user-friendly, but how to determine the execution order and generate code that meets the user's expected execution results is a major problem facing smart devices. Therefore, it is very necessary to design a code generation method for graphical programming. Summary of the invention

[0003] In order to overcome the deficiencies of the prior art, an object of the present invention is to provide a code generation method for graphical programming.

[0004] To achieve the above object, the present invention provides the following solutions:

[0005] The present invention provides a graphical programming code generation method, comprising:

[0006] Generate a dependency tree based on a set of function block instances;

[0007] Traverse the dependency tree in depth first and arrange the functional blocks in the order of traversal;

[0008] Generate code for calling function blocks according to the order of traversal results.

[0009] Preferably, a dependency tree is generated based on a set of function block instances, specifically:

[0010] Scan and establish a set of function block instances;

[0011] Scan all ports and attach them to function block instance collections;

[0012] Scan all the connections, assign values ​​to the input port and output port of each connection to establish a bidirectional reference relationship, and generate a corresponding table of the connection and the corresponding output port for debugging the state output connection value;

[0013] Add an identifier "traveled" to each function block instance object to indicate that the function block instance object has been traversed;

[0014] Find a function block instance object whose output is not wired;

[0015] Recursively search for dependent function block instance objects, mark them as traveled, and repeat this step until the end condition is reached;

[0016] Repeatedly search for a function block instance object whose output is not connected until the end condition is reached;

[0017] Search for function block instance objects without the traveled mark. If not found, complete the generation of the dependency tree. If found, recursively search for dependent function block instance objects and make a traveled mark.

[0018] Preferably, the dependent function block instance object is recursively searched, and the traveled mark is made, and this step is repeated until the end condition is reached, specifically:

[0019] End conditions include:

[0020] Other function blocks that the current function block instance object depends on are not found;

[0021] The current function block instance object is the root, a loop is generated, and the current function block is not recorded;

[0022] The current function block instance object has the traveled flag, has been traversed, and the current function block is not recorded.

[0023] Preferably, repeatedly searching for a function block instance object whose output is not connected until the end condition is reached, specifically:

[0024] The end condition is: no function block instance object that meets the output no wiring condition is found.

[0025] According to the specific embodiments provided by the present invention, the present invention discloses the following technical effects:

[0026] The present invention provides a method for generating code for graphical programming, the method comprising generating a dependency tree based on a set of function block instances, traversing the dependency tree in depth-first order, arranging each function block in the order of traversal, and generating a code for calling the function block according to the order of traversal results. The present invention can extract necessary information from the user's programming results, determine the execution order of each function block, and generate a method for generating a suitable function block calling code, and is easy to use. BRIEF DESCRIPTION OF THE DRAWINGS

[0027] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments will be briefly introduced below. 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 paying creative labor.

[0028] Figure 1 A flow chart of a method provided by an embodiment of the present invention;

[0029] Figure 2 Edit the result diagram for the user;

[0030] Figure 3 It is a schematic diagram of the dependency tree 1 structure;

[0031] Figure 4 It is a schematic diagram of the dependency tree 2 structure;

[0032] Figure 5 Schematic diagram of the deformation structure of dependency tree 2. DETAILED DESCRIPTION

[0033] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0034] The purpose of the present invention is to provide a method for generating code for graphical programming, which can extract necessary information from the user's programming results, determine the execution order of each function block, and generate a method for generating appropriate function block calling code, which is easy to use.

[0035] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the present invention is further described in detail below with reference to the accompanying drawings and specific embodiments.

[0036] Figure 1 A flow chart of a method provided by an embodiment of the present invention, such as Figure 1 As shown, the present invention provides a code generation method for graphical programming, comprising:

[0037] Step 100: Generate a dependency tree based on a set of function block instances;

[0038] Step 200: traverse the dependency tree in depth first and arrange each functional block in the order of traversal;

[0039] Step 300: Generate code for calling a function block according to the order of the traversal results.

[0040] The overall idea of ​​this method is introduced as follows:

[0041] First, the direct expression of programming results is introduced, including three types of object sets:

[0042] 1. Function block object set:

[0043] The function block object set consists of function block instances;

[0044] The function block instance data only contains the attributes of its own instance, without the subordinate port information and connection information.

[0045] 2. Port object set:

[0046] A port object set consists of port object instances;

[0047] Ports refer to the input / output variables of a function block;

[0048] Each port instance in the port object set has an index pointing to the function block object to which it belongs.

[0049] 3. Connection object set:

[0050] The wire object set consists of wire instances;

[0051] Each wire instance represents a wire;

[0052] Each wire instance contains information pointing to the ports it is connected to on both sides.

[0053] The programming result is a network similar to a graph structure. It is called similar to a graph structure rather than a graph structure because a graph structure is composed of nodes and lines, and multiple lines of a node are equivalent. In graphical programming, function block instances are not considered nodes because the lines are not connected to function blocks but to ports, and ports are not nodes because in addition to lines, ports also have the relationship of belonging to the same function block instance. Because it is not a graph structure, the data structure that expresses the graph structure is difficult to express the connection relationship of function blocks. It is not a tree structure either, and the tree data structure is also difficult to express the connection relationship of function blocks.

[0054] Therefore, you need to define your own data structure. Two principles should be considered when defining your own data structure: being able to express connection relationships and being easy to generate code;

[0055] Refactor the programming results with the goal (generated code) as the guide, and reconstruct the graph-like structure of the programming results into multiple dependency tree structures;

[0056] The general principles of the dependency tree are:

[0057] 1. Output function block instance (block with only Input connected) as the root of the dependency tree;

[0058] 2. If it is a pure loop, take any function block as the root;

[0059] 3. Check the dependency relationship from the input of the root function block instance forward to the input type function block (the function block with only output connections).

[0060] The process of code generation is the process of depth-first traversal of the dependency tree.

[0061] The present invention provides an embodiment, wherein the user editing result schematic diagram is as follows Figure 2 As shown, the two generated dependency tree structure diagrams are as follows Figure 3 and Figure 4 shown.

[0062] Problems that need to be solved during the dependency tree building process:

[0063] 1. If it is a pure cycle, there must be an exit mechanism:

[0064] A. A function block instance cannot depend on itself. If it does, it will terminate and exit.

[0065] B. Return when encountering a function block for which code has been generated.

[0066] 2. In order to ensure that each function block instance is executed only once, the function blocks in the dependency tree must not be repeated:

[0067] A. Therefore, a function block instance can only appear once in the dependency tree. If you only look at dependency tree 2, the following Hardware Input 102 should be removed;

[0068] In multiple dependency trees, function block instances cannot be repeated. Looking at the two dependency trees as a whole, dependency tree 2 becomes as follows: Figure 5 The structure shown.

[0069] The detailed operation process of the method recorded in the present invention is introduced:

[0070] In step 100, a dependency tree is generated based on the function block instance set, specifically:

[0071] Step 101: Scan and establish a function block instance set;

[0072] Step 102: Scan all ports and attach the ports to a function block instance set;

[0073] Step 103: Scan all the connections, assign values ​​to the input port and output port of each connection to establish a bidirectional reference relationship, and generate a corresponding table of the connection and the corresponding output port for debugging the state output connection value;

[0074] Step 104: Add an identifier "traveled" to each function block instance object to indicate that the function block instance object has been traversed;

[0075] Step 105: Find a function block instance object whose output is not connected;

[0076] Step 106: recursively search for dependent function block instance objects, and mark them as traveled, and repeat this step until the end condition is reached;

[0077] Step 107: repeating step 105, i.e. searching for a function block instance object whose output is not connected, until the end condition is reached;

[0078] Step 108: Repeat step 106, that is, search for the function block instance object without the traveled mark. If not found, complete the generation of the dependency tree. If found, recursively search for the dependent function block instance objects and make the traveled mark.

[0079] In step 106, the dependent function block instance object is recursively searched and the traveled mark is made, and this step is repeated until the end condition is met, specifically:

[0080] End conditions include:

[0081] Other function blocks that the current function block instance object depends on are not found;

[0082] The current function block instance object is the root, a loop is generated, and the current function block is not recorded;

[0083] The current function block instance object has the traveled flag, has been traversed, and the current function block is not recorded.

[0084] In step 107, a function block instance object whose output is not connected is repeatedly searched until the end condition is reached, specifically:

[0085] The end condition is: no function block instance object that meets the output no wiring condition is found.

[0086] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.

[0087] The principles and implementation methods of the present invention are described in this article using specific examples. The description of the above embodiments is only used to help understand the method and core idea of ​​the present invention. At the same time, for those skilled in the art, according to the idea of ​​the present invention, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as limiting the present invention.

Claims

1. A graphical programming code generation method, characterized in that: include: Generate a dependency tree based on a set of function block instances; Traverse the dependency tree in depth first and arrange the functional blocks in the order of traversal; Generate code for calling function blocks according to the order of traversal results.

2. The method according to claim 1, characterized in that Generate a dependency tree based on the function block instance set, specifically: Scan and establish a set of function block instances; Scan all ports and attach them to function block instance collections; Scan all the connections, assign values ​​to the input port and output port of each connection to establish a bidirectional reference relationship, and generate a corresponding table of the connection and the corresponding output port for debugging the state output connection value; Add an identifier "traveled" to each function block instance object to indicate that the function block instance object has been traversed; Find a function block instance object whose output is not wired; Recursively search for dependent function block instance objects, mark them as traveled, and repeat this step until the end condition is reached; Repeatedly search for a function block instance object whose output is not connected until the end condition is reached; Search for function block instance objects without the traveled mark. If not found, complete the generation of the dependency tree. If found, recursively search for dependent function block instance objects and make a traveled mark.

3. The method according to claim 2, characterized in that Recursively search for dependent function block instance objects, mark them as traveled, and repeat this step until the end condition is reached, specifically: End conditions include: Other function blocks that the current function block instance object depends on are not found; The current function block instance object is the root, a loop is generated, and the current function block is not recorded; The current function block instance object has the traveled flag, has been traversed, and the current function block is not recorded.

4. The method according to claim 2, characterized in that: Repeatedly search for a function block instance object whose output is not connected until the end condition is reached, specifically: The end condition is: no function block instance object that meets the output no wiring condition is found.

Citation Information

Patent Citations

  • Programming method, system and computer of DDC (Direct Digital Control) logic

    CN102063068A

  • Function block ordering method on basis of information flow

    CN102608934A

  • Method for converting ladder diagram developed by programmable logic controller (PLC) into statement list

    CN102736552A

  • Resource-bundle obtaining method and device, equipment and computer readable storage medium

    CN108536463A

  • System, method and device for automatically generating program according to function block diagram

    CN110147226A