A method and apparatus for generating function blocks for PLC control programs
By automatically generating function blocks for PLC control programs, the problem of cumbersome timing database operations in PLC control programs is solved, thus simplifying operations and improving development efficiency.
Patent Information
- Application Number
- CN202211656309.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-22
- Publication Date
- 2025-12-02
- Estimated Expiration
- 2042-12-22
AI Technical Summary
In PLC control programs, repeatedly creating similar function blocks when operating the timing database is tedious. Existing technologies lack methods for automatically generating function blocks, resulting in high development complexity.
By accessing a time-series database, time-series information is obtained, and function blocks conforming to the IEC 61131-3 standard are automatically generated and converted into XML files, simplifying the operation process.
It greatly simplifies the complexity of timing database operations, improves the development efficiency of PLC control programs, and reduces workload.
Smart Images

Figure CN116125902B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of PLC control technology, specifically relating to a method and apparatus for generating function blocks for PLC control programs. Background Technology
[0002] A function block (FB) is a program organization unit (POU) proposed in the IEC 61131-3 PLC programming language that can produce one or more values when executed. It is used to modularize and construct well-defined parts of a PLC program.
[0003] Time-series databases have become widely used with the development of the Industrial Internet of Things (IIoT). Operating time-series databases using PLC control programs is a common practice. However, operating on specific sets of data requires repeatedly creating similar function blocks, which is tedious.
[0004] Therefore, in view of the technical defects of the existing technology, it is necessary to propose a technical solution to solve the technical problems existing in the existing technology. Summary of the Invention
[0005] The purpose of this invention is to overcome the shortcomings of the prior art, adapt to the needs of practical applications, and provide a method and apparatus for generating function blocks for PLC control programs. It automatically generates function blocks that can be used in PLC control programs according to user settings, and realizes the extraction of path node information of time series from time series database, and automatically generates function block XML files that can be used to control PLC programs, thereby greatly simplifying the operation of time series data.
[0006] In order to solve the technical problems existing in the prior art, the technical solution of the present invention is as follows:
[0007] A method for generating function blocks for PLC control programs includes at least the following steps:
[0008] Step S1: Access the corresponding time series database and obtain time series information based on user input information;
[0009] Step S2: Create corresponding function blocks based on the specific time series information selected by the user to generate standard-compliant XML strings;
[0010] Step S3: Integrate all generated XML strings and output an XML file for use in the PLC control program.
[0011] As a further improvement, step S1 further includes:
[0012] Step S11: Obtain the login information entered by the user and log in to the time series database server. By reading the schema of the time series database, automatically obtain the path node information of the time series in the time series database.
[0013] Step S12: List the path node information of the time series read in step S11 in tabular form, convert the path node information of the time series that the user selects to read into the output pin of the function block, and convert the path node information of the time series that the user wants to write into the input pin of the function block.
[0014] As a further improvement, step S2 further includes:
[0015] Create a function block and add the necessary enable pins; add the function block pins generated in step S12 to the function block and add a timestamp pin; based on the path node information of the added time series, replace the code required for the automatically generated function block to run according to the different templates selected for reading and writing.
[0016] For further improvements, the function block pins shall include at least an input pin for starting the function block, an output pin for ending the function block, and a timestamp pin corresponding to the time series.
[0017] For further improvement, when the timestamps of the selected time series are aligned, that is, the timestamps of the selected time series are always the same, only one timestamp pin is added to the function block; when the timestamps of the selected time series are not related, a separate timestamp pin is added to each time series.
[0018] For further improvement, the structure of the function block is the function block structure specified in the IEC 61131-3 standard.
[0019] To further improve the solution, in step S3, the function block is serialized to generate an XML string, and the serialized code generated in step S2 is inserted into the corresponding position. Finally, the XML string is saved as an XML file.
[0020] For further improvements, the format of the XML file depends on the specific configuration format of the target PLC.
[0021] The present invention also discloses a function block generation device for PLC control programs, comprising at least:
[0022] The reading module is used to access the corresponding time series database and obtain time series information based on user input.
[0023] The function block creation module is used to create corresponding function block objects based on the time series selected by the user and automatically generate corresponding code for them;
[0024] The function block storage module is used to generate XML files of the corresponding format from one or more function block objects for use in PLC control programs.
[0025] As a further improvement, the reading module is specifically used for: retrieving path node information of a time series from a time series database based on user input; converting the path node information of the time series into a data table for user viewing; and saving the obtained data table as a file for separate viewing.
[0026] The function block creation module is specifically used for: creating the basic data required for function blocks; converting the path node information of the selected time series into the interface of the function block according to the user's selection; and automatically generating the required code contained in the function block according to the selected time series and database operation methods.
[0027] The function block storage module is specifically used for: serializing created function blocks to generate corresponding XML strings; serializing generated code to generate XML strings; merging XML strings generated from multiple function blocks into a single XML string; and saving XML strings as corresponding XML files.
[0028] As a further improvement, the function block is the function block specified in IEC 61131-3.
[0029] As a further improvement, the format of the XML file depends on the specific configuration format of the target PLC.
[0030] Compared with the prior art, the present invention has at least the following beneficial effects:
[0031] This invention significantly reduces the complexity of time-series database development in the industrial internet environment and improves development efficiency by integrating time-series database operations and automatically generating the required code. Attached Figure Description
[0032] Figure 1 This is a flowchart of a method for generating function blocks for PLC control programs according to the present invention.
[0033] Figure 2 This is a flowchart of the data reading module implementation method in step S1 of the present invention.
[0034] Figure 3 This is a flowchart illustrating the implementation method of generating function blocks and XML files in step S2 of the present invention.
[0035] Figure 4This is a schematic diagram illustrating the conversion process from path node information of the time series to functional blocks and then to XML files in step S3 of an embodiment of the present invention.
[0036] Figure 5 This is a schematic diagram of the function block generation device for PLC control programs according to the present invention. Detailed Implementation
[0037] 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, not all, of the embodiments of the present invention. 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.
[0038] See Figure 1 The diagram illustrates a method for generating function blocks in a PLC control program according to the present invention, comprising at least the following steps:
[0039] Step S1: Access the corresponding time series database and obtain time series information based on user input information;
[0040] Step S2: Create corresponding function blocks based on the specific time series information selected by the user to generate standard-compliant XML strings;
[0041] Step S3: Integrate all generated XML strings and output an XML file for use in the PLC control program.
[0042] In a preferred embodiment of the present invention, the IotDB time-series database is used, and an XML file as specified in the IEC61131-10 standard is generated at the end. The embodiment is as follows:
[0043] See Figure 2 The diagram shown is a flowchart of step S1 in an embodiment of the present invention. Step S1 specifically includes:
[0044] In step 101, the server information input by the user is obtained.
[0045] This information is essential for logging into the time-series database server and typically includes the server's IP address, port number, username, and password. This information is usually entered by the user using a keyboard or other human-computer interaction device.
[0046] In step 102, log in to the time series database server.
[0047] The login method is based on the type of time-series database selected. For example, it can be done through the database's pre-defined program interface; or through the database's built-in client script file. In this embodiment, the login is achieved by calling the script file for the IoTDB client.
[0048] In step 103, a time series read command is sent to the time series database server.
[0049] The read command depends on the type of time series database selected. In this embodiment, the IotDB database is used, and the "show timeseries" command can be used to read the path node information of the time series.
[0050] In step 104, the returned data is converted into a data table. In this embodiment, the returned string is converted into the DataTable data type in the C# language. Figure 4 Table 301 in the table is an example of a data table, which contains information such as the name of the time series, the warehouse to which it belongs, the data type, the encoding method, and the compression method.
[0051] See Figure 3 The diagram shows a flowchart of the implementation method for generating functional blocks and XML files in step S2 of an embodiment of the present invention, which specifically includes:
[0052] In step 201, the user is prompted to select one or more time series.
[0053] The data table generated in step 104 is displayed to the user in a tabular format, and then the numbers of one or more time series selected by the user are obtained.
[0054] In step 202, the corresponding function blocks are generated.
[0055] The content of the functional blocks is specified by the international standard IEC 61131-3.
[0056] Create a function block object and add basic content to it. For example, variables for starting the function block and displaying the results. Then add the variables selected in step 201 for transforming the time series data into the function block to the function block. The transformation method is as follows:
[0057] First, based on the user's selection of the function block operation, determine the position (input pin or output pin) and sequence number of the function block pin for time series conversion.
[0058] Then, the time series name is converted to a variable name, and non-standard characters are converted. For example, "." is converted to "_". In this embodiment, the content of the timeseries field is converted into the VARName variable of the function block.
[0059] Then, the data type of the time series is converted to the data type of the variable. For example, "BOOLEAN" is converted to "BOOL", and "DOUBLE" is converted to "REAL". In this embodiment, the content of the DataType field is converted into the Type variable of the function block pin.
[0060] Finally, based on the selected time series, a corresponding timestamp variable is automatically generated and added to the function block. In this embodiment, a timestamp pin is added to the function block, with data type DINT.
[0061] There are two methods for adding the timestamp pin:
[0062] Firstly, when the timestamps of the selected time series are aligned, meaning that the timestamps of these time series are always the same, only a pin named timestamp needs to be added to the function block.
[0063] Secondly, when the timestamps of the selected time series are not related, add a separate timestamp pin to each time series and name it after the time series name plus a capital letter T. For example, the timestamp of the sg1.d1 time series is sg1_d1T.
[0064] like Figure 4 Figure 302 shows an example of a created function block. The input pin is the automatically added Execute pin, used to start the function block. The output pins include the Done pin indicating the completion of the function block, the time series pin added after conversion, and the automatically added timestamp pin. Here, an aligned timestamp pin is added.
[0065] In step 203, a standard-compliant XML string is generated.
[0066] First, convert the pins of the function block into corresponding XML strings. For example, when converting input pins into XML strings, the pin number, name, and type variables need to be filled into the inputVARId, inputVARName, and inputType fields.
[0067] Then, the function block is converted into a corresponding XML string, and the XML string for the function block pin conversion is inserted into the appropriate position. For example, all the XML strings for the input pin conversion are inserted into the InputVARs field, and the number of pins is automatically calculated and filled into the number field.
[0068] like Figure 4Figure 303 shows the XML string for function block conversion. The pin names, data types, etc., have been automatically filled into the corresponding nodes, and the pin serial numbers have been automatically generated.
[0069] In step 204, the user is asked whether they want to continue adding function blocks.
[0070] If the user chooses to continue adding, the process will loop starting from step 201.
[0071] In step 205, an XML file is generated.
[0072] Combine the XML strings of all created functional blocks to output an XML file that meets the requirements.
[0073] See Figure 5 The diagram shows a model of the function block generation device for PLC control programs according to the present invention, which includes at least:
[0074] The reading module is used to access the corresponding time series database and obtain time series information based on user input.
[0075] The function block creation module is used to create corresponding function block objects based on the time series selected by the user and automatically generate corresponding code for them;
[0076] The function block storage module is used to generate XML files of the corresponding format from one or more function block objects for use in PLC control programs.
[0077] As a further improvement, the reading module is specifically used for: retrieving path node information of the time series from the time series database based on user input; converting the path node information of the time series into a data table for user viewing; and saving the obtained data table as a file for separate viewing.
[0078] The function block creation module is specifically used for: creating the basic data required for function blocks; converting the path node information of the selected time series into the interface of the function block according to the user's selection; and automatically generating the C language code contained in the function block according to the selected time series and database operation method.
[0079] The function block storage module is specifically used for: serializing created function blocks to generate corresponding XML strings; serializing generated code to generate XML strings; merging XML strings generated from multiple function blocks into a single XML string; and saving XML strings as corresponding XML files.
[0080] This embodiment greatly simplifies the intermediate steps from the timing database to the standard PLC control system by automatically generating function block code and XML files. It can easily import internationally compliant function blocks into the PLC control software to manipulate the time series data in the timing database, thus minimizing the workload.
[0081] It should be understood that the exemplary embodiments described herein are illustrative and not restrictive. Although one or more embodiments of the invention have been described in conjunction with the accompanying drawings, those skilled in the art will understand that various changes in form and detail may be made without departing from the spirit and scope of the invention as defined by the appended claims.
Claims
1. A method for generating function blocks in a PLC control program, characterized in that, At least the following steps are included: Step S1: Access the corresponding time series database and obtain time series information based on user input information; Step S2: Create corresponding function blocks based on the specific time series information selected by the user to generate standard-compliant XML strings; Step S3: Integrate all generated XML strings and output an XML file for use in the PLC control program; Step S1 includes: Step S11: Obtain the login information entered by the user and log in to the time series database server. By reading the schema of the time series database, automatically obtain the path node information of the time series in the time series database. Step S12: List the path node information of the time series read in step S11 in tabular form, convert the path node information of the time series that the user selects to read into the output pin of the function block, and convert the path node information of the time series that the user wants to write into the input pin of the function block. Step S2 includes: Create a function block and add the necessary enable pins; add the function block pins generated in step S12 to the function block and add a timestamp pin; based on the path node information of the added time series, replace the code required for the automatically generated function block to run according to the different templates selected for reading and writing.
2. The method for generating function blocks for PLC control programs according to claim 1, characterized in that, The function block pins include at least the input pin for starting the function block, the output pin for ending the function block, and the timestamp pin corresponding to the time series.
3. The method for generating function blocks for PLC control programs according to claim 1, characterized in that, When the timestamps of the time series selected by the user are aligned, that is, the timestamps of the selected time series are always the same, only one timestamp pin is added to the function block; when the timestamps of the time series selected by the user are not related, a separate timestamp pin is added to each time series.
4. The method for generating function blocks for PLC control programs according to claim 1, characterized in that, The structure of the function block is the function block structure specified in the IEC 61131-3 standard.
5. The method for generating function blocks for PLC control programs according to claim 1, characterized in that, In step S3, the function block is serialized to generate an XML string, and the serialized code generated in step S2 is inserted into the corresponding position. Finally, the XML string is saved as an XML file.
6. The method for generating function blocks for PLC control programs according to claim 1, characterized in that, The format of the XML file depends on the specific configuration format of the target PLC.
7. A function block generation device for PLC control programs, characterized in that, The method according to any one of claims 1-6 comprises at least: The reading module is used to access the corresponding time series database and obtain time series information based on user input. The function block creation module is used to create corresponding function block objects based on the time series selected by the user and automatically generate corresponding code for them; The function block storage module is used to generate XML files of the corresponding format from one or more function block objects for use in PLC control programs.
8. The function block generation device for PLC control programs according to claim 7, characterized in that, The reading module is specifically used for: retrieving path node information of time series from the time series database based on user input; converting the path node information of time series into a data table for user viewing; and saving the obtained data table as a file for separate viewing. The function block creation module is specifically used for: creating the basic data required for function blocks; converting the path node information of the selected time series into the interface of the function block according to the user's selection; and automatically generating the required code contained in the function block according to the selected time series and database operation methods. The function block storage module is specifically used for: serializing created function blocks to generate corresponding XML strings; serializing generated code to generate XML strings; merging XML strings generated from multiple function blocks into a single XML string; and saving XML strings as corresponding XML files.
Citation Information
Patent Citations
Automation engineering system for creating engineering project, method for creating engineering project by employing same, and computer program product
CN107871230A
Method and system for automatically packaging C language codes into function blocks
CN115033231A