A PLC program editing method, compilation method, execution method, and device
By marking function blocks as asynchronous in the PLC program and utilizing asynchronous service threads, the problems of insufficient flexibility and low execution efficiency in PLC system applications are solved, enabling more efficient task execution and the application of complex algorithms.
Patent Information
- Application Number
- CN202510596657.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-09
- Publication Date
- 2026-03-06
- Estimated Expiration
- 2045-05-09
AI Technical Summary
Existing PLC systems are not flexible enough and have low execution efficiency when facing complex and diverse industrial tasks, especially when combined with AI inference tasks, the main task execution time is greatly extended.
Asynchronous execution is achieved by marking function block instances as asynchronous in the PLC program editing interface, adding asynchronous execution parameters, setting the asynchronous function block call entry point and memory layout, and using asynchronous service threads to execute asynchronous function block instances.
It improves the execution efficiency and flexibility of PLC programs, enabling the application of complex algorithms and AI inference tasks more quickly, and reducing the overall execution time of PLC programs.
Smart Images

Figure CN120596096B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the fields of industrial control technology and PLC technology, and in particular to a PLC program editing method, compilation method, execution method and device. Background Technology
[0002] In today's era of rapid industrial automation and intelligent development, the scope of tasks undertaken by programmable logic controllers (PLCs) is constantly expanding and deepening. In the traditional PLC operating mode, function blocks are executed sequentially one by one within the main task cycle. This mode exposes many problems that cannot be ignored when facing today's complex and diverse task requirements.
[0003] With the advancement of intelligent industrial transformation, more and more AI (artificial intelligence) technologies are being integrated into industrial control processes. For example, in the quality inspection process, AI algorithms are used to analyze product images to determine whether the product is qualified; in terms of fault prediction, machine learning models are used to analyze equipment operating data in real time to predict potential faults in advance.
[0004] However, AI inference tasks typically require a large amount of data processing and complex algorithm calculations, and their execution process is extremely time-consuming. When such AI inference function blocks are executed sequentially with other regular function blocks within the main task cycle, the execution time of the main task will be significantly extended.
[0005] On the other hand, today's industrial applications are becoming increasingly complex with numerous processes, leading to a growing demand for various algorithms. The traditional periodic execution method of PLCs makes it difficult to quickly and easily apply many existing algorithm implementations to PLC systems. Instead, special designs are needed to address the execution characteristics of PLC systems, which is detrimental to the development of intelligent industrial applications.
[0006] In other words, existing technologies suffer from problems such as insufficient flexibility in the application of PLCs and low execution efficiency. Summary of the Invention
[0007] This application provides a PLC program editing method, compilation method, execution method, and apparatus to solve the problems of insufficient flexibility and low execution efficiency in the application of PLCs in the prior art.
[0008] This application provides a PLC program editing method, including:
[0009] The editing interface is displayed, which contains an instance of a function block to be edited, and an editable item for the function block instance.
[0010] When the editing operation performed on the function block instance editing item indicates that the function block instance is set to be executed asynchronously, the function block instance in the PLC program being edited this time is marked as asynchronous execution, and the function block instance marked as asynchronous execution is used as an asynchronous function block instance;
[0011] In the editing interface, for the asynchronous function block instance, a parameter editing item is displayed. The parameter editing item is used to edit the asynchronous execution parameters of the asynchronous function block instance. The asynchronous execution parameters are used to execute the asynchronous function block instance asynchronously.
[0012] Obtain the actual parameters of the asynchronous execution parameters set based on the parameter editing item, and obtain the defined asynchronous function block instance.
[0013] Furthermore, the display editing interface includes:
[0014] The text editing interface is displayed, and the function block instance editing item is used to indicate that the function block instance is set to execute asynchronously by adding preset syntax tags; or
[0015] The graphical editing interface is displayed. The function block instance editing item includes preset editing options. When the preset editing option is selected, it means that the function block instance is set to be executed asynchronously.
[0016] Furthermore, the function block editing item is a checkbox that corresponds one-to-one with all function block instances to be edited. When the checkbox is checked, it indicates that the corresponding function block instance is set to be executed asynchronously.
[0017] Furthermore, the asynchronous execution parameters include:
[0018] The input parameters used to trigger the asynchronous execution of the function block instance serve as the start execution parameters;
[0019] Used to represent the output parameters that the function block instance is currently executing, as the execution parameters;
[0020] Output parameters are used to indicate that a function block instance has been executed successfully, serving as execution completion parameters.
[0021] This application also provides a PLC program compilation method, including:
[0022] For a function block instance defined in the PLC program to be compiled, when the function block instance is marked as an asynchronous function block instance for asynchronous execution, add an asynchronous execution parameter for the asynchronous function block instance. The asynchronous execution parameter is used to execute the asynchronous function block instance asynchronously.
[0023] The call entry point of the asynchronous function block instance is set as the asynchronous function block call entry point, and the parameter of the asynchronous function block call entry point is the memory address allocated to the asynchronous function block instance;
[0024] Based on the memory layout defined in the function block corresponding to the asynchronous function block instance, a memory layout is created for the asynchronous function block instance to obtain the compiled code for asynchronously executing the asynchronous function block instance.
[0025] Furthermore, the asynchronous execution parameters include:
[0026] The input parameters used to trigger the asynchronous execution of the function block instance serve as the start execution parameters;
[0027] Used to represent the output parameters that the function block instance is currently executing, as the execution parameters;
[0028] Output parameters are used to indicate that a function block instance has been executed successfully, serving as execution completion parameters.
[0029] Furthermore, regarding the function block instance defined in the PLC program to be compiled, when the function block instance is marked as an asynchronous function block instance for asynchronous execution, before adding the asynchronous execution parameters of the asynchronous function block instance, the following is also included:
[0030] For a function block instance defined in the PLC program to be compiled, when the function block instance is marked as an asynchronous function block instance for asynchronous execution, the source code of the asynchronous function block with the same function as the function block corresponding to the asynchronous function block instance is generated. The source code includes the asynchronous execution parameters of the asynchronous function block instance and the asynchronous function block call entry point.
[0031] The asynchronous execution parameters for adding the asynchronous function block instance include:
[0032] By compiling the source code of the asynchronous function block, asynchronous execution parameters for the asynchronous function block instance are added;
[0033] Setting the entry point of the asynchronous function block instance as the asynchronous function block call entry point includes:
[0034] By compiling the source code of the asynchronous function block, the call entry point of the asynchronous function block instance is set as the asynchronous function block call entry point;
[0035] Creating a memory layout for the asynchronous function block instance according to the defined memory layout contained in the function block corresponding to the asynchronous function block instance includes:
[0036] By compiling the source code of the asynchronous function block, a memory layout is created for the asynchronous function block instance according to the memory layout defined in the function block corresponding to the asynchronous function block instance.
[0037] Furthermore, the asynchronous function block call entry point includes:
[0038] Program statements used to determine whether to start executing the asynchronous function block instance based on the current parameter value of the asynchronous execution parameters;
[0039] Program statements used to invoke a runtime asynchronous function block service, wherein the runtime asynchronous function block service is used to asynchronously execute the asynchronous function block instance.
[0040] Furthermore, the parameters of the runtime asynchronous function block service include: the memory address allocated to the asynchronous function block instance, and the function block call entry point of the function block corresponding to the asynchronous function block instance;
[0041] The runtime asynchronous function block service is used to execute the asynchronous function block instance through an asynchronous service thread.
[0042] This application also provides a PLC program execution method, including:
[0043] For an asynchronous function block instance to be executed in a PLC program, the asynchronous function block instance is executed asynchronously by calling the asynchronous function block call entry point of the asynchronous function block instance, based on the current parameter value of the asynchronous execution parameter of the asynchronous function block instance and the memory layout. The parameter of the asynchronous function block call entry point is the memory address allocated for the asynchronous function block instance.
[0044] While the asynchronous function block instance is being executed asynchronously, the statements following the asynchronous function block instance in the PLC program are also executed.
[0045] Furthermore, the asynchronous execution of the asynchronous function block instance based on the current parameter values of the asynchronous execution parameters of the asynchronous function block instance and the memory layout includes:
[0046] When the current parameter value of the asynchronous execution parameter of the asynchronous function block instance indicates that execution is started, the runtime asynchronous function block service is called. The parameters of the runtime asynchronous function block service include: the memory address allocated to the asynchronous function block instance, and the function block call entry point of the function block corresponding to the asynchronous function block instance.
[0047] The runtime asynchronous function block service is used to execute the asynchronous function block instance through an asynchronous service thread.
[0048] Furthermore, the runtime asynchronous function block service is used to execute the asynchronous function block instance via an asynchronous service thread using the following steps:
[0049] Create an asynchronous task, which includes the memory address allocated to the asynchronous function block instance according to the memory layout of the asynchronous function block instance, and the function block call entry point of the function block corresponding to the asynchronous function block instance;
[0050] The function block is executed by calling the function block entry point using the memory address as a parameter through an asynchronous service thread;
[0051] Update the current parameter value of the asynchronous execution parameter;
[0052] Release the memory allocated for executing the asynchronous task.
[0053] Furthermore, the asynchronous execution parameters include:
[0054] The input parameters used to trigger the asynchronous execution of the function block instance serve as the start execution parameters;
[0055] Used to represent the output parameters that the function block instance is currently executing, as the execution parameters;
[0056] Output parameters are used to indicate that a function block instance has been executed successfully, serving as execution completion parameters.
[0057] This application embodiment also provides a PLC program editing device, including:
[0058] The instance editing and display module is used to display the editing interface, which includes the function block instance to be edited and the function block instance editing item of the function block instance;
[0059] The asynchronous setting module is used to mark the function block instance in the currently edited PLC program as asynchronous when the editing operation performed on the function block instance editing item indicates that the function block instance is set to be executed asynchronously, and the function block instance marked as asynchronous is used as an asynchronous function block instance.
[0060] The parameter editing and display module is used to display the parameter editing items of the asynchronous function block instance in the editing interface. The parameter editing items are used to edit the asynchronous execution parameters of the asynchronous function block instance, and the asynchronous execution parameters are used to asynchronously execute the asynchronous function block instance.
[0061] The actual parameter acquisition module is used to acquire the actual parameters of the asynchronous execution parameters set based on the parameter editing item, and obtain the defined asynchronous function block instance.
[0062] Furthermore, the display editing interface includes:
[0063] The text editing interface is displayed, and the function block instance editing item is used to indicate that the function block instance is set to execute asynchronously by adding preset syntax tags; or
[0064] The graphical editing interface is displayed. The function block instance editing item includes preset editing options. When the preset editing option is selected, it means that the function block instance is set to be executed asynchronously.
[0065] Furthermore, the function block editing item is a checkbox that corresponds one-to-one with all function block instances to be edited. When the checkbox is checked, it indicates that the corresponding function block instance is set to be executed asynchronously.
[0066] Furthermore, the asynchronous execution parameters include:
[0067] The input parameters used to trigger the asynchronous execution of the function block instance serve as the start execution parameters;
[0068] Used to represent the output parameters that the function block instance is currently executing, as the execution parameters;
[0069] Output parameters are used to indicate that a function block instance has been executed successfully, serving as execution completion parameters.
[0070] This application embodiment also provides a PLC program compilation device, including:
[0071] The parameter adding module is used to add asynchronous execution parameters to the function block instance defined in the PLC program to be compiled when the function block instance is marked as an asynchronous function block instance for asynchronous execution. The asynchronous execution parameters are used to execute the asynchronous function block instance asynchronously.
[0072] The call entry setting module is used to set the call entry of the asynchronous function block instance as the asynchronous function block call entry, and the parameter of the asynchronous function block call entry is the memory address allocated for the asynchronous function block instance;
[0073] The memory layout creation module is used to create a memory layout for the asynchronous function block instance according to the memory layout defined in the function block corresponding to the asynchronous function block instance, so as to obtain the compiled code for asynchronously executing the asynchronous function block instance.
[0074] Furthermore, the asynchronous execution parameters include:
[0075] The input parameters used to trigger the asynchronous execution of the function block instance serve as the start execution parameters;
[0076] Used to represent the output parameters that the function block instance is currently executing, as the execution parameters;
[0077] Output parameters are used to indicate that a function block instance has been executed successfully, serving as execution completion parameters.
[0078] Furthermore, it also includes:
[0079] The source code generation module is used to generate source code for an asynchronous function block instance defined in the PLC program to be compiled. When the function block instance is marked as an asynchronous function block instance and executed asynchronously, the source code of the asynchronous function block instance has the same function as the function block corresponding to the asynchronous function block instance. The source code includes the asynchronous execution parameters and the asynchronous function block call entry point of the asynchronous function block instance.
[0080] The parameter adding module is specifically used to add asynchronous execution parameters of the asynchronous function block instance by compiling the source code of the asynchronous function block;
[0081] The call entry setting module is specifically used to set the call entry of the asynchronous function block instance as the asynchronous function block call entry by compiling the source code of the asynchronous function block;
[0082] The memory layout creation module is specifically used to create a memory layout for the asynchronous function block instance by compiling the source code of the asynchronous function block, according to the memory layout defined in the function block corresponding to the asynchronous function block instance.
[0083] Furthermore, the asynchronous function block call entry point includes:
[0084] Program statements used to determine whether to start executing the asynchronous function block instance based on the current parameter value of the asynchronous execution parameters;
[0085] Program statements used to invoke a runtime asynchronous function block service, wherein the runtime asynchronous function block service is used to asynchronously execute the asynchronous function block instance.
[0086] Furthermore, the parameters of the runtime asynchronous function block service include: the memory address allocated to the asynchronous function block instance, and the function block call entry point of the function block corresponding to the asynchronous function block instance;
[0087] The runtime asynchronous function block service is used to execute the asynchronous function block instance through an asynchronous service thread.
[0088] This application embodiment also provides a PLC program execution device, including:
[0089] The asynchronous execution module is used to execute asynchronous function block instances to be executed in a PLC program by calling the asynchronous function block call entry of the asynchronous function block instance, based on the current parameter values of the asynchronous execution parameters of the asynchronous function block instance and the memory layout. The parameter of the asynchronous function block call entry is the memory address allocated for the asynchronous function block instance.
[0090] The statement execution module is used to execute the statements following the asynchronous function block instance in the PLC program while asynchronously executing the asynchronous function block instance.
[0091] Furthermore, the asynchronous execution module is specifically used to call the runtime asynchronous function block service when the current parameter value of the asynchronous execution parameter of the asynchronous function block instance indicates the start of execution. The parameters of the runtime asynchronous function block service include: the memory address allocated to the asynchronous function block instance, and the function block call entry point of the function block corresponding to the asynchronous function block instance.
[0092] The runtime asynchronous function block service is used to execute the asynchronous function block instance through an asynchronous service thread.
[0093] Furthermore, the runtime asynchronous function block service is used to execute the asynchronous function block instance via an asynchronous service thread using the following steps:
[0094] Create an asynchronous task, which includes the memory address allocated to the asynchronous function block instance according to the memory layout of the asynchronous function block instance, and the function block call entry point of the function block corresponding to the asynchronous function block instance;
[0095] The function block is executed by calling the function block entry point using the memory address as a parameter through an asynchronous service thread;
[0096] Update the current parameter value of the asynchronous execution parameter;
[0097] Release the memory allocated for executing the asynchronous task.
[0098] Furthermore, the asynchronous execution parameters include:
[0099] The input parameters used to trigger the asynchronous execution of the function block instance serve as the start execution parameters;
[0100] Used to represent the output parameters that the function block instance is currently executing, as the execution parameters;
[0101] Output parameters are used to indicate that a function block instance has been executed successfully, serving as execution completion parameters.
[0102] This application also provides an electronic device, including a processor and a machine-readable storage medium, wherein the machine-readable storage medium stores machine-executable instructions that can be executed by the processor, and the processor is prompted by the machine-executable instructions to: implement any of the above-described PLC program editing methods, or implement any of the above-described PLC program compilation methods, or implement any of the above-described PLC program execution methods.
[0103] This application embodiment also provides a computer-readable storage medium storing a computer program. When the computer program is executed by a processor, it implements any of the above-described PLC program editing methods, or implements any of the above-described PLC program compilation methods, or implements any of the above-described PLC program execution methods.
[0104] This application also provides a computer program product containing instructions that, when run on a computer, causes the computer to execute any of the above-described PLC program editing methods, or execute any of the above-described PLC program compilation methods, or execute any of the above-described PLC program execution methods.
[0105] The beneficial effects of this application include:
[0106] In the PLC program editing method provided in this application embodiment, when editing the PLC program, for the function block instance to be edited contained in the editing interface, the function block instance can be marked as asynchronous execution based on the function block instance editing item, and the asynchronous execution parameters can be edited based on the parameter editing item to obtain the defined asynchronous function block instance, thereby realizing a more flexible way to set the function block instance to asynchronous execution.
[0107] In the PLC program compilation method provided in this application embodiment, when a function block instance defined in the PLC program to be compiled is marked as asynchronous execution, it indicates that the function block instance is an asynchronous function block instance. The asynchronous execution parameter of the asynchronous function block instance is added, the call entry point of the asynchronous function block instance is set as the asynchronous function block call entry point, and a memory layout is created for the asynchronous function block instance according to the memory layout defined in the function block corresponding to the asynchronous function block instance. The compilation code for asynchronous execution of the asynchronous function block instance is obtained, thereby realizing the compilation of function block instances set to be executed asynchronously.
[0108] The PLC program execution method provided in this application, for an asynchronous function block instance to be executed in a PLC program, calls the asynchronous function block call entry of the asynchronous function block instance, and executes the asynchronous function block instance asynchronously based on the current parameter value of the asynchronous execution parameters of the asynchronous function block instance and the memory layout. Furthermore, while executing the asynchronous function block instance, the statements following the asynchronous function block instance in the PLC program are executed. Compared with the prior art, by flexibly setting the function block instances in the PLC program to be executed asynchronously, the overall execution time of the PLC program is reduced, thereby improving the flexibility and execution efficiency of PLC applications.
[0109] Other features and advantages of this application will be set forth in the following description and will be apparent in part from the description or may be learned by practicing the application. The objectives and other advantages of this application may be realized and obtained by means of the structures particularly pointed out in the written description, claims, and drawings. Attached Figure Description
[0110] The accompanying drawings are provided to further illustrate the present application and form part of the specification. They are used together with the embodiments of the present application to explain the application and do not constitute a limitation thereof. In the drawings:
[0111] Figure 1 A flowchart illustrating the PLC program editing method provided in this application embodiment;
[0112] Figure 2-1 This is a schematic diagram of a text editing interface containing function block instance editing items shown in the embodiments of this application;
[0113] Figure 2-2 This is a schematic diagram of a text editing interface including parameter editing items shown in the embodiments of this application;
[0114] Figure 2-3 This is a schematic diagram of a graphical editing interface containing function block instance editing items, as shown in the embodiments of this application;
[0115] Figure 2-4 This is a schematic diagram of a graphical editing interface including parameter editing items shown in the embodiments of this application;
[0116] Figure 3 A flowchart of the PLC program compilation method provided in the embodiments of this application;
[0117] Figure 4 This is a schematic diagram illustrating the compilation of a function block instance in an embodiment of this application;
[0118] Figure 5 A flowchart of the PLC program execution method provided in the application embodiment;
[0119] Figure 6 A flowchart of a PLC program compilation method provided in another embodiment of the application;
[0120] Figure 7 This is a schematic diagram of the structure of the PLC program editing device provided in the embodiments of this application;
[0121] Figure 8 This is a schematic diagram of the structure of the PLC program compilation device provided in the embodiments of this application;
[0122] Figure 9 This is a schematic diagram of the structure of the PLC program execution device provided in the embodiments of this application;
[0123] Figure 10 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0124] To provide a solution for improving the flexibility and execution efficiency of PLC applications, this application provides a PLC program editing method, compilation method, execution method, and apparatus. The preferred embodiments of this application are described below with reference to the accompanying drawings. It should be understood that the preferred embodiments described herein are for illustrative and explanatory purposes only and are not intended to limit this application. Furthermore, the embodiments and features described in this application can be combined with each other unless otherwise specified.
[0125] This application provides a PLC program editing method, such as... Figure 1 As shown, it includes:
[0126] Step 11: Display the editing interface, which contains the function block instance to be edited, and the function block instance editing items of that function block instance;
[0127] Step 12: When the editing operation performed on the function block instance editing item indicates that the function block instance is set to be executed asynchronously, the function block instance in the PLC program being edited this time is marked as asynchronous execution, and the function block instance marked as asynchronous execution is used as the asynchronous function block instance;
[0128] Step 13: In the editing interface, for the asynchronous function block instance, display the parameter editing item of the asynchronous function block instance. The parameter editing item is used to edit the asynchronous execution parameters of the asynchronous function block instance. The asynchronous execution parameters are used to execute the asynchronous function block instance asynchronously.
[0129] Step 14: Obtain the actual parameters of the asynchronous execution parameters set based on the parameter editing items, and obtain the defined asynchronous function block instance.
[0130] Using the PLC program editing method provided in this application embodiment, when editing a PLC program, for the function block instance to be edited contained in the editing interface, the function block instance can be marked as asynchronous execution based on the function block instance editing item, and the asynchronous execution parameters can be edited based on the parameter editing item to obtain the defined asynchronous function block instance, thereby realizing a more flexible way to set the function block instance to asynchronous execution.
[0131] In one embodiment of this application, the above-described PLC program editing method can be implemented on the editor of the PLC's IDE (Integrated Development Environment), such as... Figure 2-1 As shown, during the PLC program editing process, a text editing interface can be displayed on the IDE. Developers can add text content of the selected function block instance in the text editing interface. Furthermore, the text content of the corresponding function block instance in the text editing interface has a function block instance editing item. Developers can add preset syntax tags to the function block instance in the text editing interface based on the function block instance editing item, indicating that the function block instance is set to be executed asynchronously, i.e., as an asynchronous function block instance.
[0132] Figure 2-1 In the context of the same function block A, "no_async_inst:function block A" is an instance of function block A, and "async_inst{{ASYNC:"TRUE"}}:function block A" is an asynchronous instance of function block A. That is, for the same function block A, the corresponding function block instance can be flexibly set to be executed asynchronously or non-asynchronously.
[0133] Correspondingly, such as Figure 2-2 As shown, after adding preset syntax tags to this function block instance, the parameter editing items for that asynchronous function block instance are displayed in the text editing interface. Developers can set the actual parameters (actual arguments) for asynchronous execution based on the parameter editing items, for example, Figure 2-2 In, "async_inst(Execute:=TRUE,Done=>done,Busy=>busy)".
[0134] In another embodiment of this application, such as Figure 2-3 As shown, during the PLC program editing process, a graphical editing interface can be displayed on the IDE. Developers can select the function block icon of the function block instance they are using on the graphical editing interface. Furthermore, the function block instance editing item for the selected function block instance in the graphical editing interface includes preset editing options. Developers can select the preset editing option to set the function block instance to be executed asynchronously, i.e., as an asynchronous function block instance.
[0135] Correspondingly, such as Figure 2-4 As shown, when the preset editing option is selected for the function block instance, the parameter editing items of the function block instance are displayed in the graphical editing interface. The parameter editing items can be the pins on the function block icon corresponding to each execution parameter. Developers can set the actual parameters (actual parameters) of the asynchronous execution parameters based on the parameter editing items.
[0136] Figure 2-3 In the middle section, for the function block instance "counter_1", a corresponding function block instance editing option is displayed. After selecting "Convert to Asynchronous Call", the function block instance is set as an asynchronous function block instance and displayed. Figure 2-4 The graphical editing interface shown has a parameter editing item on the function block icon. Compared with the non-asynchronous execution function block instance "cpp_counter-1", it corresponds to the same function block, but the parameter editing item adds pins corresponding to the asynchronous execution parameters, such as "Execute", "Busy", "Done", etc. Clicking the pin can set the actual parameters of the corresponding asynchronous execution parameters.
[0137] In addition to using the text editing interface and graphical editing interface described above to set the function block instance to be executed asynchronously, in another embodiment of this application, a checkbox method can also be used. That is, the function block instance editing item in the editing interface is a checkbox that corresponds one-to-one with all the function block instances selected for use. When the checkbox is checked, it means that the corresponding function block instance is set to be executed asynchronously.
[0138] In this embodiment of the application, the asynchronous execution parameters used for asynchronous execution may include:
[0139] The input parameters used to trigger the asynchronous execution of the function block instance, as the start execution parameters, can be named execute;
[0140] This is used to indicate the output parameters that a function block instance is currently executing. As an execution parameter, it can be named busy.
[0141] Output parameters used to indicate that a function block instance has completed execution can be named "done".
[0142] Accordingly, embodiments of this application also provide a PLC program compilation method, such as... Figure 3 As shown, it includes:
[0143] Step 31: For the function block instance defined in the PLC program to be compiled, when the function block instance is marked as an asynchronous function block instance and executed asynchronously, add the asynchronous execution parameter of the asynchronous function block instance. The asynchronous execution parameter is used to execute the asynchronous function block instance asynchronously.
[0144] Step 32: Set the call entry point of this asynchronous function block instance as the asynchronous function block call entry point. The parameter of the asynchronous function block call entry point is the memory address allocated for this asynchronous function block instance.
[0145] Step 33: Create a memory layout for the asynchronous function block instance according to the memory layout defined in the function block corresponding to the asynchronous function block instance, and obtain the compiled code for asynchronously executing the asynchronous function block instance.
[0146] Using the PLC program compilation method provided in this application, when a function block instance defined in the PLC program to be compiled is marked as asynchronous execution, it indicates that the function block instance is an asynchronous function block instance. The asynchronous execution parameter of the asynchronous function block instance is added, the call entry point of the asynchronous function block instance is set as the asynchronous function block call entry point, and a memory layout is created for the asynchronous function block instance according to the memory layout defined in the function block corresponding to the asynchronous function block instance. The compilation code for asynchronous execution of the asynchronous function block instance is obtained, thereby realizing the compilation of function block instances set to be executed asynchronously.
[0147] In one embodiment of this application, the above-described PLC program compilation method can be implemented on the compiler of the PLC IDE. For a function block instance defined in the PLC program to be compiled, if the function block instance is not marked as asynchronous, the source code of the function block corresponding to that function block instance can be directly compiled into compiled code corresponding to a non-asynchronous execution function block instance. Compilation can also be understood as the instantiation of the function block. Figure 4 As shown, for function block A, it can be compiled into function block A instance 1 and function block A instance 2, which are executed asynchronously.
[0148] For function block instances defined in the PLC program to be compiled, if the function block instance is marked for asynchronous execution, the above compilation method can be used. Following the asynchronous execution compilation method, the source code of the function block corresponding to the function block instance is directly compiled into the compiled code corresponding to the asynchronous execution function block instance, such as... Figure 4 As shown, for the same function block A, it can be compiled into an asynchronously executed function block A instance 3.
[0149] In another embodiment of this application, for instances of asynchronous function blocks marked as asynchronous execution in the PLC program, such as Figure 4As shown, alternatively, one can first generate the source code of an asynchronous function block that has the same functionality as the function block corresponding to the asynchronous function block instance. This source code can be used as temporary source code, containing the asynchronous execution parameters and the asynchronous function block call entry point of the asynchronous function block instance. Then, by compiling the source code of the asynchronous function block, the asynchronous execution parameters of the asynchronous function block instance can be added, the call entry point can be set as the asynchronous function block call entry point, and a memory layout can be created, as shown below. Figure 4 As shown, for the same function block A, the source code of the asynchronous function block A corresponding to function block A is automatically generated first, and the source code of the asynchronous function block A is compiled to obtain the asynchronously executed function block A instance 3.
[0150] In this embodiment of the application, the asynchronous function block call entry point may include:
[0151] Program statements used to determine whether to start executing the asynchronous function block instance based on the current parameter value of the asynchronous execution parameters;
[0152] Program statements used to invoke a runtime asynchronous function block service, which is used to asynchronously execute asynchronous function block instances.
[0153] The above-mentioned asynchronous function block call entry point and runtime asynchronous function block service are both functions.
[0154] Furthermore, the parameters of the runtime asynchronous function block service may include: the memory address allocated to the asynchronous function block instance, and the function block call entry point of the function block corresponding to the asynchronous function block instance;
[0155] This runtime asynchronous function block service is used to execute the asynchronous function block instance via an asynchronous service thread.
[0156] Accordingly, embodiments of this application also provide a PLC program execution method, such as... Figure 5 As shown, it includes:
[0157] Step 51: For the asynchronous function block instance to be executed in the PLC program, by calling the asynchronous function block call entry point of the asynchronous function block instance, based on the current parameter value of the asynchronous execution parameter of the asynchronous function block instance and the memory layout, the asynchronous function block instance is executed asynchronously. The parameter of the asynchronous function block call entry point is the memory address allocated for the asynchronous function block instance.
[0158] Step 52: While the asynchronous function block instance is being executed asynchronously, the statements following the asynchronous function block instance in the PLC program are also executed.
[0159] The PLC program execution method provided in this application embodiment targets an asynchronous function block instance to be executed in a PLC program. By calling the asynchronous function block call entry of the asynchronous function block instance, and based on the current parameter values of the asynchronous execution parameters of the asynchronous function block instance and the memory layout, the asynchronous function block instance is executed asynchronously. Furthermore, while the asynchronous function block instance is executed asynchronously, the statements following the asynchronous function block instance in the PLC program are executed. Compared with the prior art, by flexibly setting the function block instances in the PLC program to be executed asynchronously, the overall execution time of the PLC program is reduced, thereby improving the flexibility and execution efficiency of PLC applications.
[0160] In PLC applications, PLC tasks are often executed periodically to achieve PLC functionality. A PLC task can include multiple function block instances and multiple functions, and the execution of the PLC task is completed by calling the functions and function block instances through program statements.
[0161] In one embodiment of this application, regarding the above-described PLC program execution method, such as Figure 6 As shown, the specific steps may include the following:
[0162] Step 61: During the execution of the PLC program, for the asynchronous function block instance that needs to be executed asynchronously, call the asynchronous function block call entry point of the asynchronous function block instance. The parameter of the asynchronous function block call entry point is the memory address allocated for the asynchronous function block instance.
[0163] In practical applications, when encountering an asynchronous function block instance that needs to be executed asynchronously during the periodic execution of PLC tasks, this step calls the entry point of that asynchronous function block.
[0164] Step 62: Based on the current parameter value of the asynchronous execution parameter of the asynchronous function block instance, determine whether to start the execution of the asynchronous function block instance. If it is determined to start the execution, proceed to step 63. If it is determined not to start the execution, return directly and continue to execute the statements after the asynchronous function block instance.
[0165] In this step, if it is determined not to start execution, it can be understood that the asynchronous function block instance is currently being executed, and the start execution of the asynchronous function block instance can be skipped within this cycle.
[0166] In this embodiment of the application, when the asynchronous execution parameters specifically include the above-mentioned start execution parameter execute, the execution in progress parameter busy, and the execution completion parameter done, if the start execution parameter execute is a rising edge, that is, changing from 0 to 1, and the execution in progress parameter busy is 0, indicating that it is not being executed, then it is determined to start the execution of the asynchronous function block instance; otherwise, it returns directly and continues to execute the statements after the asynchronous function block instance.
[0167] In practical applications, the value of the execute parameter changes from 1 to 0 depending on the actual value of the variable that the caller needs to pass in, which will not be described in detail here.
[0168] Step 63: Call the runtime asynchronous function block service. The parameters of the runtime asynchronous function block service include: the memory address allocated to the asynchronous function block instance, and the function block call entry point of the function block corresponding to the asynchronous function block instance. The function block call entry point can be understood as the original function block call entry point of the function block, which is different from the asynchronous function block call entry point mentioned above.
[0169] By calling the runtime asynchronous function block service, execute steps 64-67 as follows.
[0170] Step 64: Create an asynchronous task. The asynchronous task contains the memory address allocated to the asynchronous function block instance according to the memory layout of the asynchronous function block instance, as well as the function block call entry point of the function block corresponding to the asynchronous function block instance.
[0171] It sets the busy parameter to 1 to indicate that the function block instance is being executed asynchronously, and sets the done parameter to 0 to indicate that the execution is not yet complete.
[0172] Step 65: Use the memory address as a parameter to call the entry point of the function block through the asynchronous service thread to execute the function block corresponding to the asynchronous function block instance.
[0173] In this step, the asynchronous service thread can be created in advance or created when needed.
[0174] In practical applications, the asynchronous task created in step 64 above can be placed in the asynchronous task queue, waiting for the asynchronous service thread to retrieve the asynchronous task from the asynchronous task queue and execute it.
[0175] Step 66: After the asynchronous function block instance is completed, update the current parameter value of the asynchronous execution parameter through the asynchronous service thread.
[0176] Specifically, you can set the "busy" parameter to 0 and the "done" parameter to 1 to indicate that the execution is complete.
[0177] Step 67: Release the memory allocated for executing the asynchronous task through the asynchronous service thread.
[0178] Step 68: After creating the asynchronous task in step 64 above, proceed to step 68. While the asynchronous function block instance is executed asynchronously through the asynchronous task thread, the statements following the asynchronous function block instance in the PLC program are also executed.
[0179] This enables asynchronous execution of the asynchronous function block instance relative to other program statements of its corresponding PLC task, thereby improving task execution efficiency.
[0180] The PLC program editing, compilation, and execution methods provided in the embodiments of this application can flexibly set the selected function blocks to be executed asynchronously or non-asynchronously without modifying the existing function blocks. In other words, there is no need to make specific implementations for the asynchronous execution mode inside the function block. The method provided in the embodiments of this application can automatically provide the asynchronous execution function of the function block, making the asynchronous execution scheme more flexible and practical in PLC applications.
[0181] Furthermore, function blocks written in various languages can all be set to execute asynchronously using the methods provided in the embodiments of this application. This makes it easier to bring existing algorithm implementations and ecosystems of various programming languages into the PLC system, and also makes it possible to run complex algorithms and AI inference tasks in the PLC.
[0182] Based on the same inventive concept, and according to the PLC program editing method provided in the above embodiments of this application, another embodiment of this application also provides a PLC program editing device, the structural schematic diagram of which is shown below. Figure 7 As shown, it specifically includes:
[0183] The instance editing display module 71 is used to display the editing interface, which includes the function block instance to be edited and the function block instance editing item of the function block instance;
[0184] The asynchronous setting module 72 is used to mark the function block instance in the currently edited PLC program as asynchronous when the editing operation performed on the function block instance editing item indicates that the function block instance is set to be executed asynchronously, and the function block instance marked as asynchronous is used as an asynchronous function block instance.
[0185] The parameter editing and display module 73 is used to display the parameter editing items of the asynchronous function block instance in the editing interface. The parameter editing items are used to edit the asynchronous execution parameters of the asynchronous function block instance, and the asynchronous execution parameters are used to asynchronously execute the asynchronous function block instance.
[0186] The actual parameter acquisition module 74 is used to acquire the actual parameters of the asynchronous execution parameters set based on the parameter editing item, and obtain the defined asynchronous function block instance.
[0187] Furthermore, the display editing interface includes:
[0188] The text editing interface is displayed, and the function block instance editing item is used to indicate that the function block instance is set to execute asynchronously by adding preset syntax tags; or
[0189] The graphical editing interface is displayed. The function block instance editing item includes preset editing options. When the preset editing option is selected, it means that the function block instance is set to be executed asynchronously.
[0190] Furthermore, the function block editing item is a checkbox that corresponds one-to-one with all function block instances to be edited. When the checkbox is checked, it indicates that the corresponding function block instance is set to be executed asynchronously.
[0191] Furthermore, the asynchronous execution parameters include:
[0192] The input parameters used to trigger the asynchronous execution of the function block instance serve as the start execution parameters;
[0193] Used to represent the output parameters that the function block instance is currently executing, as the execution parameters;
[0194] Output parameters are used to indicate that a function block instance has been executed successfully, serving as execution completion parameters.
[0195] Based on the same inventive concept, and according to the PLC program compilation method provided in the above embodiments of this application, another embodiment of this application also provides a PLC program compilation device, the structural schematic diagram of which is shown below. Figure 8 As shown, it specifically includes:
[0196] The parameter adding module 81 is used to add asynchronous execution parameters to the function block instance defined in the PLC program to be compiled when the function block instance is marked as an asynchronous function block instance for asynchronous execution. The asynchronous execution parameters are used to execute the asynchronous function block instance asynchronously.
[0197] The call entry setting module 82 is used to set the call entry of the asynchronous function block instance as the asynchronous function block call entry, wherein the parameter of the asynchronous function block call entry is the memory address allocated for the asynchronous function block instance;
[0198] The memory layout creation module 83 is used to create a memory layout for the asynchronous function block instance according to the memory layout defined in the function block corresponding to the asynchronous function block instance, so as to obtain the compiled code for asynchronously executing the asynchronous function block instance.
[0199] Furthermore, the asynchronous execution parameters include:
[0200] The input parameters used to trigger the asynchronous execution of the function block instance serve as the start execution parameters;
[0201] Used to represent the output parameters that the function block instance is currently executing, as the execution parameters;
[0202] Output parameters are used to indicate that a function block instance has been executed successfully, serving as execution completion parameters.
[0203] Furthermore, it also includes:
[0204] The source code generation module 84 is used to generate source code for an asynchronous function block instance defined in the PLC program to be compiled. When the function block instance is marked as an asynchronous function block instance and executed asynchronously, the source code generates source code for an asynchronous function block that has the same function as the function block corresponding to the asynchronous function block instance. The source code includes the asynchronous execution parameters and the asynchronous function block call entry point of the asynchronous function block instance.
[0205] The parameter adding module 81 is specifically used to add asynchronous execution parameters of the asynchronous function block instance by compiling the source code of the asynchronous function block;
[0206] The call entry setting module 82 is specifically used to set the call entry of the asynchronous function block instance as the asynchronous function block call entry by compiling the source code of the asynchronous function block;
[0207] The memory layout creation module 83 is specifically used to create a memory layout for the asynchronous function block instance by compiling the source code of the asynchronous function block, according to the memory layout defined in the function block corresponding to the asynchronous function block instance.
[0208] Furthermore, the asynchronous function block call entry point includes:
[0209] Program statements used to determine whether to start executing the asynchronous function block instance based on the current parameter value of the asynchronous execution parameters;
[0210] Program statements used to invoke a runtime asynchronous function block service, wherein the runtime asynchronous function block service is used to asynchronously execute the asynchronous function block instance.
[0211] Furthermore, the parameters of the runtime asynchronous function block service include: the memory address allocated to the asynchronous function block instance, and the function block call entry point of the function block corresponding to the asynchronous function block instance;
[0212] The runtime asynchronous function block service is used to execute the asynchronous function block instance through an asynchronous service thread.
[0213] Based on the same inventive concept, and according to the PLC program execution method provided in the above embodiments of this application, another embodiment of this application also provides a PLC program execution device, the structural schematic diagram of which is shown below. Figure 9 As shown, it specifically includes:
[0214] The asynchronous execution module 91 is used to execute an asynchronous function block instance to be executed in the PLC program by calling the asynchronous function block call entry of the asynchronous function block instance, based on the current parameter value of the asynchronous execution parameter of the asynchronous function block instance and the memory layout. The parameter of the asynchronous function block call entry is the memory address allocated for the asynchronous function block instance.
[0215] The statement execution module 92 is used to execute the statements following the asynchronous function block instance in the PLC program while asynchronously executing the asynchronous function block instance.
[0216] Furthermore, the asynchronous execution module 91 is specifically used to call the runtime asynchronous function block service when the current parameter value of the asynchronous execution parameter of the asynchronous function block instance indicates the start of execution. The parameters of the runtime asynchronous function block service include: the memory address allocated to the asynchronous function block instance, and the function block call entry point of the function block corresponding to the asynchronous function block instance.
[0217] The runtime asynchronous function block service is used to execute the asynchronous function block instance through an asynchronous service thread.
[0218] Furthermore, the runtime asynchronous function block service is used to execute the asynchronous function block instance via an asynchronous service thread using the following steps:
[0219] Create an asynchronous task, which includes the memory address allocated to the asynchronous function block instance according to the memory layout of the asynchronous function block instance, and the function block call entry point of the function block corresponding to the asynchronous function block instance;
[0220] The function block is executed by calling the function block entry point using the memory address as a parameter through an asynchronous service thread;
[0221] Update the current parameter value of the asynchronous execution parameter;
[0222] Release the memory allocated for executing the asynchronous task.
[0223] Furthermore, the asynchronous execution parameters include:
[0224] The input parameters used to trigger the asynchronous execution of the function block instance serve as the start execution parameters;
[0225] Used to represent the output parameters that the function block instance is currently executing, as the execution parameters;
[0226] Output parameters are used to indicate that a function block instance has been executed successfully, serving as execution completion parameters.
[0227] The functions of the above modules can be corresponding to Figures 1-6 The corresponding processing steps in the process shown will not be repeated here.
[0228] The PLC program editing device, PLC program compilation device, and PLC program execution device provided in the embodiments of this application can be implemented by computer programs. Those skilled in the art should understand that the above-described module division method is only one of many module division methods. If the modules are divided into other modules or not divided at all, as long as the PLC program editing device, PLC program compilation device, and PLC program execution device have the above-described functions, they should all be within the protection scope of this application.
[0229] This application also provides an electronic device, such as... Figure 10 As shown, the system includes a processor 101 and a machine-readable storage medium 102. The machine-readable storage medium 102 stores machine-executable instructions that can be executed by the processor 101. The processor 101 is prompted by the machine-executable instructions to: implement any of the above-described PLC program editing methods, or implement any of the above-described PLC program compilation methods, or implement any of the above-described PLC program execution methods.
[0230] This application embodiment also provides a computer-readable storage medium storing a computer program. When the computer program is executed by a processor, it implements any of the above-described PLC program editing methods, or implements any of the above-described PLC program compilation methods, or implements any of the above-described PLC program execution methods.
[0231] This application also provides a computer program product containing instructions that, when run on a computer, causes the computer to execute any of the above-described PLC program editing methods, or execute any of the above-described PLC program compilation methods, or execute any of the above-described PLC program execution methods.
[0232] The machine-readable storage medium in the aforementioned electronic device may include random access memory (RAM) or non-volatile memory (NVM), such as at least one disk storage device. Optionally, the memory may also be at least one storage device located remotely from the aforementioned processor.
[0233] The processors mentioned above can be general-purpose processors, including central processing units (CPUs), network processors (NPs), etc.; they can also be digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.
[0234] The various embodiments in this specification are described in a related manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the embodiments of devices, electronic devices, computer-readable storage media, and computer program products are basically similar to the method embodiments, and therefore the descriptions are relatively simple; relevant parts can be referred to the descriptions of the method embodiments.
[0235] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0236] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0237] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0238] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0239] Obviously, those skilled in the art can make various modifications and variations to this application without departing from the spirit and scope of this application. Therefore, if such modifications and variations fall within the scope of the claims of this application and their equivalents, this application also intends to include such modifications and variations.
Claims
1. A PLC program editing method characterized by comprising: The method comprises the following steps: displaying an editing interface, wherein the editing interface comprises function block instance to be edited and function block instance editing item of the function block instance; when the editing operation performed by the function block instance editing item indicates that the function block instance is set to be executed asynchronously, marking the function block instance in the PLC program edited this time as asynchronous execution, and the function block instance marked as asynchronous execution as an asynchronous function block instance; in the editing interface, displaying parameter editing item of the asynchronous function block instance for the asynchronous function block instance, wherein the parameter editing item is used to edit asynchronous execution parameter of the asynchronous function block instance, and the asynchronous execution parameter is used to execute the asynchronous function block instance asynchronously; obtaining actual parameter of the asynchronous execution parameter set based on the parameter editing item, and obtaining defined asynchronous function block instance.
2. The method of claim 1, wherein, The method comprises the following steps: displaying a text editing interface, wherein the function block instance editing item is used to indicate that the function block instance is set to be executed asynchronously through adding editing operation of preset syntax mark; or displaying a graphic editing interface, wherein the function block instance editing item comprises preset editing option, and when the preset editing option is selected, it indicates that the function block instance is set to be executed asynchronously.
3. The method of claim 1, wherein, The function block instance editing item is a check box corresponding to all function block instances to be edited, and when the check box is checked, it indicates that the corresponding function block instance is set to be executed asynchronously.
4. The method of claim 1, wherein, The asynchronous execution parameter comprises: input parameter used to trigger asynchronous execution function block instance as start execution parameter; output parameter used to indicate that the function block instance is executing as executing parameter; output parameter used to indicate that the function block instance has completed execution as execution completion parameter.
5. A PLC program compiling method characterized by comprising: The method comprises the following steps: for function block instance defined in the PLC program to be compiled, when the function block instance is marked as asynchronous execution as an asynchronous function block instance, adding asynchronous execution parameter of the asynchronous function block instance, wherein the asynchronous execution parameter is used to execute the asynchronous function block instance asynchronously; setting call entry of the asynchronous function block instance as asynchronous function block call entry, wherein parameter of the asynchronous function block call entry is memory address allocated for the asynchronous function block instance; creating memory layout for the asynchronous function block instance according to defined memory layout contained in the function block corresponding to the asynchronous function block instance, and obtaining compiled code used to execute the asynchronous function block instance asynchronously.
6. The method of claim 5, wherein, The asynchronous execution parameter comprises: input parameter used to trigger asynchronous execution function block instance as start execution parameter; output parameter used to indicate that the function block instance is executing as executing parameter; output parameter used to indicate that the function block instance has completed execution as execution completion parameter.
7. The method of claim 5, wherein, Before the step of adding asynchronous execution parameter of the asynchronous function block instance when the function block instance defined in the PLC program to be compiled is marked as asynchronous execution as an asynchronous function block instance, the method further comprises the following steps: For a function block instance defined in a PLC program to be compiled, when the function block instance is marked as asynchronous execution as an asynchronous function block instance, source code of an asynchronous function block having the same function as a function block corresponding to the asynchronous function block instance is generated, the source code containing an asynchronous execution parameter and an asynchronous function block calling entry of the asynchronous function block instance; The adding of the asynchronous execution parameter of the asynchronous function block instance includes: The adding of the asynchronous execution parameter of the asynchronous function block instance is implemented through compilation of the source code of the asynchronous function block; The setting of the calling entry of the asynchronous function block instance as an asynchronous function block calling entry includes: The setting of the calling entry of the asynchronous function block instance as an asynchronous function block calling entry is implemented through compilation of the source code of the asynchronous function block; The creating of the memory layout for the asynchronous function block instance according to the defined memory layout contained in the function block corresponding to the asynchronous function block instance includes: The creating of the memory layout for the asynchronous function block instance according to the defined memory layout contained in the function block corresponding to the asynchronous function block instance is implemented through compilation of the source code of the asynchronous function block.
8. The method of claim 5, wherein, The asynchronous function block calling entry includes: a program statement for determining whether to start execution of the program statement of the asynchronous function block instance based on a current parameter value of the asynchronous execution parameter; a program statement for calling a runtime asynchronous function block service, the runtime asynchronous function block service being configured to asynchronously execute the asynchronous function block instance.
9. The method of claim 8, wherein, The parameter of the runtime asynchronous function block service includes a memory address allocated for the asynchronous function block instance and a function block calling entry of the function block corresponding to the asynchronous function block instance; The runtime asynchronous function block service is configured to execute the asynchronous function block instance through an asynchronous service thread.
10. A PLC program execution method characterized by, It includes: For an asynchronous function block instance to be executed in a PLC program, the asynchronous function block instance is asynchronously executed through an asynchronous function block calling entry of the asynchronous function block instance, based on a current parameter value of an asynchronous execution parameter of the asynchronous function block instance and a memory layout, the parameter of the asynchronous function block calling entry being a memory address allocated for the asynchronous function block instance, the asynchronous function block instance being a function block instance marked as asynchronous execution in an editing process of the PLC program; While the asynchronous function block instance is being asynchronously executed, a statement after the asynchronous function block instance in the PLC program is executed.
11. The method of claim 10, wherein, The asynchronous execution of the asynchronous function block instance based on the current parameter value of the asynchronous execution parameter of the asynchronous function block instance and the memory layout includes: When the current parameter value of the asynchronous execution parameter of the asynchronous function block instance indicates start of execution, a runtime asynchronous function block service is called, the parameter of the runtime asynchronous function block service including a memory address allocated for the asynchronous function block instance and a function block calling entry of a function block corresponding to the asynchronous function block instance; The runtime asynchronous function block service is configured to execute the asynchronous function block instance through an asynchronous service thread.
12. The method of claim 11, wherein, The runtime asynchronous function block service is configured to execute the asynchronous function block instance by an asynchronous service thread using the following steps: creating an asynchronous task, the asynchronous task containing a memory address allocated to the asynchronous function block instance according to a memory layout of the asynchronous function block instance, and a function block call entry of a function block corresponding to the asynchronous function block instance; calling the function block call entry by the asynchronous service thread using the memory address as a parameter to execute the function block; updating a current parameter value of the asynchronous execution parameter; releasing the memory allocated for executing the asynchronous task.
13. The method according to any one of claims 10 to 12, wherein, The asynchronous execution parameter includes: an input parameter for triggering an asynchronous execution function block instance as a start execution parameter; an output parameter for indicating that a function block instance is executing as an executing parameter; an output parameter for indicating that a function block instance has completed execution as an execution completion parameter.
14. A PLC program editing apparatus characterized by comprising: It includes: an instance editing display module configured to display an editing interface, the editing interface containing a function block instance to be edited and a function block instance editing item of the function block instance; an asynchronous setting module configured to, when an editing operation performed on the function block instance editing item indicates that the function block instance is set to asynchronous execution, mark the function block instance in the PLC program edited this time as asynchronous execution, the function block instance marked as asynchronous execution serving as an asynchronous function block instance; a parameter editing display module configured to, in the editing interface, display, for the asynchronous function block instance, a parameter editing item of the asynchronous function block instance, the parameter editing item being used to edit an asynchronous execution parameter of the asynchronous function block instance, the asynchronous execution parameter being used to asynchronously execute the asynchronous function block instance; an actual parameter acquisition module configured to acquire an actual parameter of the asynchronous execution parameter set based on the parameter editing item, to obtain a defined asynchronous function block instance.
15. The apparatus of claim 14, wherein, The editing interface is displayed, including: displaying a text editing interface, the function block instance editing item being used to indicate, through an editing operation of adding a preset syntax mark, that the function block instance is set to asynchronous execution; or displaying a graphical editing interface, the function block instance editing item containing a preset editing option, the preset editing option being selected to indicate that the function block instance is set to asynchronous execution.
16. The apparatus of claim 14, wherein, The function block instance editing item is a check box corresponding to all function block instances to be edited, the check box being checked to indicate that the corresponding function block instance is set to asynchronous execution.
17. The apparatus of claim 14, wherein, The asynchronous execution parameter includes: an input parameter for triggering an asynchronous execution function block instance as a start execution parameter; an output parameter for indicating that a function block instance is executing as an executing parameter; an output parameter for indicating that a function block instance has completed execution as an execution completion parameter.
18. A PLC program compiling apparatus characterized by comprising: It includes: a parameter adding module configured to, for a function block instance defined in a PLC program to be compiled, when the function block instance is marked as asynchronous execution as an asynchronous function block instance, add an asynchronous execution parameter of the asynchronous function block instance, the asynchronous execution parameter being used to asynchronously execute the asynchronous function block instance; The calling entry setting module is configured to set the calling entry of the asynchronous function block instance as an asynchronous function block calling entry, and the parameter of the asynchronous function block calling entry is a memory address allocated for the asynchronous function block instance. The memory layout creating module is configured to create a memory layout for the asynchronous function block instance according to a defined memory layout contained in the function block corresponding to the asynchronous function block instance, and obtain a compiled code for asynchronously executing the asynchronous function block instance.
19. The apparatus of claim 18, wherein, The asynchronous execution parameter includes: an input parameter for triggering the asynchronous execution function block instance, as a start execution parameter; an output parameter for indicating that the function block instance is executing, as an executing parameter; an output parameter for indicating that the function block instance has completed execution, as an execution completion parameter.
20. The apparatus of claim 18, wherein, Further comprising: a source code generating module configured to, for a function block instance defined in a PLC program to be compiled, generate source code of an asynchronous function block having the same function as a function block corresponding to the asynchronous function block instance when the function block instance is marked as asynchronous execution as an asynchronous function block instance, and the source code contains asynchronous execution parameters and an asynchronous function block calling entry of the asynchronous function block instance; the parameter adding module is specifically configured to add the asynchronous execution parameters of the asynchronous function block instance by compiling the source code of the asynchronous function block; the calling entry setting module is specifically configured to set the calling entry of the asynchronous function block instance as an asynchronous function block calling entry by compiling the source code of the asynchronous function block; the memory layout creating module is specifically configured to create a memory layout for the asynchronous function block instance according to a defined memory layout contained in the function block corresponding to the asynchronous function block instance by compiling the source code of the asynchronous function block.
21. The apparatus of claim 18, wherein, The asynchronous function block calling entry includes: a program statement for determining whether to start executing the program statement of the asynchronous function block instance based on a current parameter value of the asynchronous execution parameter; a program statement for calling a runtime asynchronous function block service, and the runtime asynchronous function block service is configured to asynchronously execute the asynchronous function block instance.
22. The apparatus of claim 21, wherein, The parameter of the runtime asynchronous function block service includes a memory address allocated for the asynchronous function block instance and a function block calling entry of the function block corresponding to the asynchronous function block instance; The runtime asynchronous function block service is configured to execute the asynchronous function block instance through an asynchronous service thread.
23. A PLC program execution device characterized by comprising: Comprising: an asynchronous execution module configured to, for an asynchronous function block instance to be executed in a PLC program, asynchronously execute the asynchronous function block instance based on a current parameter value of an asynchronous execution parameter of the asynchronous function block instance and a memory layout by calling an asynchronous function block calling entry of the asynchronous function block instance, and the parameter of the asynchronous function block calling entry is a memory address allocated for the asynchronous function block instance, and the asynchronous function block instance is a function block instance marked as asynchronous execution in an editing process of the PLC program; a statement execution module configured to execute a statement after the asynchronous function block instance in the PLC program while asynchronously executing the asynchronous function block instance.
24. The apparatus of claim 23, wherein, The asynchronous execution module is specifically configured to: when a current parameter value of an asynchronous execution parameter of the asynchronous function block instance indicates starting execution, invoke a runtime asynchronous function block service, and parameters of the runtime asynchronous function block service include: a memory address allocated for the asynchronous function block instance and a function block call entry of a function block corresponding to the asynchronous function block instance. The runtime asynchronous function block service is configured to execute the asynchronous function block instance through an asynchronous service thread.
25. The apparatus of claim 24, wherein, The runtime asynchronous function block service is configured to execute the asynchronous function block instance through an asynchronous service thread by using the following steps: create an asynchronous task, and the asynchronous task includes the memory address allocated for the asynchronous function block instance according to a memory layout of the asynchronous function block instance and the function block call entry of the function block corresponding to the asynchronous function block instance; invoke the function block call entry through the asynchronous service thread by using the memory address as a parameter, to execute the function block; update the current parameter value of the asynchronous execution parameter; release the memory allocated for executing the asynchronous task.
26. The apparatus of any one of claims 23-25, wherein, The asynchronous execution parameter includes: an input parameter for triggering an asynchronous execution function block instance, as a starting execution parameter; an output parameter for indicating that a function block instance is executing, as an executing parameter; an output parameter for indicating that a function block instance has completed execution, as a completed execution parameter.
27. An electronic device, comprising: A processor and a machine readable storage medium are included, and the machine readable storage medium stores machine executable instructions capable of being executed by the processor, and the processor is prompted by the machine executable instructions to implement the PLC program editing method of any one of claims 1-4, or implement the PLC program compiling method of any one of claims 5-9, or implement the PLC program execution method of any one of claims 10-13.
28. A computer-readable storage medium, characterized in that, The computer readable storage medium stores a computer program, and the computer program is executed by the processor to implement the PLC program editing method of any one of claims 1-4, or implement the PLC program compiling method of any one of claims 5-9, or implement the PLC program execution method of any one of claims 10-13.
Citation Information
Patent Citations
Information processing device, information processing method, and computer readable recording medium
CN109388096A
Industrial Control with Integrated Machine Vision
US20090234471A1