Multi-task scheduling method and PLC controller
By adopting the multi-task scheduling method and the shared memory and semaphore mechanism between processes on the PLC controller, the problem that traditional PLC cannot realize multi-task parallel control is solved, and multi-task processing with high stability and data isolation is achieved.
Patent Information
- Application Number
- CN202510272315.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-07
- Publication Date
- 2025-06-13
AI Technical Summary
Traditional PLC controllers cannot effectively implement multi-task parallel control, resulting in poor data isolation, low stability and high data competition risks.
Using a multi-task scheduling method, it is distributed to different CPU cores on a single PLC controller by managing processes and worker processes, and data isolation and synchronous access is achieved using inter-process shared memory and semaphore mechanisms.
Complete data isolation between multitasking is achieved, the stability and security of multitasking is improved, and the difficulty of software development and user usage threshold is reduced.
Smart Images

Figure CN120144255A_ABST
Abstract
Description
Technical Field
[0001] This document relates to the technical field of data processing, and particularly to a multi-task scheduling method and a PLC controller. Background Art
[0002] A PLC (Programmable Logic Controller) is an operation controller based on a microprocessor and is widely used in the field of automation control. The working process of a PLC is mainly divided into three stages: input sampling, IEC operation (a program compliant with the standards of the International Electrotechnical Commission), and output refreshing. The process of completing these three stages is called a scan cycle. During operation, the PLC periodically executes the three stages at a fixed rate: in the input sampling stage, the PLC scans and reads all input states and data and stores them in the input data area. In the IEC operation stage, the PLC executes the user's IEC program and updates the operation results to the output data area. In the output refreshing stage, the PLC updates the values in the output data area to the corresponding peripherals.
[0003] With the increasing complexity of industrial production scales, the demand for parallel control of on-site logic control is also growing. The continuous progress of information technology has led to continuous improvements in the number of CPU cores on a microprocessor and the computing performance of a single CPU, while the proportion of CPU resources occupied by processes in the operating system has gradually decreased. Traditional PLCs adopt a single-task operation mode and can no longer meet the requirements of modern industries for the multi-task parallel control capabilities of PLCs. Summary of the Invention
[0004] Embodiments of this application provide a multi-task scheduling method and a PLC controller, which can implement parallel processing of multiple tasks on a single PLC controller and simultaneously improve the security of data isolation between multiple tasks and the stability of multi-task processing.
[0005] An embodiment of this application provides a multi-task scheduling method, which is applied to a PLC controller including multiple CPU cores and includes: The management process receives multi-task configuration information, starts one or more corresponding worker processes according to one or more tasks included in the multi-task configuration information, and assigns each started worker process to run on a different CPU core; Each worker process respectively receives the corresponding configuration information of this worker process, and loads the configuration information in this worker process to execute the corresponding task of this worker process; Among them, the CPU cores for running the management process and running the one or more worker processes are different.
[0006] In an exemplary embodiment, before the management process starts one or more corresponding worker processes, the method further includes: The management process creates an inter-process shared memory according to the multi-task configuration information; the inter-process shared memory is used to store global variables of the one or more worker processes; After the management process starts one or more corresponding worker processes, the method further includes: The management process configures interfaces for the one or more worker processes to access the inter-process shared memory respectively; The one or more worker processes access the global variables respectively through the interfaces for accessing the inter-process shared memory configured in their own worker processes.
[0007] In an exemplary embodiment, before the management process starts one or more corresponding worker processes, the method further includes: The management process creates an inter-process semaphore; The one or more worker processes access the global variables respectively through the interfaces for accessing the inter-process shared memory configured in their own worker processes, including: When the worker process needs to access the global variable, it applies for the inter-process semaphore; the operating system grants the inter-process semaphore to one worker process; The worker process that is granted the inter-process semaphore accesses the global variable through the interface for accessing the inter-process shared memory configured in its own worker process; after accessing the global variable, it releases the inter-process semaphore.
[0008] In an exemplary embodiment, the management process receives multi-task configuration information, and starts one or more corresponding worker processes according to one or more tasks included in the multi-task configuration information, including: After the management process receives the multi-task configuration information, it stores the multi-task configuration information in the PLC controller; wherein, the multi-task configuration information includes: the number of multi-tasks, and the worker processes bound to the specified industrial protocol; After the PLC controller restarts, the management process reads the multi-task configuration information stored in the PLC controller, and starts the corresponding number of worker processes according to the number of multi-tasks included in the read multi-task configuration information, and binds the worker processes to the industrial protocol; wherein, different types of industrial protocols are bound to different worker processes.
[0009] In an exemplary embodiment, after each worker process receives the corresponding configuration information of the worker process, and before loading the configuration information in the worker process to execute the corresponding task of the worker process, the method further includes: Each worker process determines whether the type of the industrial protocol to be run in the configuration information received by the worker process matches the type of the industrial protocol bound to the worker process; if not, the loading of the configuration information of the worker process is cancelled, and a first error message is reported.
[0010] In an exemplary embodiment, after each worker process receives the corresponding configuration information of the worker process, and before loading the configuration information in the worker process to execute the corresponding task of the worker process, the method further includes: Each worker process performs data verification on the configuration information received by the worker process; if the verification fails, the loading of the configuration information of the worker process is cancelled, and a second error message is reported.
[0011] In an exemplary embodiment, after the management process starts one or more corresponding worker processes, and before each worker process receives the corresponding configuration information of the worker process, the method further includes: The management process sends the identity identifier of the worker process to each of the one or more started worker processes according to the multi-task configuration information; the identity identifier is used to uniquely determine each worker process.
[0012] In an exemplary embodiment, each worker process receives the corresponding configuration information of the worker process, including: Each worker process receives the identity identifier from the management process, determines the listening port of the worker process according to the identity identifier, and receives the configuration information of the worker process from the upper computer through the listening port of the worker process.
[0013] In an exemplary embodiment, the method further includes: The management process periodically monitors the running status of each worker process; For a worker process that exits abnormally, the management process reports a first exception warning message and attempts to restart the worker process; if the worker process fails to be restarted continuously N times, the management process reports a second exception warning message; where N is an integer greater than 1.
[0014] In another embodiment of the present application, a PLC controller is provided, including a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the computer program, the steps of the above method are implemented.
[0015] The technical solution provided by the embodiments of this application can achieve parallel processing of multiple tasks on a single PLC controller, and at the same time improve the security of data isolation between multiple tasks and the stability of multi-task processing.
[0016] Other features and advantages of this application will be described in the subsequent specification, and, in part, will become apparent from the specification, or will be understood by implementing this application. Other advantages of this application can be realized and obtained through the solutions described in the specification and the drawings. Brief Description of the Drawings
[0017] The drawings are used to provide an understanding of the technical solution of this application, and constitute a part of the specification. Together with the embodiments of this application, they are used to explain the technical solution of this application, and do not constitute a limitation to the technical solution of this application.
[0018] Figure 1 It is a schematic flowchart of a multi-task scheduling method and a PLC controller method provided by the embodiments of this application; Figure 2 It is a schematic diagram of the binding relationship between multiple processes and CPU cores provided by the embodiments of this application; Figure 3 It is a schematic flowchart of a working process accessing global variables provided by the embodiments of this application; Figure 4 It is a schematic flowchart of a management process processing multi-task configuration information provided by the embodiments of this application; Figure 5 It is a schematic illustration of the binding of a working process to an industrial protocol provided by the embodiments of this application; Figure 6 It is a schematic flowchart of a management process monitoring the running status of a working process provided by the embodiments of this application; Figure 7 It is a schematic diagram of the structure of a PLC controller provided by the embodiments of this application. Detailed Description of the Embodiments
[0019] This application describes multiple embodiments, but the description is exemplary, not restrictive, and it is obvious to those of ordinary skill in the art that there can be more embodiments and implementation solutions within the scope of the embodiments described in this application. Although many possible feature combinations are shown in the drawings and discussed in the detailed description, many other combination ways of the disclosed features are also possible. Unless specifically restricted, any feature or element of any embodiment can be combined with any other feature or element in any other embodiment, or can replace any other feature or element in any other embodiment.
[0020] This application includes and contemplates combinations of features and elements known to those of ordinary skill in the art. The disclosed embodiments, features, and elements of this application can also be combined with any conventional features or elements to form unique inventive solutions. Any feature or element of any embodiment can also be combined with features or elements from other inventive solutions to form another unique inventive solution. Therefore, it should be understood that any feature shown and / or discussed in this application can be implemented alone or in any suitable combination. Therefore, the embodiments are not subject to other limitations except those made in accordance with the appended claims and their equivalents. In addition, various modifications and changes can be made within the scope of the appended claims.
[0021] In addition, when describing representative embodiments, the specification may have presented the method and / or process as a specific sequence of steps. However, to the extent that the method or process does not depend on the specific order of the steps described herein, the method or process should not be limited to the specific order of steps described. As will be understood by those of ordinary skill in the art, other step sequences are possible. Therefore, the specific order of steps set forth in the specification should not be construed as a limitation on the claims. In addition, the claims directed to the method and / or process should not be limited to performing their steps in the order written, as those skilled in the art can readily understand that these orders can vary and still remain within the spirit and scope of the embodiments of this application.
[0022] Traditional PLC controllers do not have the ability of multi-task parallel processing. For scenarios that require multi-task parallel control, traditional PLC controllers usually need to construct a complex and cumbersome IEC project during the process of single-task periodic execution inside the PLC, and use a loop counting mechanism to trigger specific tasks when meeting pre-set specific conditions to simulate the effect of multi-task execution.
[0023] In another type of PLC multi-task execution simulation solution, the core method is to initiate multiple threads in a single process, bind each thread to an IEC task, and perform loop operations of input sampling, IEC operation, and output refreshing respectively in the threads of each IEC task, so as to achieve PLC multi-task control based on the method of single process and multi-threads. In this solution, the multiple IEC threads can be scheduled in a preemptive priority manner or in a round-robin manner.
[0024] The above solutions for simulating multi-task parallel processing in PLC controllers have the following defects: 1. For traditional PLC controllers that do not have multi-task processing capabilities, although the method of loop counting can be used to simulate the execution of specific functions in multi-tasks, this method has problems such as cumbersome configuration, high error rate, and difficulty in ensuring task real-time performance.
[0025] 2. The PLC simulation multi-task control solution implemented by single-process and multi-thread technology still has three difficult problems to solve: 1). The data areas between multiple tasks cannot be completely isolated. Since each task runs in different threads of the same process, the data area in the PLC, as a global variable, can be read and written by the threads of all tasks. Once a variable exception or out-of-bounds access occurs in a certain task, it is very likely to access the data areas of other tasks, thus affecting the logical execution of other tasks.
[0026] 2). Successful multi-task scheduling depends on the stability of each individual task. For example, in the scenario of preemptive scheduling, if a high-priority task has an exception and occupies the CPU resources without releasing them, the low-priority tasks will not be able to run properly. Another example is that once a single task (i.e., a thread) crashes during operation (such as events like illegal address access, memory leak, illegal handle operation, etc.), it will cause the entire process to crash, directly resulting in the abnormal stop of the tasks running on other threads.
[0027] 3). When multiple tasks access global variables simultaneously, there is a risk of data competition. For example, when one task is reading a certain data and another task is trying to write to the same data, it may lead to incorrect reading of the data or reading an incomplete value; another example is that when multiple tasks write to the same variable simultaneously, it may cause one task to overwrite the modification results of other tasks, thus destroying data consistency.
[0028] For the above reasons, the software logic implementation of the current PLC controller that supports simulating the execution of multiple tasks has a high complexity and is usually accompanied by many usage restrictions. This not only increases the development cost of PLC software but also significantly raises the usage threshold for users. This application proposes a multi-task scheduling method for a PLC controller in view of the deficiencies of traditional PLC controllers.
[0029] Figure 1 The flowchart of a multi-task scheduling method provided by an embodiment of this application is shown. The method is applied to a PLC controller with multiple CPU cores, as Figure 1 shown, and the method includes: Step 100: The management process receives multi-task configuration information, and according to one or more tasks included in the multi-task configuration information, starts the corresponding one or more worker processes, and assigns each started worker process to run on a different CPU core; Step 101: Each worker process respectively receives the corresponding configuration configuration information of this worker process, and loads the configuration configuration information in this worker process to execute the corresponding task of this worker process; In this embodiment, the CPU cores for running the management process and the one or more worker processes are different. This application is designed based on a PLC controller with a multi-core processor (N CPUs, where N > 2), and it can utilize multi-process to achieve the function of multi-task parallel processing in a single PLC device.
[0030] In this embodiment, a management process and one or more worker processes are run in the PLC controller. Among them, the management process is mainly responsible for receiving the multi-task configuration information issued by the user. The user can send the multi-task configuration information to the PLC management process through the upper computer configuration software. The management process starts the corresponding one or more worker processes according to the multi-task configuration information. The worker processes are used to truly implement the multi-task processing function of the PLC. Multiple worker processes are allocated to different CPU cores to run in parallel, thus realizing the function of PLC multi-task parallel control.
[0031] The management process is the first process initiated after the PLC is powered on, and this process occupies one CPU exclusively. The worker process is the process that truly implements the PLC task function. Each PLC worker process is responsible for executing one task. By executing different tasks in multiple PLC worker processes respectively, each PLC worker process occupies one CPU exclusively, realizing the function of multi-task parallel processing of the PLC controller.
[0032] As Figure 2 shown, in this embodiment, the management process occupies CPU0 exclusively. If the multi-task configuration information of the user includes M tasks, then after the PLC management process completes its own initialization, it will initiate M worker processes respectively and bind each worker process to the idle CPU cores. At this time, the cores from CPU_M + 1 to CPU_N - 1 in the system are in the idle state. It should be noted that M is a positive integer with a maximum value of N - 1 to ensure that each PLC worker process can occupy an idle CPU core exclusively. In addition, for the sake of illustration, in this embodiment, worker process 1 is bound to CPU1, and worker process 2 is bound to CPU2. The numbers of the PLC worker processes and the CPU cores are synchronized and corresponding. In fact, there is no need to follow any specific rule between the numbers of the worker processes and the CPU cores. The key is to ensure that each PLC worker process can be bound to an idle CPU core.
[0033] Compared with the process control method of traditional PLC controllers, the multi-task scheduling method proposed in this embodiment, based on a multi-core CPU, realizes the multi-task parallel control of the PLC and has the following advantages at the same time: 1) The data areas between multiple tasks can be completely isolated from each other without interference: Each task is an independent process running on a different CPU core, and no task can access the data areas of other tasks. Even if a variable access exception occurs in a certain task, it will not affect the logical execution of other tasks, improving the security of data isolation between multiple tasks.
[0034] 2) The robustness of multi-task scheduling no longer depends on the stability of the execution of a single task: Since this embodiment adopts the method of starting multiple processes to run different tasks respectively, each process is bound to a different CPU, and there is no scenario where multiple PLC working processes compete for the same CPU resources. In principle, the possibility of high-priority tasks preempting the CPU of low-priority tasks is avoided, and even if a single task crashes during operation, it has no impact on the operation of other tasks. Since each PLC working process is independently executed, even if a task runs abnormally and triggers a crash (such as illegal address access, memory leak, illegal handle operation, etc.), it will not affect the normal operation of other tasks running on other processes, thus improving the stability of multi-task processing of the PLC controller.
[0035] Through the multi-task scheduling method proposed in this embodiment, it is only necessary to ensure the stable operation of a single PLC working process, thus avoiding the complex mutual influence relationship between different threads when a single process executes multiple tasks in the traditional simulated multi-task processing mode. In addition, in this embodiment, users do not need to worry about the restrictions of the cumbersome configuration software required for PLC design in the traditional single-process multi-task mode. By running different task processes on multiple CPU cores respectively, the multi-task parallel control function can be more conveniently implemented, while ensuring the secure isolation of data between different tasks, significantly reducing the software development difficulty and the user usage threshold.
[0036] In an exemplary embodiment, before the management process starts one or more corresponding working processes, the method further includes: The management process creates an inter-process shared memory according to the multi-task configuration information; the inter-process shared memory is used to store the global variables of the one or more working processes; After the management process starts one or more corresponding working processes, the method further includes: The management process configures interfaces for the one or more working processes to access the inter-process shared memory respectively; The one or more working processes access the global variables respectively through the interfaces for accessing the inter-process shared memory configured in this working process.
[0037] In this embodiment, after the management process of the PLC completes the initialization of the basic functions of the PLC, such as hardware initialization, self-check, version information initialization, network interface initialization, watchdog initialization, etc., it creates an inter-process shared memory to store the global variables of the multiple working processes. The multiple working processes can all access the inter-process shared memory. In addition, the management process of the PLC is also responsible for configuring an interface for accessing the inter-process shared memory in each working process of the PLC, thereby realizing the access function of the multiple working processes to the global variables.
[0038] In an exemplary embodiment, before the management process starts one or more corresponding working processes, the method further includes: The management process creates an inter-process semaphore; The one or more working processes respectively access the global variables through the interfaces configured in their own working processes for accessing the inter-process shared memory, including: When the working process needs to access the global variables, it applies for the inter-process semaphore; the operating system grants the inter-process semaphore to one working process; The working process granted the inter-process semaphore accesses the global variables through the interface configured in its own working process for accessing the inter-process shared memory; after accessing the global variables, it releases the inter-process semaphore.
[0039] In this embodiment, the inter-process semaphore is used to control the orderly access of multiple working processes to the global variables, so as to avoid the problem that the data in the inter-process shared memory may be inconsistent when multiple working processes access the global variables simultaneously. The management process and the working processes run in the operating system. Among them, the management process is responsible for creating the inter-process semaphore, and each working process applies for the inter-process semaphore from the operating system to access the inter-process shared memory, and the operating system is responsible for scheduling the inter-process semaphore among the working processes.
[0040] Each working process of the PLC may access the global variables when performing tasks. In this embodiment, the inter-process semaphore is used to control the access to the global variables to ensure that the access to critical region resources such as global variables is synchronous and mutually exclusive.
[0041] When the working process of the PLC accesses its own internal data area (such as the input data area, output data area, diagnostic data area, etc.), it does not need to obtain a semaphore. When the working process of the PLC needs to access the global variables, it needs to apply for the inter-process semaphore first. Only the working process granted the semaphore by the operating system can access the global variables. The working process needs to immediately release the semaphore after accessing the global variables to ensure that other subsequent working processes can normally obtain the semaphore to access the global variables. The specific processing process is as follows: 1. After the management process initialization is completed, before starting one or more corresponding worker processes, call the semaphore creation function of the operating system to create an inter-process semaphore in the operating system. 2. After the initialization of each worker process is completed, call the inter-process semaphore opening function of the operating system to open the inter-process semaphore created by the management process, so that each worker process can apply for the inter-process semaphore when it needs to access the inter-process shared memory subsequently. 3. Taking the access of worker process 1 and worker process 2 to the inter-process shared memory as an example, when worker process 1 needs to access the inter-process shared memory, call the inter-process semaphore application function of the operating system and wait for the operating system to grant the inter-process semaphore to this worker process 1; after worker process 1 obtains the inter-process semaphore granted by the operating system, it can access the global variable in the inter-process shared memory; (at this time, if worker process 2 calls the inter-process semaphore application function of the operating system, the operating system will not grant the inter-process semaphore to worker process 2, and worker process 2 will join the application queue in the operating system until worker process 1 releases the inter-process semaphore to the operating system, and then the operating system can grant the inter-process semaphore to worker process 2).
[0042] 4. After worker process 1 finishes accessing the shared memory, call the inter-process semaphore release function of the operating system to release the inter-process semaphore to the operating system; then the operating system will wake up the next worker process in the application queue and grant the inter-process semaphore.
[0043] In an exemplary embodiment, as Figure 3 shown, the initial value of the inter-process semaphore is set to 1, indicating that at most only 1 worker process of the PLC is allowed to read and write the global variable at a time. If multiple worker processes need to read and write the global variable simultaneously, each process needs to first join the queue for applying for the inter-process semaphore, and the operating system will schedule and grant the semaphore to one of the worker processes. After the worker process finishes reading and writing the global variable, it releases the inter-process semaphore. After the operating system reclaims the released inter-process semaphore, it grants the semaphore to another process in the application queue.
[0044] In this embodiment, the protection of the orderly access of multiple task worker processes to the global variable is realized through the inter-process semaphore mechanism, effectively avoiding the risk of data competition between processes, and ensuring the security and smoothness of the global variable interaction between multiple tasks.
[0045] In an exemplary embodiment, the management process receives multi-task configuration information and starts one or more corresponding worker processes according to one or more tasks included in the multi-task configuration information, including: After receiving the multitask configuration information, the management process stores the multitask configuration information in the PLC controller; wherein, the multitask configuration information includes: the number of multitasks, and the working processes bound to the specified industrial protocols. After the PLC controller restarts, the management process reads the multitask configuration information stored in the PLC controller, and according to the number of multitasks included in the read multitask configuration information, starts the corresponding number of working processes, and binds the working processes to the industrial protocols; wherein, different types of industrial protocols are bound to different working processes.
[0046] In this embodiment, as Figure 5 shown, the user can send multitask configuration information to the management process of the PLC through the upper computer configuration software. The multitask configuration information may include parameters such as the number of multitasks, the size of the global variable area, and the working processes bound to the specified industrial protocols.
[0047] After the management process receives the multitask configuration information sent by the user, it stores the multitask configuration information in the PLC controller in the form of a configuration file. After the user confirms that the setting is completed and restarts the PLC device, the management process will configure the corresponding working processes according to the multitask configuration information stored in the PLC controller. The specific process is as Figure 4 shown, including: Step 400: Start the management process; Step 401: The management process completes initialization and starts the corresponding working processes according to the historical multitask configuration information; Step 402: The management process runs its own periodic function; Step 403: The management process periodically queries whether it has received new multitask configuration information sent by the upper computer; if it has received, it executes Step 404; if it has not received, it returns to Step 402; Step 404: The management process parses the received multitask configuration information and stores it in the PLC controller; Step 405: The management process stops all working processes and then restarts the PLC controller.
[0048] In a single PLC device, the user needs to bind different types of industrial protocols to the corresponding working processes to avoid conflicts caused by multiple PLC working processes running the same industrial protocol simultaneously (such as port number conflicts of industrial Ethernet, external protocol device management conflicts, etc.).
[0049] In an exemplary embodiment, after each working process receives the corresponding configuration information of the working process, and before loading the configuration information in the working process to execute the corresponding task of the working process, the method further includes: Each worker process respectively determines whether the type of the industrial protocol to be run in the configuration information received by the worker process matches the type of the industrial protocol bound to the worker process; if not, the configuration information of the worker process is cancelled from being loaded, and a first error message is reported.
[0050] In this embodiment, after the worker process of each PLC receives the configuration information of the user, it checks whether the type of the industrial protocol to be run in the configuration information matches the type of the protocol bound to the worker process configured by the user. If not, a first error message is reported and the configuration information is not loaded. If it matches, the configuration information is loaded and run to execute the corresponding task of the worker process.
[0051] In an exemplary embodiment, after each worker process respectively receives the corresponding configuration information of the worker process, and before the configuration information is loaded in the worker process to execute the corresponding task of the worker process, the method further includes: Each worker process respectively performs data verification on the configuration information received by the worker process; if the verification fails, the configuration information of the worker process is cancelled from being loaded, and a second error message is reported.
[0052] In an exemplary embodiment, after the management process starts one or more corresponding worker processes, and before each worker process respectively receives the corresponding configuration information of the worker process, the method further includes: The management process respectively sends the identity identifier of the worker process to the one or more started worker processes according to the multi-task configuration information; the identity identifier is used to uniquely determine each worker process.
[0053] In an exemplary embodiment, each worker process respectively receiving the corresponding configuration information of the worker process includes: Each worker process respectively receives the identity identifier from the management process, determines the listening port of the worker process according to the identity identifier, and receives the configuration information of the worker process from the upper computer through the listening port of the worker process.
[0054] In this embodiment, after the working process of each PLC completes the basic software initialization (such as communication server listening, configuration project loading, IEC task management, industrial protocol initialization, etc.), according to the received identity identifier, it determines the port number to be listened to, and creates a corresponding working directory to wait for the upper computer to download the configuration information. When the working process listens to the download request from the upper computer at the determined port number, it responds to the download request from the upper computer and receives the downloaded configuration information. After the downloaded configuration information is verified, it stores the configuration information and loads it into the working process to run the corresponding tasks of the working process.
[0055] Taking the example of configuring M working processes in a PLC, the process of configuring industrial protocols is described as follows. As Figure 5 shown, the various processes of the PLC share the same network interface and are connected to one or more upper computers through a switch. The working processes of each PLC listen to different port numbers respectively, waiting for the upper computer configuration software to download their respective configuration information through the corresponding port numbers. Once the configuration information download is completed and the configuration information is verified to be correct, the working process loads and runs the configuration information.
[0056] In Figure 5 the shown embodiment, working processes 1, 2, and M listen to ports 10001, 10002, and 10000 + M respectively. The user configures the ModbusTCP slave protocol to run in working process 1 of the PLC, the Profibus-DP master protocol 1 to run in working process 2, and the EtherNet / IP slave protocol to run in working process M.
[0057] Since specific industrial protocols need to occupy specific resources. For example, the ModbusTCP slave protocol will listen to TCP port 502, and the EtherNet / IP protocol will listen to UDP port 44818 and TCP port 2222. If the same protocol is run on multiple PLC working processes and listens to the same port, it will cause resource conflicts and affect the operation of the protocol. For the Profibus-DP master protocol instance, although it does not use network port numbers, to ensure the stability of protocol control, it can only be run by one PLC working process. Therefore, the above industrial protocols need to be configured by the PLC management process before the configuration information is downloaded to ensure that these industrial protocols will not be run repeatedly on multiple PLC working processes.
[0058] It should be noted that Figure 5 the port numbers 10001 to 10000 + M listed in
[0059] are only examples for illustration, and any suitable port numbers can be configured for the working processes in the actual environment. The management process periodically monitors the running status of each worker process. For a worker process that exits abnormally, the management process reports the first abnormal alarm information and attempts to restart the worker process. If the worker process fails to restart continuously for N times, where N is an integer greater than 1, the management process reports the second abnormal alarm information.
[0060] In this embodiment, the management process of the PLC periodically monitors the running status of each worker process of the PLC. Once it is found that a certain PLC worker process exits abnormally, an abnormal alarm is reported and an attempt is made to restart the worker process again. Once the abnormally exited worker process fails to restart three times in a row, it indicates that a serious fault has occurred, and the PLC management process will report a serious error. In addition, the PLC management process also monitors the CPU, memory, disk occupancy of the PLC device, and basic running status such as PLC temperature and RTC battery voltage, and reports an alarm once an abnormality occurs.
[0061] In an exemplary embodiment, the processing flow of the management process for monitoring the worker process is as Figure 6 shown, including: Step 600: The management process monitors the basic running status of the PLC. Step 601: The management process checks the running status of worker processes 1 - M. Step 602: Determine whether the worker process is running abnormally. If it is normal, execute Step 603; if it is abnormal, execute Step 604. Step 603: The management process checks the running status of the next worker process. Step 604: The management process reports the first abnormal alarm information and attempts to restart the worker process. Step 605: Determine whether the number of times the abnormal worker process has been restarted is >= 3. If so, execute Step 606; if not, execute Step 603. Step 606: The management process reports the second abnormal alarm information. Step 607: Determine whether all M worker processes have been checked. If so, execute Step 600; if not, execute Step 601.
[0062] Figure 7 A PLC controller provided by an embodiment of the present application is shown, including a memory 700, a processor 701, and a computer program stored on the memory and executable on the processor. When the processor 701 executes the computer program, the steps of the above - described method are implemented.
[0063] Those of ordinary skill in the art will understand that all or some of the steps in the methods disclosed above, and the functional modules / units in systems and devices, can be implemented as software, firmware, hardware, and appropriate combinations thereof. In the hardware implementation, the division of functional modules / units mentioned above does not necessarily correspond to the division of physical components; for example, one physical component may have multiple functions, or one function or step may be executed by several physical components in cooperation. Some or all components may be implemented as software executed by a processor, such as a digital signal processor or a microprocessor, or implemented as hardware, or implemented as an integrated circuit, such as an application-specific integrated circuit. Such software can be distributed on a computer-readable medium, which can include a computer storage medium (or non-transitory medium) and a communication medium (or transitory medium). As is well known to those of ordinary skill in the art, the term "computer storage medium" includes volatile and non-volatile, removable and non-removable media implemented in any method or technology for storing information, such as computer-readable instructions, data structures, program modules, or other data. Computer storage media includes, but is not limited to, RAM, ROM, EEPROM, flash memory or other memory technologies, CD-ROM, digital versatile disk (DVD) or other optical disk storage, magnetic cassettes, tapes, magnetic disk storage or other magnetic storage devices, or any other medium that can be used to store the desired information and can be accessed by a computer. In addition, it is well known to those of ordinary skill in the art that a communication medium typically contains computer-readable instructions, data structures, program modules, or other data in a modulated data signal such as a carrier wave or other transmission mechanism, and can include any information delivery medium.
Claims
1. A multi-task scheduling method, characterized in that: Applicable to PLC controllers with multiple CPU cores, including: The management process receives the multi-task configuration information, starts one or more corresponding working processes according to one or more tasks included in the multi-task configuration information, and allocates each started working process to run on a different CPU core; Each work process receives the configuration information corresponding to the work process respectively, and loads the configuration information into the work process to execute the task corresponding to the work process; The CPU cores for running the management process and the CPU cores for running the one or more working processes are different.
2. The multi-task scheduling method according to claim 1, characterized in that: Before the management process starts the corresponding one or more work processes, the method further includes: The management process creates an inter-process shared memory according to the multi-task configuration information; the inter-process shared memory is used to store global variables of the one or more working processes; After the management process starts the corresponding one or more working processes, the method further includes: The management process configures an interface for accessing the inter-process shared memory for the one or more working processes respectively; The one or more working processes access the global variable respectively through the interface for accessing the inter-process shared memory configured in the working process.
3. The multi-task scheduling method according to claim 2, characterized in that: Before the management process starts the corresponding one or more work processes, the method further includes: The management process creates an inter-process semaphore; The one or more working processes access the global variable respectively through the interface for accessing the inter-process shared memory configured in the working process, including: When the working process is about to access the global variable, it applies for the inter-process semaphore; the operating system grants the inter-process semaphore to a working process; The working process that is granted the inter-process semaphore accesses the global variable through the interface for accessing the inter-process shared memory configured in the working process; after completing the access to the global variable, the inter-process semaphore is released.
4. The multi-task scheduling method according to claim 1, characterized in that: The management process receives the multi-task configuration information, and starts one or more corresponding working processes according to one or more tasks included in the multi-task configuration information, including: After receiving the multi-task configuration information, the management process stores the multi-task configuration information in the PLC controller; wherein the multi-task configuration information includes: the number of multi-tasks and the working process bound to the specified industrial protocol; After the PLC controller is restarted, the management process reads the multi-task configuration information stored in the PLC controller, and starts a corresponding number of working processes according to the number of multi-tasks contained in the read multi-task configuration information, and binds the working processes to the industrial protocols; wherein different types of industrial protocols are bound to different working processes.
5. The multi-task scheduling method according to claim 1, characterized in that: After each work process receives the configuration information corresponding to the work process, and before loading the configuration information in the work process to execute the task corresponding to the work process, the method further includes: Each working process determines whether the type of industrial protocol to be run in the configuration information received by the working process matches the type of industrial protocol bound to the working process; if not, the configuration information of the working process is unloaded and the first error message is reported.
6. The multi-task scheduling method according to claim 5, characterized in that: After each work process receives the configuration information corresponding to the work process, and before loading the configuration information in the work process to execute the task corresponding to the work process, the method further includes: Each working process performs data verification on the configuration information received by the working process respectively; if the verification fails, the configuration information of the working process is unloaded and the second error information is reported.
7. The multi-task scheduling method according to claim 1, characterized in that: After the management process starts one or more corresponding working processes, and before each working process receives the configuration information corresponding to the working process, the method further includes: The management process sends the identity of the work process to the started one or more work processes respectively according to the multi-task configuration information; the identity is used to uniquely identify each work process.
8. The multi-task scheduling method according to claim 7, characterized in that: Each work process receives configuration information corresponding to the work process, including: Each working process receives an identity from the management process, determines a listening port of the working process according to the identity, and receives configuration information of the working process from the host computer through the listening port of the working process.
9. The multi-task scheduling method according to any one of claims 1 to 8, characterized in that: The method further comprises: The management process periodically monitors the running status of each working process; For a work process that exits abnormally, the management process reports a first abnormal alarm message and attempts to restart the work process; if the work process fails to be restarted N times in a row, the management process reports a second abnormal alarm message; wherein N is an integer greater than 1.
10. A PLC controller, characterized in that: The method comprises a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the method according to any one of claims 1 to 9 when executing the computer program.