Program control method, device and computer equipment of programmable logic controller
By acquiring and controlling the execution of third-party programs within the PLC, the shortcomings of PLC programming languages are resolved, enabling functional expansion and efficiency improvement.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-18
- Publication Date
- 2026-04-07
AI Technical Summary
The existing PLC programming languages are not rich enough, making it difficult to load arbitrary third-party programs, which limits the flexibility of use and the scalability of functions.
By acquiring a third-party program compiled using a compiler compatible with the programmable logic controller (PLC), and utilizing interface functions and configuration information, its operation within the PLC can be controlled, including program startup, shutdown, and data manipulation.
This expands the functionality of the PLC, improves its flexibility and program execution efficiency, and thus enhances the control efficiency of industrial control processes.
Smart Images

Figure CN120742776B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of industrial automation control technology, and in particular to a programmable logic controller program control method, apparatus, computer equipment, computer-readable storage medium, and computer program product. Background Technology
[0002] Programmable Logic Controllers (PLCs) are core components in industrial automation control systems. PLCs collect real-time data from the industrial field by reading inputs, execute production processes by running applications, and control production equipment by updating outputs. As industrial automation control systems expand in scale and processes become increasingly complex and diverse, users require industrial PLCs with open development environments and more robust integration capabilities.
[0003] Currently, PLCs do not support a wide range of programming languages, making it difficult to load arbitrary third-party programs and limiting their functionality. This results in certain limitations in the flexibility and scalability of PLCs. Summary of the Invention
[0004] Therefore, it is necessary to provide a programmable logic controller (PLC) control method, apparatus, computer equipment, computer-readable storage medium, and computer program product that can expand the functionality of the PLC and improve its flexibility of use, in order to address the above-mentioned technical problems.
[0005] In a first aspect, this application provides a programmable logic controller (PLC) control method, comprising:
[0006] Obtain third-party programs compiled using a compiler compatible with the programmable logic controller;
[0007] Based on the configuration information for the third-party program in the programmable logic controller, the operation of the third-party program in the programmable logic controller is controlled.
[0008] In one embodiment, the method further includes:
[0009] Obtain the interface functions encapsulated in the interface library, and determine the interface functions as the configuration information for the third-party program in the programmable logic controller;
[0010] The step of controlling the execution of the third-party program within the programmable logic controller (PLC) based on the configuration information for the third-party program includes:
[0011] By calling the interface function, the operation of the third-party program in the programmable logic controller can be controlled.
[0012] In one embodiment, the interface function includes a program startup function and candidate operation functions corresponding to various candidate operation types;
[0013] The step of controlling the execution of the third-party program in the programmable logic controller by calling the interface function includes:
[0014] By calling the program startup function, the third-party program is controlled to load into the programmable logic controller;
[0015] From the candidate operation functions, determine the target operation function that matches the expected operation type of the third-party program;
[0016] By invoking the target operation function, the third-party program is controlled to perform data operations in the programmable logic controller that match the desired operation type.
[0017] In one embodiment, controlling the third-party program to perform data operations matching the desired operation type in the programmable logic controller by calling the target operation function includes:
[0018] A third-party process corresponding to the third-party program is generated in the programmable logic controller.
[0019] Based on the data interaction channel between the third-party process and the application process of the programmable logic controller, the third-party process is controlled to perform data operations matching the desired operation type in the programmable logic controller by calling the target operation function.
[0020] In one embodiment, the step of controlling the third-party process to perform data operations matching the desired operation type in the programmable logic controller by calling the target operation function through the data interaction channel between the third-party process and the application process of the programmable logic controller includes:
[0021] Analyze the target operation function to determine the data operation information that matches the desired operation type;
[0022] When the expected operation type is a write operation, the application process is invoked to write the first data to the data interaction channel according to the data operation information corresponding to the expected operation type, so that the third-party process can read the first data from the data interaction channel.
[0023] When the expected operation type is a read operation, the application process is invoked to read out the second data written by the third-party process into the data interaction channel according to the data operation information corresponding to the expected operation type.
[0024] In one embodiment, the interface function further includes a program stop function; the method further includes:
[0025] In response to a program stop event for the third-party program, the program stop function is invoked to control the third-party program to stop running in the programmable logic controller.
[0026] Cancel the data interaction channel between the third-party process and the application process of the programmable logic controller.
[0027] In one embodiment, the method further includes:
[0028] Obtain the mapping relationship between the addresses of the input / output data areas in the programmable logic controller and the preset processing commands, and determine the mapping relationship as the configuration information of the programmable logic controller for the third-party program;
[0029] The step of controlling the execution of the third-party program within the programmable logic controller (PLC) based on the configuration information for the third-party program includes:
[0030] Based on the mapping relationship, a target address matching the expected processing command of the third-party program is determined; the expected processing command includes at least one of the following: a program start command, a program stop command, a write command, or a read command;
[0031] By modifying the variable corresponding to the target address to be consistent with the preset variable corresponding to the expected processing command, the third-party program is controlled to run an operation matching the processing command in the programmable logic controller.
[0032] Secondly, this application provides a programmable logic controller (PLC) control device, the device comprising:
[0033] The acquisition module is used to acquire third-party programs compiled based on a compiler that matches the programmable logic controller.
[0034] The control module is used to control the operation of the third-party program in the programmable logic controller based on the configuration information for the third-party program in the programmable logic controller.
[0035] Thirdly, this application also provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to perform the following steps:
[0036] Obtain third-party programs compiled using a compiler compatible with the programmable logic controller;
[0037] Based on the configuration information for the third-party program in the programmable logic controller, the operation of the third-party program in the programmable logic controller is controlled.
[0038] Fourthly, this application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, performs the following steps:
[0039] Obtain third-party programs compiled using a compiler compatible with the programmable logic controller;
[0040] Based on the configuration information for the third-party program in the programmable logic controller, the operation of the third-party program in the programmable logic controller is controlled.
[0041] Fifthly, this application also provides a computer program product, including a computer program that, when executed by a processor, performs the following steps:
[0042] Obtain third-party programs compiled using a compiler compatible with the programmable logic controller;
[0043] Based on the configuration information for the third-party program in the programmable logic controller, the operation of the third-party program in the programmable logic controller is controlled.
[0044] The aforementioned programmable logic controller (PLC) control method, apparatus, computer device, computer-readable storage medium, and computer program product acquire third-party programs compiled using a compiler compatible with the PLC. This allows arbitrary functional code to be compiled into a program that runs on the PLC, expanding its functionality and increasing its flexibility. Furthermore, by controlling the execution of the third-party program within the PLC based on its configuration information, the program's execution efficiency can be improved, thereby enhancing control efficiency in industrial control processes. Attached Figure Description
[0045] To more clearly illustrate the technical solutions in the embodiments of this application or related technologies, the drawings used in the description of the embodiments of this application or related technologies will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0046] Figure 1 This is a structural block diagram of an industrial automation control system in one embodiment;
[0047] Figure 2 This is a flowchart illustrating the program control method of a programmable logic controller in one embodiment;
[0048] Figure 3 This is a schematic diagram illustrating the process of controlling the operation of a third-party program in a programmable logic controller (PLC) based on configuration information for that third-party program in one embodiment.
[0049] Figure 4 This is a flowchart illustrating the process of controlling the operation of a third-party program in a programmable logic controller by calling interface functions in one embodiment.
[0050] Figure 5 This is a flowchart illustrating how, in one embodiment, a third-party program is controlled to perform data operations matching the desired operation type within a programmable logic controller by calling a target operation function.
[0051] Figure 6 This is a schematic diagram illustrating the process of controlling the operation of a third-party program in a programmable logic controller (PLC) based on configuration information for the third-party program in another embodiment.
[0052] Figure 7 This is a control diagram illustrating a programmable logic controller (PLC) control method in one embodiment.
[0053] Figure 8 This is a schematic diagram illustrating data interaction between a third-party process and an application process based on shared memory in one embodiment.
[0054] Figure 9 This is a structural block diagram of the programmable logic controller's program control device in one embodiment;
[0055] Figure 10 This is an internal structural diagram of a computer device in one embodiment. Detailed Implementation
[0056] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0057] The embodiments of the technical solution of this application will now be described in detail with reference to the accompanying drawings. These embodiments are only used to more clearly illustrate the technical solution of this application and are therefore merely examples, and should not be used to limit the scope of protection of this application.
[0058] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application pertains; the terminology used herein is for the purpose of describing particular embodiments only and is not intended to limit the application; the terms “comprising” and “having”, and any variations thereof, in the specification, claims, and foregoing description of the drawings are intended to cover non-exclusive inclusion.
[0059] In the description of the embodiments of this application, technical terms such as "first" and "second" are used only to distinguish different objects and should not be construed as indicating or implying relative importance or implicitly specifying the number, specific order, or primary and secondary relationship of the indicated technical features. In the description of the embodiments of this application, "multiple" means two or more, unless otherwise explicitly defined.
[0060] In this document, the term "embodiment" means that a particular feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of this application. The appearance of this phrase in various places throughout the specification does not necessarily refer to the same embodiment, nor is it a separate or alternative embodiment mutually exclusive with other embodiments. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments.
[0061] In the description of the embodiments in this application, the term "and / or" is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, and B existing alone. Additionally, the character " / " in this document generally indicates that the preceding and following related objects have an "or" relationship.
[0062] Currently, common industrial automation control systems such as Figure 1As shown, the PLC communicates with the host computer via a first fieldbus and with at least one servo driver and coupler via a second fieldbus. The host computer can be a Human-Machine Interface (HMI) for displaying on-site process parameters; the servo driver drives the motors; and the coupler connects to at least one input / output module (IO module) via a backplane bus to collect and output production data from the industrial site. Thus, the PLC loads and executes the user's process control program, achieving various industrial production processes through periodic input reading, logic execution, and output refresh.
[0063] PLCs support programming languages such as Ladder Diagram (LD), Structured Text (ST), Sequential Function Chart (SFC), Function Block Diagram (FBD), and Instruction List (IL). These languages can implement the user's required process control. However, if the process algorithm is complex and requires high execution efficiency, the programming languages currently supported by the PLC are inconvenient for implementation. Furthermore, some PLC application development environments support C language function calls but do not support the general libc library and POSIX programming interface, limiting the functionality they can achieve. This results in a limited range of supported programming languages for PLCs, making it difficult to load arbitrary third-party programs, thus limiting the flexibility and functional expandability of PLCs.
[0064] In view of this, if a compiler matching the programmable logic controller is provided to the user, the user can compile the code of any function into a third-party program that can be run in the PLC by simply setting up a compilation environment corresponding to the compiler. By downloading the third-party program to the PLC and running it, the operation of the third-party program can be controlled at the application layer of the PLC.
[0065] like Figure 2 As shown, a programmable logic controller (PLC) control method is provided. Taking the application of this method to a PLC as an example, the method includes the following steps:
[0066] S202, Obtain a third-party program compiled using a compiler that matches the programmable logic controller.
[0067] The compiler is used to compile third-party code into a third-party program that can be run in the PLC. The functions implemented by the third-party code can be set according to the actual application scenario.
[0068] For example, the compiler provided by the PLC's main unit manufacturer can be used as the compiler that matches the programmable logic controller. The main unit in the PLC may include a central processing unit (CPU), etc.
[0069] In one embodiment, when a third-party program is downloaded to the host of the programmable logic controller (PLC) based on a target protocol, the third-party program is obtained by compiling it using a compiler compatible with the PLC. In other words, after obtaining the third-party program corresponding to the third-party code using the compiler, the user can download the third-party program to the host of the PLC via the target protocol.
[0070] For example, the target protocol may include protocols such as File Transfer Protocol (FTP), Secure Copy Protocol (SCP), and Samba.
[0071] In one embodiment, if a third-party program has been downloaded to the host of the programmable logic controller, the third-party program can be stored on the disk of the host of the programmable logic controller.
[0072] S204 controls the operation of third-party programs within the programmable logic controller (PLC) based on the configuration information for those programs.
[0073] Configuration information refers to the information configured by the programmable logic controller (PLC) to control the execution of third-party programs. The content of the configuration information is not limited. For example, configuration information may include interface functions and processing commands. Different interface functions result in different control processes by the PLC over the third-party program, leading to different execution behaviors of the third-party program within the PLC. Similarly, different processing commands result in different processing behaviors of the PLC over the third-party program. In some cases, the control process corresponding to the interface function and the processing process corresponding to the processing command can be the same.
[0074] The implementation method for controlling the execution of a third-party program within the programmable logic controller (PLC) based on its configuration information is not limited. For example, the configuration information for the third-party program can be parsed to obtain the corresponding processing commands; the execution of the third-party program within the PLC can then be matched with these processing commands.
[0075] based on Figure 2The content shown demonstrates how, by acquiring third-party programs compiled using a compiler compatible with the programmable logic controller (PLC), code with arbitrary functionality can be compiled into programs that run on the PLC, expanding its capabilities and increasing its flexibility. Furthermore, based on the configuration information for the third-party program within the PLC, its execution can be controlled. By pre-configuring the third-party program's settings, program execution efficiency can be improved, further enhancing control efficiency in industrial control processes.
[0076] In one embodiment, the implementation of controlling the execution of a third-party program within the programmable logic controller (S204) based on configuration information for that third-party program in the programmable logic controller can be as follows: Figure 3 As shown, it includes the following steps:
[0077] S302, obtain the interface functions encapsulated in the interface library, and determine the interface functions as the configuration information for third-party programs in the programmable logic controller.
[0078] The type of interface function is not limited. For example, an interface function may include at least one of a program start function, a program stop function, or a candidate operation function corresponding to a candidate operation type, and the number of candidate operation types may be one or more.
[0079] Candidate operation types characterize the processing method of target data in the programmable logic controller (PLC). For example, candidate operation types can include write operations and read operations. Candidate operation functions characterize the PLC's processing logic for the target data, the content of which is not limited. For example, target data can refer to the final and / or intermediate results generated by running a third-party program, the results generated by the application process in the PLC, or other forms.
[0080] In one embodiment, the programmable logic controller (PLC) is configured with PLC background software and application processes. The PLC background software is the core tool for programming, debugging, monitoring, and maintaining the PLC. The PLC host also deploys a runtime environment (Runitme), i.e., PLC Runitme, in which the PLC application processes run.
[0081] For example, an application process can obtain configuration information for third-party programs in a programmable logic controller by calling interface functions encapsulated in an interface library. For example, an application process can call interface functions encapsulated in an interface library based on a communication protocol.
[0082] In one embodiment, when the programmable logic controller includes an interface library configured for a third-party program, the configuration information of the programmable logic controller for the third-party program can be obtained by acquiring the interface functions encapsulated in the interface library.
[0083] S304 controls the operation of third-party programs in the programmable logic controller by calling interface functions.
[0084] The control process for controlling the operation of third-party programs in the programmable logic controller varies depending on the type of the interface function.
[0085] In one embodiment, the interface function includes a program stop function, which, in response to a program stop event for a third-party program, controls the third-party program to stop running in the programmable logic controller by calling the program stop function.
[0086] The program stop event can be generated automatically or manually. For example, a program stop event can be generated automatically if the result of a third-party program matches the expected result. Alternatively, a program stop event can be manually generated based on the industrial control computer software.
[0087] In one implementation, if a third-party program is already running in the programmable logic controller (PLC), the application process is controlled to call a program stop function, thereby stopping the third-party program from running in the PLC.
[0088] based on Figure 3 The content shown demonstrates that by pre-configuring the interface functions encapsulated in the interface library, the programmable logic controller (PLC) can control the operation of third-party programs based on these interface functions. This expands the functionality of the PLC and improves the efficiency of externally connected programs.
[0089] In one embodiment, the interface function includes a program startup function and candidate operation functions corresponding to various candidate operation types. For example, the implementation of controlling the operation of a third-party program in the programmable logic controller (i.e., S304) by calling the interface function can be as follows: Figure 4 As shown, it includes:
[0090] S402 controls the loading of third-party programs into the programmable logic controller by calling the program startup function.
[0091] In one embodiment, the program startup function is parsed to obtain the storage location of the third-party program on the host disk of the programmable logic controller; if the third-party program is read from the host disk to the host memory of the programmable logic controller based on the storage location, the third-party program is controlled to be loaded into the host memory of the programmable logic controller.
[0092] In one embodiment, parsing the program startup function can also obtain data channel information; based on the data channel information, a data interaction channel is created between the third-party process and the application process of the programmable logic controller. Here, data channel information refers to the information used to generate the data interaction channel. For example, taking shared memory as an example, the data channel information may include the number of partitions in the shared memory and the partition address corresponding to each partition.
[0093] The storage location can be represented by the program save path or the program storage address.
[0094] In some embodiments, the storage location can be configured in the startup code corresponding to the industrial control system where the programmable logic controller is located or the RLC operating environment, so that when the PLC is powered on and started, the third-party program in the host disk can be automatically read into the host memory of the programmable logic controller, so that the third-party program can be loaded and run in the host memory of the programmable logic controller.
[0095] S404: From the candidate operation functions, determine the target operation function that matches the expected operation type of the third-party program.
[0096] The expected operation types include write operations and read operations, etc.
[0097] Specifically, for each candidate operation function, if the candidate operation type matches the expected operation type, then the candidate operation function corresponding to the matching candidate operation type is determined as the target operation function that matches the expected operation type of the third-party program.
[0098] S406 controls a third-party program to perform data operations matching the desired operation type in the programmable logic controller by calling the target operation function.
[0099] In one embodiment, when a third-party program is loaded into the programmable logic controller (PLC), a third-party process corresponding to the third-party program is generated in the host of the PLC. Based on the data interaction channel between the application process and the third-party process in the host of the PLC, the third-party program is controlled to perform data operations matching the expected operation type in the PLC by calling the target operation function.
[0100] In one implementation, when a third-party program is loaded into the programmable logic controller (PLC), the application process or the third-party process can be invoked to create a data interaction channel between the application process and the third-party process. Alternatively, other processes in the industrial control system where the PLC resides can be invoked to create a data interaction channel between the application process and the third-party process. The form of creating the data interaction channel is not limited.
[0101] The form of the data interaction channel is not limited. For example, the form of the data interaction channel may include shared memory, message queues, pipes, and sockets. In some embodiments, the data interaction channel may be a memory address in the host memory of the programmable logic controller or a preset data interface.
[0102] For example, the data interaction channel can be represented by shared memory. This involves the application process or a third-party process requesting physical memory in the programmable logic controller's memory space, using this physical memory as shared memory. For example, the shared memory can include multiple partitions, each including a protection lock and a data area. The data area is used to store data, and the protection lock is used to protect data write operations or data read operations in the data area.
[0103] based on Figure 4 As shown, when the interface function includes a program startup function and candidate operation functions corresponding to various candidate operation types, the programmable logic controller (PLC) can control the operation of third-party programs by calling the interface function, thus expanding the flexibility of the PLC.
[0104] In one embodiment, the implementation method of controlling a third-party program to perform data operations matching the desired operation type in the programmable logic controller by calling the target operation function (i.e., S406) can be as follows: Figure 5 As shown, it includes the following steps:
[0105] S502 generates a third-party process corresponding to a third-party program in a programmable logic controller.
[0106] For example, when a third-party program is loaded into the programmable logic controller (PLC), a third-party process corresponding to the third-party program is generated in the host of the PLC.
[0107] S504 is a data interaction channel between a third-party process and the application process of the programmable logic controller. By calling the target operation function, it controls the third-party process to perform data operations in the programmable logic controller that match the expected operation type.
[0108] In one embodiment, the target operation function is parsed to obtain data operation information that matches the desired operation type; based on the data operation information and the data interaction channel between the third-party process and the application process of the programmable logic controller, the third-party process is controlled to execute data operations that match the desired operation type in the programmable logic controller.
[0109] The data operation information may include the starting address of the data, the data length, and the data value corresponding to the expected operation type. The content of the data interaction channel can be found in the aforementioned description.
[0110] In one implementation, when the expected operation type is a write operation, the application process writes the first data to the data interaction channel according to the data operation information corresponding to the expected operation type, so that the third-party process can read the first data from the data interaction channel.
[0111] The first data refers to the data generated by the application process after it runs and needs to be sent to a third-party process.
[0112] For example, the third-party process stores the first data in the address space corresponding to the third-party process.
[0113] For example, the data interaction channel includes shared memory, which has multiple partitions, each with a partition address. Then, by mapping the application process to the corresponding partition addresses of each partition, the application process is invoked to write the second data into at least one partition according to the data operation information corresponding to the desired operation type.
[0114] For example, each partition in the shared memory includes a protection lock and a data area, where the first data includes first sub-data corresponding to at least one partition. If a third-party process fails to acquire the protection lock for the first target partition, the third-party process is controlled to stop reading the first sub-data in the first target partition until the protection lock for the first target partition is successfully acquired, at which point the third-party process is controlled to resume reading the first sub-data of the first target partition. Alternatively, the third-party process can be controlled to skip the first target partition and read the first sub-data in the next partition. Here, the first target partition refers to the partition containing the data that the third-party process should read from the shared memory.
[0115] For example, if a third-party process successfully acquires a protection lock for the first target partition, the third-party process is invoked to release the protection lock for the second target partition.
[0116] In some embodiments, automatic data refresh can also be achieved based on the scan cycle of the PLC Runtime, so that the application process can write the latest data to the shared memory.
[0117] In one implementation, when the expected operation type is a read operation, the application process reads out the second data written by the third-party process into the data interaction channel according to the data operation information corresponding to the expected operation type.
[0118] The second data refers to the data generated by the third-party program after it runs and needs to be sent to the application process.
[0119] In one embodiment, the data interaction channel includes shared memory with multiple partitions, each with a partition address. By mapping application processes to the corresponding partition addresses of each partition, the application process, according to the data operation information corresponding to the desired operation type, reads the second data written by the third-party process into the data interaction channel, thereby enabling the data transmission from the third-party process to the PLC application layer via the data interaction channel.
[0120] For example, each partition in the shared memory includes a protection lock and a data area, and the second data includes second sub-data corresponding to at least one partition. If the application process fails to acquire the protection lock for the second target partition, the application process is stopped from reading the second sub-data in the second target partition until the protection lock for the second target partition is successfully acquired, at which point the application process is called again to read the second sub-data of the second target partition. Alternatively, the application process can skip the second target partition and read the second sub-data in the next partition after the second target partition. Here, the second target partition refers to the partition where the data that the application process should read from the shared memory is located.
[0121] For example, if the application process successfully acquires the protection lock for the second target partition, the application process is called to release the protection lock for the second target partition.
[0122] Understandably, by setting a protection lock, the read and write process can be protected so that only one process can operate on the data in the partition at a time. This effectively manages the access order of data in shared memory and improves the reliability of data operations.
[0123] In conjunction with S302, the first or second data in the data interaction channel is the aforementioned target data. The target data can be data written to the data interaction channel by a third-party process or data written to the data interaction channel by an application process. That is, the data in the data interaction channel is data that can be shared by the third-party process and the application process. The content of the data in the data interaction channel can be set according to the actual application scenario, and this embodiment does not impose any limitations.
[0124] based on Figure 5The content shown demonstrates how parsing the target operation function determines the data operation information that matches the desired operation type. When the desired operation type is different, different control processes are executed, thus expanding the functionality of the programmable logic controller (PLC) and improving its flexibility.
[0125] The above describes how, when the interface function includes a program startup function and candidate operation functions corresponding to various candidate operation types, the operation of a third-party program can be controlled by calling the interface function. The interface function can also include other types of functions; for example, it can include a program stop function.
[0126] In one embodiment, the interface function may further include a program stop function. In response to a program stop event for a third-party program, calling the program stop function controls the third-party program to cease execution within the programmable logic controller (PLC); and cancels the data interaction channel between the third-party process and the PLC's application process. Thus, by responding to a program stop event for a third-party program, the running third-party program can be stopped. Furthermore, by canceling the data interaction channel between the third-party process and the PLC's application process, memory resources within the PLC can be saved.
[0127] For example, in response to a program stop event for a third-party program, the application process is controlled to call a program stop function, thereby causing the third-party program to stop running in the programmable logic controller.
[0128] In some embodiments, the program stop function can be configured in the deregistration code corresponding to the industrial control system where the programmable logic controller is located or the RLC operating environment, so that when the PLC is powered off or reset, the third-party program can be automatically controlled to stop running in the programmable logic controller.
[0129] Based on the above, it can be seen that the above describes controlling the operation of a third-party program in a programmable logic controller by calling interface functions encapsulated in an interface library. In one embodiment, it is also possible to use... Figure 6 The content shown describes how, based on the configuration information for third-party programs in the programmable logic controller (PLC), the operation of third-party programs is controlled within the PLC, including the following steps:
[0130] S602, obtain the mapping relationship between the address of the input / output data area in the programmable logic controller and the preset processing command, and determine the mapping relationship as the configuration information for the third-party programmable logic controller.
[0131] The input / output data area refers to the IO data address mapping area in the programmable logic controller. The IO data address mapping area is configured with multiple addresses, each address corresponding to one or more variables, and there is a mapping relationship between the address and the processing command.
[0132] The preset processing commands include, but are not limited to: program start command, program stop command, and write or read command. The contents of the input / output data area addresses corresponding to different preset processing commands are not limited.
[0133] In one embodiment, if no interface library for third-party programs is configured in the programmable logic controller (PLC), the configuration information for third-party programs in the PLC can be obtained by calling the mapping relationship between the addresses of the input / output data areas in the PLC and the preset processing commands.
[0134] S604, based on the mapping relationship, determines the target address that matches the expected processing command of the third-party program.
[0135] For example, the preset processing commands in the mapping relationship are matched with the expected processing command; when the preset processing command and the expected processing command match, the address corresponding to the matching preset processing command is determined as the target address that matches the expected processing command of the third-party program.
[0136] The expected processing command includes at least one of the following: a program start command, a program stop command, a write command, or a read command. For example, when the expected processing command includes a program start command, the program start command is identical to the content of the aforementioned program start function. Similarly, the program stop command is identical to the content of the aforementioned program stop function, the write command is identical to the content of the aforementioned write operation, and the read command is identical to the content of the aforementioned read operation.
[0137] S606 controls a third-party program to perform operations matching the processing command in the programmable logic controller by modifying the variable corresponding to the target address to be consistent with the preset variable corresponding to the expected processing command.
[0138] Among them, the implementation methods for controlling third-party programs to run operations in the programmable logic controller that match the processing commands differ depending on the type of the expected processing command.
[0139] In one implementation, when the expected processing command includes a program startup command, the loading of a third-party program into the programmable logic controller is controlled by modifying the variable corresponding to the target address to be consistent with the preset variable corresponding to the program startup command.
[0140] For example, by modifying the variable corresponding to the target address to be consistent with the preset variable corresponding to the program startup command, the system controls the reading of the third-party program from the host disk into the host memory of the programmable logic controller; and controls the loading of the third-party program into the host memory of the programmable logic controller.
[0141] In one embodiment, when a third-party program is loaded into the programmable logic controller (PLC), a third-party process corresponding to the third-party program is generated, and a data interaction channel is created between the third-party process and the application process of the PLC. The details of the data interaction channel can be found in the foregoing description.
[0142] In one implementation, in response to a program stop event for a third-party program, the third-party program is controlled to stop running in the programmable logic controller by modifying the variable corresponding to the target address to be consistent with the preset variable corresponding to the program stop event, and the data interaction channel between the third-party process and the application process of the programmable logic controller is cancelled.
[0143] The details of the program stop event can be found in the description above, and will not be repeated here.
[0144] In one implementation, if the expected processing command is a write command, the write command is parsed to obtain the data write information; a third-party process is called to migrate the data written by the application process to the data interaction channel according to the data write information to the storage space corresponding to the third-party process.
[0145] Among them, data write information refers to the information that a third-party process should refer to when performing data write operations on the storage space. Data write information may include the starting address of the data to be written to the storage space, the data length, and the data value.
[0146] In one implementation, if the expected processing command is a read command, the read command is parsed to obtain data read information; the application process is then invoked to read the data written to the data interaction channel by the third-party process according to the data read information.
[0147] Among them, data read information refers to the information that the application process should refer to when performing data reading operations on the data interaction channel. Data read information may include the starting address of the data to be read from the data interaction channel, the data length, and other contents.
[0148] The contents of S602-S606 can be adapted to the description by referring to the aforementioned contents.
[0149] based on Figure 6The content shown demonstrates that by modifying the addresses of the input / output data areas in the programmable logic controller (PLC), third-party programs can be controlled to perform operations matching the processing commands within the PLC, thereby expanding the PLC's functionality and improving its flexibility.
[0150] Based on the above, a schematic diagram of a programmable logic controller (PLC) control method is provided. Taking the application of this method to a PLC as an example, the method includes the following steps:
[0151] S11, Obtain the third-party program compiled based on a compiler that matches the programmable logic controller.
[0152] S12, obtain the interface functions encapsulated in the interface library, and determine the interface functions as the configuration information for third-party programs in the programmable logic controller.
[0153] The interface functions include program start function, program stop function, and candidate operation functions corresponding to various candidate operation types.
[0154] S13, by calling the program startup function, controls the loading of the third-party program in the programmable logic controller, generates the third-party process corresponding to the third-party program, and creates a data interaction channel between the third-party process and the application process of the programmable logic controller.
[0155] S14. From the candidate operation functions, determine the target operation function that matches the expected operation type of the third-party program.
[0156] S15, parse the target operation function and determine the data operation information that matches the expected operation type.
[0157] S16, if the expected operation type is a write operation, the application process is called to write the first data to the data interaction channel according to the data operation information corresponding to the expected operation type, so that the third-party process can read the first data from the data interaction channel and store it in the corresponding address space.
[0158] S17, if the expected operation type is a read operation, the application process is called to read out the second data written by the third-party process into the data interaction channel according to the data operation information corresponding to the expected operation type.
[0159] The contents of S11-S17 can be referred to the aforementioned content description, and will not be repeated here.
[0160] Based on the above, it is clear that, using the method provided in this application, users only need to set up a compiler that matches the compiler to compile third-party code with any function into a third-party program that can run on the PLC. The third-party program is then downloaded to the PLC's host disk and subsequently loaded into the PLC's host memory for execution. Furthermore, the PLC's application process can control the start and stop of the third-party program by calling corresponding functions or commands. The application process and the corresponding third-party program communicate through a defined data exchange channel, enabling data reading and writing of the third-party program at the PLC application layer.
[0161] Based on the content shown in S11-S17, in one embodiment, as Figure 7 As shown, a control diagram of a programmable logic controller (PLC) program control method is provided. The PLC is configured with a PLC host and PLC background software. The PLC host has an application process running in the RLC runtime environment, and the PLC background software has an interface library.
[0162] For example, after a user compiles third-party code using a compiler compatible with the programmable logic controller (PLC), the third-party program can be downloaded to the PLC's host disk. By invoking the application process, the application process can call the program startup function encapsulated in the interface library based on the communication protocol. The application process can then parse the startup function to obtain the storage location and data channel information of the third-party program on the host disk. Subsequently, after reading the third-party program from the host disk to the PLC's host memory based on its storage location, the application process can be invoked to load the third-party program into the PLC's host memory. Simultaneously, a third-party process corresponding to the third-party program can be generated, and a data interaction channel between the third-party process and the application process can be created based on the data channel information.
[0163] When a third-party program is already loaded and running in the programmable logic controller (PLC), in response to a program stop event for the third-party program, the control application process calls the program stop function encapsulated in the interface library to stop the third-party program from running in the PLC. The third-party process corresponding to the third-party program will also be deregistered.
[0164] For the write function in the interface library, if the target operation function that matches the expected operation type of the third-party program is a write function, that is, the expected operation type of the third-party program is a write operation, then the target operation function is parsed to determine the data operation information that matches the write operation. Then, the application process is called to write the first data to the data interaction channel according to the data operation information corresponding to the write operation, so that the third-party process can read the first data from the data interaction channel and save it to the corresponding address space.
[0165] For the read function in the interface library, if the target operation function that matches the expected operation type of the third-party program is a read function, that is, if the expected operation type of the third-party program is a read operation, then the target operation function is parsed to determine the data operation information that matches the read operation. Then, the application process is called to read out the second data written by the third-party process into the data interaction channel according to the data operation information corresponding to the read operation.
[0166] Taking shared memory as an example, such as... Figure 8 As shown, a schematic diagram is provided for data interaction between a third-party process and an application process based on shared memory. The shared memory includes N partitions, namely the first partition, the second partition, and so on up to the Nth partition. Each partition is set with a partition address, and each partition includes a protection lock and a data area.
[0167] For example, when an application process needs to transfer shared data to a third-party process, based on the mapping relationship between the application process and the corresponding partition addresses of each partition, controlling the application process to call the write function in the interface library (i.e., calling the write interface in the interface library) can write the shared data to the data area of at least one partition in shared memory. Similarly, when a third-party process writes data to shared memory, controlling the application process to call the read function in the interface library (i.e., calling the read interface in the interface library) can read the data written by the third-party process to at least one partition in shared memory. Thus, based on the shared memory between the third-party process and the application process, the data read and write process can be implemented by controlling the application process to call the write or read functions in the interface library.
[0168] Specifically, when a third-party process writes data to a shared memory partition, the third-party process can be invoked to write data to the shared memory partition based on the mapping relationship between the third-party process and the partition addresses corresponding to each partition.
[0169] In summary, the programmable logic controller (PLC) provided in this application supports loading external third-party programs. These programs only require an interface for data interaction with the PLC host and must be compiled using a compiler specified by the PLC host manufacturer to be loaded and run on the PLC host. Furthermore, the provided compiler supports common libraries and programming interfaces, such as the common libc library and POSIX programming interface. This effectively solves the problems of existing PLCs' limited programming languages, which struggle to implement complex control algorithms, have low code execution efficiency, and lack open development environments. Additionally, PLC users can load any third-party code into the PLC host and access it at the application layer through the data read / write interfaces in the interface library. This provides the PLC with the ability to integrate any third-party code library, allowing users to implement various required functions using different programming languages. This significantly enhances the openness and development potential of the PLC, greatly strengthening the product's competitiveness.
[0170] It should be understood that although the steps in the flowcharts of the embodiments described above are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the embodiments described above may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages of other steps.
[0171] Based on the same inventive concept, this application also provides a program control device for a programmable logic controller (PLC) to implement the program control method of the PLC described above. The solution provided by this device is similar to the implementation described in the above method. Therefore, the specific limitations in one or more PLC program control device embodiments provided below can be found in the limitations of the program control method of the PLC described above, and will not be repeated here.
[0172] In one exemplary embodiment, such as Figure 9 As shown, a programmable logic controller (PLC) control device is provided, comprising: an acquisition module 902 and a control module 904, wherein:
[0173] The acquisition module 902 is used to acquire third-party programs compiled based on a compiler that matches the programmable logic controller.
[0174] The control module 904 is used to control the operation of the third-party program in the programmable logic controller based on the configuration information of the third-party program in the programmable logic controller.
[0175] In one embodiment, the control module 904 is further configured to: obtain interface functions encapsulated in an interface library, determine the interface functions as configuration information for the third-party program in the programmable logic controller; and control the operation of the third-party program in the programmable logic controller by calling the interface functions.
[0176] In one embodiment, the interface function includes a program startup function and candidate operation functions corresponding to various candidate operation types; the control module 904 is further configured to: control the third-party program to load in the programmable logic controller by calling the program startup function; determine a target operation function that matches the expected operation type of the third-party program from the candidate operation functions; and control the third-party program to perform data operations matching the expected operation type in the programmable logic controller by calling the target operation function.
[0177] In one embodiment, the control module 904 is further configured to: generate a third-party process corresponding to the third-party program in the programmable logic controller; and, based on the data interaction channel between the third-party process and the application process of the programmable logic controller, control the third-party process to perform data operations matching the desired operation type in the programmable logic controller by calling the target operation function.
[0178] In one embodiment, the control module 904 is further configured to: parse the target operation function to determine data operation information matching the expected operation type; if the expected operation type is a write operation, call the application process to write first data to the data interaction channel according to the data operation information corresponding to the expected operation type, so that the third-party process can read the first data from the data interaction channel; if the expected operation type is a read operation, call the application process to read the second data written to the data interaction channel by the third-party process according to the data operation information corresponding to the expected operation type.
[0179] In one embodiment, the interface function further includes a program stop function; the control module 904 is further configured to: in response to a program stop event for the third-party program, control the third-party program to stop running in the programmable logic controller by calling the program stop function; and cancel the data interaction channel between the third-party process and the application process of the programmable logic controller.
[0180] In one embodiment, the control module 904 is further configured to: obtain a mapping relationship between the addresses of the input / output data areas in the programmable logic controller and preset processing commands; determine the mapping relationship as configuration information for the third-party program in the programmable logic controller; determine a target address matching the expected processing command of the third-party program based on the mapping relationship; the expected processing command includes at least one of a program start command, a program stop command, a write command, or a read command; and control the third-party program to perform an operation matching the processing command in the programmable logic controller by modifying the variable corresponding to the target address to be consistent with the preset variable corresponding to the expected processing command.
[0181] Each module in the programmable logic controller's program control device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in hardware or independent of the processor in a computer device, or stored in software in the computer device's memory, so that the processor can call and execute the operations corresponding to each module.
[0182] In one exemplary embodiment, a computer device is provided, which may be a server, and its internal structure diagram may be as follows: Figure 10 As shown, this computer device includes a processor, memory, input / output interfaces (I / O), and a communication interface. The processor, memory, and I / O interfaces are connected via a system bus, and the communication interface is also connected to the system bus via the I / O interfaces. The processor provides computational and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system, computer programs, and a database. The internal memory provides the environment for the operating system and computer programs stored in the non-volatile storage media. The database stores data such as third-party programs. The I / O interfaces are used for exchanging information between the processor and external devices. The communication interface is used for communication with external terminals via a network connection. When the computer program is executed by the processor, it implements a programmable logic controller (PLC) program control method.
[0183] Those skilled in the art will understand that Figure 10 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0184] In one embodiment, a computer device is also provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps in the above method embodiments.
[0185] In one embodiment, a computer-readable storage medium is provided having a computer program stored thereon that, when executed by a processor, implements the steps in the above method embodiments.
[0186] In one embodiment, a computer program product is provided, including a computer program that, when executed by a processor, implements the steps in the above method embodiments.
[0187] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of the relevant data must comply with relevant regulations.
[0188] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, artificial intelligence (AI) processors, etc., and are not limited to these.
[0189] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.
[0190] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of this patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this application should be determined by the appended claims.
Claims
1. A programmable logic controller (PLC) control method, characterized in that, include: Obtain third-party programs compiled using a compiler compatible with the programmable logic controller; Based on the configuration information for the third-party program in the programmable logic controller, the operation of the third-party program in the programmable logic controller is controlled; The method further includes: Obtain the interface functions encapsulated in the interface library, and determine the interface functions as the configuration information for the third-party program in the programmable logic controller; the interface functions include program startup functions and candidate operation functions corresponding to various candidate operation types; The step of controlling the execution of the third-party program within the programmable logic controller (PLC) based on the configuration information for the third-party program includes: By calling the program startup function, the third-party program is controlled to load into the programmable logic controller; From the candidate operation functions, determine the target operation function that matches the expected operation type of the third-party program; By invoking the target operation function, the third-party program is controlled to perform data operations in the programmable logic controller that match the desired operation type.
2. The method according to claim 1, characterized in that, The step of controlling the third-party program to perform data operations matching the desired operation type in the programmable logic controller by calling the target operation function includes: A third-party process corresponding to the third-party program is generated in the programmable logic controller. Based on the data interaction channel between the third-party process and the application process of the programmable logic controller, the third-party process is controlled to perform data operations matching the desired operation type in the programmable logic controller by calling the target operation function.
3. The method according to claim 2, characterized in that, The data interaction channel between the third-party process and the application process of the programmable logic controller (PLC) controls the third-party process to perform data operations matching the desired operation type in the PLC by calling the target operation function, including: Analyze the target operation function to determine the data operation information that matches the desired operation type; When the expected operation type is a write operation, the application process is invoked to write the first data to the data interaction channel according to the data operation information corresponding to the expected operation type, so that the third-party process can read the first data from the data interaction channel. When the expected operation type is a read operation, the application process is invoked to read out the second data written by the third-party process into the data interaction channel according to the data operation information corresponding to the expected operation type.
4. The method according to claim 2, characterized in that, The interface function also includes a program stop function; the method also includes: In response to a program stop event for the third-party program, the program stop function is invoked to control the third-party program to stop running in the programmable logic controller. Cancel the data interaction channel between the third-party process and the application process of the programmable logic controller.
5. The method according to claim 1, characterized in that, The method further includes: Obtain the mapping relationship between the addresses of the input / output data areas in the programmable logic controller and the preset processing commands, and determine the mapping relationship as the configuration information of the programmable logic controller for the third-party program; The step of controlling the execution of the third-party program within the programmable logic controller (PLC) based on the configuration information for the third-party program includes: Based on the mapping relationship, a target address matching the expected processing command of the third-party program is determined; the expected processing command includes at least one of the following: a program start command, a program stop command, a write command, or a read command; By modifying the variable corresponding to the target address to be consistent with the preset variable corresponding to the expected processing command, the third-party program is controlled to run an operation matching the processing command in the programmable logic controller.
6. A programmable logic controller (PLC) control device, characterized in that, The device includes: The acquisition module is used to acquire third-party programs compiled by a compiler that matches the programmable logic controller. The control module is used to control the operation of the third-party program in the programmable logic controller based on the configuration information for the third-party program in the programmable logic controller. The control module is further configured to obtain interface functions encapsulated in the interface library, and determine the interface functions as configuration information for the third-party program in the programmable logic controller (PLC). The interface functions include a program startup function and candidate operation functions corresponding to various candidate operation types. By calling the program startup function, the third-party program is controlled to load in the PLC. From the candidate operation functions, a target operation function matching the desired operation type of the third-party program is determined. By calling the target operation function, the third-party program is controlled to perform data operations matching the desired operation type in the PLC.
7. The apparatus according to claim 6, characterized in that, The control module is also used for: A third-party process corresponding to the third-party program is generated in the programmable logic controller. Based on the data interaction channel between the third-party process and the application process of the programmable logic controller, the third-party process is controlled to perform data operations matching the desired operation type in the programmable logic controller by calling the target operation function.
8. The apparatus according to claim 7, characterized in that, The control module is also used for: Analyze the target operation function to determine the data operation information that matches the desired operation type; When the expected operation type is a write operation, the application process is invoked to write the first data to the data interaction channel according to the data operation information corresponding to the expected operation type, so that the third-party process can read the first data from the data interaction channel. When the expected operation type is a read operation, the application process is invoked to read out the second data written by the third-party process into the data interaction channel according to the data operation information corresponding to the expected operation type.
9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 5.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 5.
Citation Information
Patent Citations
Method and device for the programming and configuration of programmable logic controller
CN103814333A
Compiler and programming assistance device
CN110720081A
Method and device for newly building PLC (Programmable Logic Controller) project
CN117785153A