Method and device for generating self-defined FBD code of upper computer computing software
By defining variable information of input, output and parameters in the upper computer computing software, custom FBD code is generated and compiled into a dynamic link library, the problem of closed configuration design environment of the upper computer computing software is solved, and higher flexibility and openness are achieved.
Patent Information
- Application Number
- CN202510403886.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-01
- Publication Date
- 2025-07-04
AI Technical Summary
The configuration design environment of existing computer computing software is relatively closed, lacks flexibility and openness, and it is difficult to write customized control logic based on actual applications in the industrial site.
By defining variable information of input, output and parameters in the visual interface, custom FBD code is generated, and the dynamic library is used to generate read and write interface functions, which is compiled into a dynamic link library, which supports the dynamic loading and calling of custom FBD in the upper computer computing software.
It improves the openness and flexibility of the FBD programming environment of the upper computer computing software. Users can write control logic based on actual applications, enrich the configuration design interface, and reduce debugging costs.
Smart Images

Figure CN120255899A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of wind power generation, and particularly relates to a method and device for generating custom FBD codes for a host computer calculation software. Background Art
[0002] With the development of computer technology and network communication technology, the structure and function of embedded controllers have undergone a qualitative change. Based on the functions of traditional embedded controllers, the host computer calculation software inherits the powerful data processing and logical operation capabilities of the embedded controllers while eliminating the cost of embedded hardware.
[0003] The host computer calculation software needs to generate corresponding instruction codes based on the host computer FBD (function block diagram) configuration programming and then interpret and execute the instruction codes. This method limits the functions of the host computer calculation software to the pre-defined FBDs in the host computer system, which is not conducive to the openness of the configuration process. Summary of the Invention
[0004] The purpose of the present invention is to provide a method and device for generating custom FBD codes for a host computer calculation software to solve the technical problem of the relatively closed configuration design environment of the existing host computer calculation software.
[0005] To achieve the above object, the present invention adopts the following technical solutions: A method for generating custom FBD codes for a host computer calculation software includes the following steps: Create a new FBD, define the variable information of inputs, outputs, and parameters, and store it in a variable array; Traverse all variable arrays of inputs, outputs, and parameters, generate a variable list containing variable names, types, and default values, and export it as a dynamic library according to the variable list; Generate a read interface function based on the input variables and parameter variables in the dynamic library, and generate a write interface function based on the output variables in the dynamic library: Construct a running function with the pointer of the variable array as a function parameter, and the running function includes custom code logic; Use the above steps to generate FBD custom codes, compile the FBD custom codes to generate a dynamic link library for dynamic loading and calling by the host computer calculation software.
[0006] Further, the creation of the new FBD includes specifying the name, version number, and description information of the new FBD.
[0007] Further, the step of defining the variable information of inputs, outputs, and parameters and storing it in a variable array includes: Specify the name, data type, default value, and visibility of the input, and store the defined input variables in the input variable array; Specify the name, data type, default value, and visibility of the output, and store the defined output variables in the output variable array; Specify the name, data type, and default value of the parameter, and store the defined parameter variables in the parameter variable array.
[0008] Furthermore, before traversing all the variable arrays of inputs, outputs, and parameters, verify the number of variables. If the number of variables is less than the maximum number of variables allowed by FBD, continue; otherwise, the FBD definition fails.
[0009] Furthermore, the number of variables includes the total number of input variables, output variables, and parameter variables.
[0010] Furthermore, obtain the read variable interface based on the read interface function, and the read variable logic is as follows: Pass the pointer of the variable array and the variable name into the read variable interface; Traverse all the variables in the variable array. If the variable type is input or the variable type is a parameter, retrieve the variable name; Read the value of the variable and return the variable value to the read variable interface for external programs to call.
[0011] Furthermore, obtain the read variable interface based on the write interface function, and the write variable logic is as follows: Pass the pointer of the variable array, the variable name, and the value to be written into the write variable interface; Traverse all the variables in the variable array. If the variable type is output, retrieve the variable name; Write the variable value passed into the write variable interface into the corresponding variable to complete the assignment of the output variable.
[0012] In a second aspect, the present invention provides a host computer calculation software custom FBD code generation system, including a definition module, a library building module, a function generation module, and a compilation module, where: Definition module: used to create a new FBD, define the variable information of inputs, outputs, and parameters, and store it in the variable array; Library building module: used to traverse all the variable arrays of inputs, outputs, and parameters, generate a variable list including variable names, types, and default values, and export it as a dynamic library according to the variable list; Function generation module: used to generate a read interface function based on the input variables and parameter variables in the dynamic library, generate a write interface function based on the output variables in the dynamic library, construct a running function with the pointer of the variable array as a function parameter, and the running function includes custom code logic; Compilation module: It is used to generate FBD custom code by using the above steps, compile the FBD custom code to generate a dynamic link library for the host computer calculation software to perform dynamic loading and calling.
[0013] In a third aspect, a terminal device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the steps of the above method are implemented.
[0014] In a fourth aspect, a computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the above method are implemented.
[0015] Compared with the prior art, the present invention has the following beneficial technical effects: A method for generating custom FBD code for a host computer calculation software according to the present invention predefines information such as inputs, outputs, and parameters of FBD based on a visual interface. The virtual control generates corresponding custom code according to the software architecture and system interface. The user only needs to add the corresponding FBD operation logic at the reserved interface of the automatically generated code. After completing the writing of the FBD operation logic code, the compiler interface is automatically called to compile the custom code into a dynamic link library. After the virtual control is started, it automatically loads the input, output, parameter interface variables and operation functions in the dynamic link library to participate in the configuration logic operation; the present invention upgrades the FBD programming environment of the host computer calculation software to an open system, enabling users to write corresponding control logic according to the actual applications in the industrial field, and supporting adding custom FBDs to different task levels, greatly improving the flexibility and openness of the configuration system, and providing a richer configuration design interface for configuration designers.
[0016] Preferably, the inputs, outputs, and parameter variables are stored separately to achieve data structuring, reduce the complexity of variable management, and the definition of variable visibility enhances the encapsulation of the module to prevent illegal access.
[0017] Preferably, before traversing all variable arrays of inputs, outputs, and parameters, the number of variables is verified, which can effectively prevent the generation of invalid code and reduce the debugging cost. Description of the Drawings
[0018] Figure 1 It is a flowchart of a method for generating custom FBD code for a host computer calculation software in an embodiment of the present invention; Figure 2 It is a schematic diagram of the call of a custom FBD in a host computer calculation software in an embodiment of the present invention; Figure 3 It is a schematic diagram of the working principle of a custom FBD in an embodiment of the present invention; Figure 4 Schematic diagram of variable list code in an embodiment of the present invention; Figure 5 Schematic diagram of running function code in an embodiment of the present invention. Detailed implementation manners
[0019] In order to enable those skilled in the art to better understand the solution of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present invention.
[0020] It should be noted that similar reference numerals and letters denote similar items in the following drawings. Therefore, once an item is defined in one drawing, it does not need to be further defined and explained in subsequent drawings.
[0021] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above drawings are used to distinguish similar objects, and do not necessarily need to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged under appropriate circumstances so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "comprising" and "having" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, system, product or device comprising a series of steps or units does not necessarily have to be limited to those steps or units clearly listed, but may include other steps or units not clearly listed or inherent to these processes, methods, products or devices.
[0022] Parameter explanation: FBD: That is, Function Block Diagram, which is a graphical programming language widely used in industrial automation control systems. It represents the control logic and data flow of the system through intuitive graphical symbols and connections, and is easy to understand and use.
[0023] The present invention will be further described in detail below with reference to the accompanying drawings: As Figure 1 shown, a method for generating custom FBD code for a host computer calculation software includes the following steps: Step 1, create a new FBD, define the variable information of inputs, outputs and parameters, and store it in a variable array; In creating a new FBD, at this time, the user needs to specify the name, version number, and description information of the FBD; Define the variable information of inputs, outputs, and parameters and store it in a variable array, which specifically includes the definition of input variables, output variables, and parameter variables. Among them: Definition of input variables: Define the input variable InputVar, specifying the name of the input InputVar.name, data type InputVar.type, default value InputVar.default, and the visibility of the variable InputVar.visible; The visibility of the variable determines whether the corresponding input pin is generated and is visible to the user, and store the defined variable in the input variable array of the variable array VarArray.
[0024] Definition of output variables: Define the output variable OutputVar, specifying the name of the output OutputVar.name, data type OutputVar.type, default value OutputVar.default, and the visibility of the variable OutputVar.visible; The visibility of the variable determines whether the corresponding output pin is generated and is visible to the user, and store the defined output variable in the output variable array of the variable array VarArray.
[0025] Definition of parameter variables: Define the parameter variable ParaVar, specifying the name of the parameter ParaVar.name, data type ParaVar.type, default value ParaVar.default; Store the defined parameter variable in the parameter variable array VarArray.
[0026] Step 2: Traverse all variable arrays of inputs, outputs, and parameters, generate a variable list containing variable names, types, and default values, and export it as a dynamic library according to the variable list; Optionally, before traversing all variable arrays of inputs, outputs, and parameters, first verify the number of variables. The specific verification method is as follows: Verify the number of input, output, and parameter variables of the custom FBD; If VarArray.count > MAX_VAR, then prompt the user that the FBD definition fails at this time, otherwise continue with the subsequent steps; Among them, VarArray.count represents the total number of input variables, output variables, and parameter variables, and MAX_VAR represents the maximum number of variables allowed by the FBD.
[0027] Step 3: Generate a read interface function based on the input variables and parameter variables in the dynamic library, and generate a write interface function based on the output variables in the dynamic library; Based on the dynamic library of variables obtained in Step 2, generate a read interface function and a write interface function respectively, where: Obtain a read variable interface based on the read interface function, and the read variable logic is: Pass the pointer of the variable array and the variable name into the read variable interface; Traverse all variables in the variable array. If the variable type is input or the variable type is a parameter, retrieve the variable name; Read the value of the variable and return the variable value to the read variable interface for external programs to call.
[0028] Obtain a read variable interface based on the write interface function, and the write variable logic is: Pass the pointer of the variable array, the variable name, and the value to be written into the write variable interface; Traverse all variables in the variable array. If the variable type is output, retrieve the variable name; Write the variable value passed into the write variable interface into the corresponding variable to complete the assignment of the output variable.
[0029] Step 4: Construct a running function with the pointer of the variable array as a function parameter, and the running function includes custom code logic; Pass the pointer of the variable array as a function parameter into the running function of the function block, and add custom code logic inside the running function.
[0030] Step 5: Use the FBD custom code generated in the above steps to compile and generate a dynamic link library for the host computer calculation software to perform dynamic loading and calling.
[0031] In an embodiment of the present invention, a method for generating custom FBD code for a host computer calculation software is provided, including the following steps: Step 1: Create a new FBD. At this time, the user needs to specify the name, version number, and description information of the FBD; Step 2: Define the input, output, and parameter information of the FBD; Step 3: Define an input variable InputVar, specifying the input name InputVar.name, data type InputVar.type, default value InputVar.default, and the visibility InputVar.visible of the variable. The visibility of the variable determines whether the generated corresponding input pin is visible to the user. Store the defined variable in the input variable array VarArray; Step 4: Define the output variable OutputVar, specifying the output name OutputVar.name, data type OutputVar.type, default value OutputVar.default, and the visibility of the variable OutputVar.visible. The visibility of the variable determines whether to generate the corresponding output pin and whether it is visible to the user. Store the defined output variable in the output variable array VarArray; Step 5: Define the parameter variable ParaVar, specifying the parameter name ParaVar.name, data type ParaVar.type, and default value ParaVar.default. Store the defined parameter variable in the parameter variable array VarArray; Step 6: Verify the number of input, output, and parameter variables of the custom FBD. If VarArray.count > MAX_VAR, prompt the user that the FBD definition fails at this time. Otherwise, proceed to Step 6. (MAX_VAR represents the maximum number of variables allowed by the FBD); Step 7: Traverse the variables in the input variable list, output variable list, and parameter variable list, and obtain the variable name, variable type, and variable default value. Generate the corresponding variable list as Figure 4 shown, where Section 1 represents the variable name, Section 2 represents the variable type, and Section 3 represents the usage status of the variable. 0 represents the unused status, 1 represents the input status, 2 represents the output status, and 3 represents the parameter status; Step 8: Export the input, output, and parameter variables generated in Step 7 as a dynamic library; Step 9: Automatically generate the input and parameter variable read interface functions. For the read variable interface, the logic for reading variables is as follows: Pass the pointer of the variable array and the variable name to the read variable interface; Step 10: Traverse all variables in the variable array, and set i = 0; Step 11: Access the variable VarArray[i]. If the variable type is input or parameter, retrieve the variable name; Step 12: If the variable name is different from the variable name passed to the read variable interface, execute i = i + 1 and return to Step 11; if they are equal, execute Step 13; Step 13: Read the value of the variable VarArray[i] and return the variable value to the variable interface for external programs to call; Step 14: If i < MAX_VAR, return to Step 11; Step 15: Automatically generate the output variable write interface function. For the write variable interface, the logic for writing variables is as follows: Pass the pointer of the variable array, the variable name, and the value to be written to the write variable interface; Step 16: Traverse all variables in the variable array, and set i = 0; Step 17: Access VarArray[i]. If the variable type is output, retrieve the name of the variable; Step 18: If the variable name is different from the variable name passed into the write variable interface, execute i = i + 1 and return to Step 17; if they are equal, execute Step 19; Step 19: Write the variable value passed into the write variable interface into the corresponding variable. Complete the assignment of the output variable.
[0032] Step 20: If i < MAX_VAR, return to Step 17.
[0033] Step 21: For the running function of the function block, pass the pointer of the variable array as a function parameter into the running function of the function block. The pseudocode of the running function is as Figure 5 shown: As Figure 2 and Figure 3 shown, the user can access the values of the input function block through the read interface of the input parameter variables in the running function. Inside the running function, add custom code logic. After the operation is completed, output the calculated result to the output pin of the function block through the write interface function of the output variable.
[0034] Step 22: Compile the FBD custom code generated in the above steps to generate the corresponding dynamic library, which can be provided to the host computer calculation software for dynamic loading and calling. Implement the operation of the custom FBD in the host computer calculation software.
[0035] In another embodiment of the present invention, a system for generating FBD custom code for host computer calculation software is provided, including a definition module, a library construction module, a function generation module, and a compilation module, where: Definition module: used to create a new FBD, define the variable information of inputs, outputs, and parameters, and store it in the variable array; Library construction module: used to traverse all variable arrays of inputs, outputs, and parameters, generate a variable list containing variable names, types, and default values, and export it as a dynamic library according to the variable list; Function generation module: used to generate a read interface function based on the input variables and parameter variables in the dynamic library, generate a write interface function based on the output variables in the dynamic library, construct a running function with the pointer of the variable array as a function parameter, and the running function includes custom code logic; Compilation module: used to generate FBD custom code using the above steps, compile the FBD custom code to generate a dynamic link library for dynamic loading and calling by the host computer calculation software.
[0036] In summary, the present invention provides a method for generating custom FBD code for a host computer calculation software. This method upgrades the FBD programming environment of the host computer calculation software to an open system, enabling users to write corresponding control logics according to the actual applications in the industrial field, and supporting the addition of custom FBDs to different task levels, greatly improving the flexibility and openness of the configuration system and providing more abundant configuration design interfaces for configuration designers.
[0037] Those skilled in the art should understand that the embodiments of the present invention can be provided as a method, a system, or a computer program product. Therefore, the present invention can take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present invention can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk memories, CD-ROMs, optical memories, etc.) containing computer-usable program codes.
[0038] The present invention is described with reference to the flowcharts and / or block diagrams of methods, apparatuses (systems), and computer program products according to embodiments of the present invention. It should be understood that each flow and / or block in the flowcharts and / or block diagrams, as well as the combination of flows and / or blocks in the flowcharts and / or block diagrams, can be realized by computer program instructions. These computer program instructions can be provided to the processors of general-purpose computers, special-purpose computers, embedded processors, or other programmable data processing devices to generate a machine, such that the instructions executed by the processors of the computer or other programmable data processing devices generate means for realizing the functions specified in one Figure 1 flow or multiple flows and / or blocks Figure 1 block or multiple blocks.
[0039] These computer program instructions can also be stored in a computer-readable memory that can direct a computer or other programmable data processing device to work in a specific manner, such that the instructions stored in the computer-readable memory generate a manufactured article including instruction means that realizes the functions specified in one Figure 1 flow or multiple flows and / or blocks Figure 1 block or multiple blocks.
[0040] These computer program instructions can also be loaded onto a computer or other programmable data processing device, such that a series of operation steps are executed on the computer or other programmable device to generate a computer-implemented process, and thus the instructions executed on the computer or other programmable device provide steps for realizing the functions specified in one Figure 1 flow or multiple flows and / or blocks Figure 1 block or multiple blocks.
[0041] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention rather than to limit the scope of its protection. Although the present invention has been described in detail with reference to the above embodiments, those of ordinary skill in the art should understand that after reading the present invention, various changes, modifications or equivalent substitutions can still be made to the specific implementation manners of the invention. However, these changes, modifications or equivalent substitutions are all within the scope of protection of the claims pending for the invention.
Claims
1. A method for generating custom FBD code in a host computer calculation software, characterized in that, It includes the following steps: Create a new FBD, define the variable information of inputs, outputs, and parameters, and store it in a variable array; Traverse all variable arrays of inputs, outputs, and parameters, generate a variable list containing variable names, types, and default values, and export it as a dynamic library according to the variable list; Based on the input variables and parameter variables in the dynamic library, generate read interface functions, and based on the output variables in the dynamic library, generate write interface functions: Construct a running function with the pointer of the variable array as a function parameter, and the running function includes custom code logic; Use the above steps to generate FBD custom code, compile the FBD custom code to generate a dynamic link library for dynamic loading and calling by the host computer calculation software.
2. The method for generating a custom FBD code for a host computer calculation software according to claim 1, wherein The said creating a new FBD includes specifying the name, version number, and description information of the new FBD.
3. A method for generating a custom FBD code of a host computer calculation software according to claim 1, characterized in that, The step of defining the variable information of inputs, outputs, and parameters and storing it in a variable array includes: Specify the name, data type, default value, and visibility of the input, and store the defined input variables in the input variable array; Specify the name, data type, default value, and visibility of the output, and store the defined output variables in the output variable array; Specify the name, data type, and default value of the parameter, and store the defined parameter variables in the parameter variable array.
4. A method for generating a customized FBD code of a host computer calculation software according to claim 1, characterized in that Before traversing all variable arrays of inputs, outputs, and parameters, verify the number of variables. If the number of variables is less than the maximum number of variables allowed by the FBD, continue; otherwise, the FBD definition fails.
5. A method for generating a custom FBD code for a host computer calculation software according to claim 4, characterized in that, The said number of variables includes the total number of input variables, output variables, and parameter variables.
6. A method for generating custom FBD code for a host computer calculation software according to claim 1, characterized in that, Based on the said read interface function, obtain a read variable interface, and the read variable logic is: Pass the pointer of the variable array and the variable name into the read variable interface; Traverse all variables in the variable array. If the variable type is input or the variable type is a parameter, retrieve the variable name; Read the value of the variable and return the variable value to the read variable interface for external programs to call.
7. A method for generating a custom FBD code of a host computer calculation software according to claim 1, characterized in that Based on the said write interface function, obtain a write variable interface, and the write variable logic is: Pass the pointer of the variable array, the variable name, and the value to be written into the write variable interface; Traverse all variables in the variable array. If the variable type is output, retrieve the variable name; Write the variable value passed into the write variable interface into the corresponding variable to complete the assignment of the output variable.
8. An upper computer calculation software custom FBD code generation system, characterized in that, It includes a definition module, a library building module, a function generation module, and a compilation module, where: Definition module: used to create a new FBD, define the variable information of inputs, outputs, and parameters, and store it in a variable array; Library building module: used to traverse all variable arrays of inputs, outputs, and parameters, generate a variable list containing variable names, types, and default values, and export it as a dynamic library according to the variable list; Function generation module: used to generate read interface functions based on the input variables and parameter variables in the dynamic library, generate write interface functions based on the output variables in the dynamic library, construct a running function with the pointer of the variable array as a function parameter, and the running function includes custom code logic; Compilation module: It is used to generate FBD custom code by using the above steps, compile the FBD custom code to generate a dynamic link library for dynamic loading and calling by the host computer calculation software.
9. A terminal device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1-7.
10. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by the processor, it implements the steps of the method according to any one of claims 1-7.