A graphical programming code generation method

By generating a dependency tree and performing a depth-first traversal, the problem of uncertain execution order in graphical programming of DDC devices and edge intelligent devices is solved, generating functional block call code that meets user expectations.

CN119536113BActive Publication Date: 2026-05-29TONGFANG TECHNOVATOR INT (BEIJING) CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
TONGFANG TECHNOVATOR INT (BEIJING) CO LTD
Filing Date
2024-11-06
Publication Date
2026-05-29

AI Technical Summary

Technical Problem

In DDC devices and edge intelligent devices, the graphical programming method of free topology makes it difficult to determine the execution order and generate code that meets the user's expected execution results.

Method used

By generating a dependency tree, a depth-first traversal of the dependency tree is performed to determine the execution order of the functional blocks, and the code for calling the functional blocks is generated based on the traversal results.

Benefits of technology

It enables the extraction of necessary information from user programming results, determination of function block execution order, and generation of appropriate function block call code for ease of use.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119536113B_ABST
    Figure CN119536113B_ABST
Patent Text Reader

Abstract

The application provides a graphical programming code generation method, which comprises the following steps: generating a dependency tree based on a functional block instance set, performing depth-first traversal on the dependency tree, arranging the functional blocks in the order of traversal, and generating a code for calling the functional blocks according to the order of the traversal result. The application can extract necessary information from the user's programming result, determine the execution order of the functional blocks, and generate a suitable functional block calling code, which is convenient to use.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of graphical programming technology, and in particular to a method for generating code for graphical programming. Background Technology

[0002] In DDC (Distributed Data Center) devices and edge intelligent devices, many require secondary programming to meet specific application scenarios. Programming methods have evolved from lookup table programming and text-based code programming to graphical programming. Unlike the graphical programming of industrial PLCs (such as IEEE 61131-3), which pre-defines many rules that users need to learn and has explicit requirements for input / output and function block execution order, DDC and edge intelligent devices often employ free-topology graphical programming to support more complex program logic and lower the barrier to entry. While this more flexible programming approach is user-friendly, determining the execution order and generating code that matches the user's expected execution results remains a significant challenge for intelligent devices. Therefore, designing a graphical programming code generation method is essential. Summary of the Invention

[0003] To overcome the shortcomings of existing technologies, the purpose of this invention is to provide a graphical programming code generation method.

[0004] To achieve the above objectives, the present invention provides the following solution:

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

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

[0007] The dependency tree is traversed in a depth-first manner to arrange the functional blocks in the order of traversal.

[0008] The code for calling the function block is generated based on the order of the traversal results.

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

[0010] Scan to create a collection of function block instances;

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

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

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

[0014] Find a function block instance whose output has no wires;

[0015] Recursively search for dependent function block instances and mark them as traveled. Repeat this step until the termination condition is met.

[0016] Repeatedly search for a function block instance object whose output has no connection until the termination condition is met;

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

[0018] Preferably, the dependent function block instance objects are recursively searched, and the "traveled" flag is marked. This step is repeated until the termination condition is met, specifically:

[0019] Termination conditions include:

[0020] No other function blocks were found that the current function block instance depends on.

[0021] The current function block instance is the root, which creates a loop, so the current function block is not recorded.

[0022] The current function block instance object has the "traveled" flag, indicating that it has already been traversed, and the current function block will not be recorded.

[0023] Preferably, the search is repeated for a function block instance object whose output has no connection until the termination condition is met, specifically:

[0024] The termination condition is: no function block instance object matching the condition of no connection in the output is found.

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

[0026] This invention provides a graphical programming code generation method. The method includes generating a dependency tree based on a set of function block instances, performing a depth-first traversal of the dependency tree, arranging the function blocks in the traversal order, and generating code to call the function blocks according to the traversal results. This invention can extract necessary information from the user's programming results, determine the execution order of each function block, and generate appropriate function block calling code, making it easy to use. Attached Figure Description

[0027] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0028] Figure 1 A flowchart of the method provided in an embodiment of the present invention;

[0029] Figure 2 A diagram showing the results of the user's editing;

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

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

[0032] Figure 5 This is a schematic diagram of the deformed structure of dependency tree 2. Detailed Implementation

[0033] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0034] The purpose of this invention is to provide a graphical programming code generation method that can extract necessary information from the user's programming results, determine the execution order of each functional block, and generate appropriate functional block call code, making it easy to use.

[0035] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, the present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments.

[0036] Figure 1 The method flowchart provided in the embodiments of the present invention is as follows: Figure 1 As shown, this invention provides a graphical programming code generation method, including:

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

[0038] Step 200: Perform a depth-first traversal of the dependency tree to arrange the functional blocks in the traversal order;

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

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

[0041] First, we will introduce the direct ways of expressing programming results, including three types of object sets:

[0042] 1. Function block object set:

[0043] A set of function block objects consists of function block instances;

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

[0045] 2. Port object set:

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

[0047] A port refers to the input / output variable of a function block;

[0048] Each port instance in the port object set has an index pointing to its own function block object.

[0049] 3. Set of connected objects:

[0050] A set of connection objects consists of connection instances;

[0051] Each connection instance represents a connection;

[0052] Each connection instance contains information pointing to the ports connected to both sides.

[0053] The programming result is a network resembling a graph structure. It's described as resembling a graph structure but not quite a graph structure because a graph structure consists of nodes and connections, and multiple connections to a given node are equivalent. However, in graphical programming, function block instances are not considered nodes because the lines connect to ports instead of function blocks. Ports are not nodes either, because ports are related not only by connections but also by belonging to the same function block instance. Because it's not a graph structure, data structures that represent graph structures struggle to express the connections between function blocks. Nor is it a tree structure, as tree data structures also struggle to express the connections between function blocks.

[0054] Therefore, it is necessary to define your own data structure. When defining your own data structure, consider two principles: it should be able to express the connection relationship and be easy to generate code.

[0055] Refactor the programming results with the goal (generated code) in mind, and refactor the graph-like structure of the programming results into a structure of multiple dependency trees;

[0056] The general principles of dependency trees are:

[0057] 1. Output the function block instance (referring to the block where only the Input has a connection) as the root of the dependency tree;

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

[0059] 3. Start from the Input of the root function block instance and trace the dependencies backward until you reach the input function block (the function block with only output connections).

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

[0061] This invention provides an embodiment in which a schematic diagram of the user editing result is shown below. Figure 2 As shown, the two generated dependency tree structure diagrams are respectively as follows: Figure 3 and Figure 4 As shown.

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

[0063] 1. If it's a pure loop, there needs to be an exit mechanism:

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

[0065] B. If a function block with already generated code is encountered, return.

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

[0067] A. Therefore, a function block instance can only appear once in the dependency tree. If we only look at dependency tree two, the Hardware Input 102 below 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 two becomes as follows: Figure 5 The structure shown.

[0069] The detailed operation process of the method described in this invention is as follows:

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

[0071] Step 101: Scan and build a set of function block instances;

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

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

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

[0075] Step 105: Locate a function block instance object whose output has no wires;

[0076] Step 106: Recursively search for dependent function block instance objects and mark them as traveled. Repeat this step until the termination condition is met.

[0077] Step 107: Repeat step 105, that is, find a function block instance object whose output has no connection, until the termination condition is met;

[0078] Step 108: Repeat step 106, that is, search for function block instance objects without the traveled mark. If not found, the dependency tree is generated. If found, recursively search for dependent function block instance objects and mark them with the traveled mark.

[0079] In step 106, recursively search for dependent function block instance objects and mark them as traveled. Repeat this step until the termination condition is met, specifically:

[0080] Termination conditions include:

[0081] No other function blocks were found that the current function block instance depends on.

[0082] The current function block instance is the root, which creates a loop, so the current function block is not recorded.

[0083] The current function block instance object has the "traveled" flag, indicating that it has already been traversed, and the current function block will not be recorded.

[0084] In step 107, the search continues for a function block instance object whose output has no connection until the termination condition is met. Specifically:

[0085] The termination condition is: no function block instance object matching the condition of no connection in the output is found.

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

[0087] This document uses specific examples to illustrate the principles and implementation methods of the present invention. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of the present invention. Furthermore, those skilled in the art will recognize that, based on the ideas of the present invention, there will be changes in the specific implementation methods and application scope. Therefore, the content of this specification should not be construed as a limitation of the present invention.

Claims

1. A method for generating code for graphical programming, characterized in that, include: A dependency tree is generated based on a collection of function block instances, specifically as follows: Scan to create a collection of function block instances; Scan all ports and attach them to the function block instance set; Scan all connections, assign values ​​to the input and output ports of each connection to establish a bidirectional reference relationship, and generate a table of connections and corresponding output ports for debugging to output connection values. Add a traveled identifier to each function block instance object to indicate that the function block instance object has been traversed; Find a function block instance whose output has no wires; Recursively search for dependent function block instances and mark them as traveled. Repeat this step until a termination condition is met. The termination condition includes: No other function blocks were found that the current function block instance depends on. The current function block instance is the root, which creates a loop, so the current function block is not recorded. The function block instance object will terminate and exit when it depends on itself. When encountering a function block instance object whose code has already been generated, return directly; The current function block instance object has the "traveled" flag, indicating that it has been traversed and will not be recorded. Repeatedly search for a function block instance object whose output has no connection until the termination condition is met. The termination condition is: no function block instance object that meets the condition of no output connection is found. Search for function block instance objects without the traveled flag. If not found, complete the generation of the dependency tree. If found, recursively search for dependent function block instance objects and mark them as traveled. The dependency tree is traversed in a depth-first manner to arrange the functional blocks in the order of traversal. Generate the code to call the function block according to the order of the traversal results; The dependency tree includes multiple dependency tree structures; to ensure that each function block instance is executed only once, the function block instance is limited to appearing only once in any dependency tree and not repeated in multiple dependency trees.