Data Synchronization Method, Device, Storage Medium and Electronic Device of a Controller

By dividing the controller data into global and task variables and synchronizing in stages, the synchronization in the existing technology is solved, and efficient data transmission is achieved and the impact on the controller's performance is reduced.

CN118151517BActive Publication Date: 2025-07-22NR ELECTRIC CO LTD +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202410112724.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-01-25
Publication Date
2025-07-22
Estimated Expiration
2044-01-25

AI Technical Summary

Technical Problem

The existing controller synchronization method synchronizes all data in the initial level task, which takes up time to occupy high-priority tasks, has high network bandwidth requirements, is costly, and has limited data volume.

Method used

The data to be synchronized is divided into global variable data and task variable data, and synchronizes it in stages. First, synchronize the global variable data, and then synchronize the task variable data in the task process. Use the virtual function table storage location to skip to avoid overwriting the virtual function table from the controller.

Benefits of technology

It reduces the impact of the data synchronization process on the controller's execution thread, reduces the time of high-priority tasks, and reduces the network interface bandwidth requirements and overall cost.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118151517B_ABST
    Figure CN118151517B_ABST
Patent Text Reader

Abstract

The present application provides a data synchronization method, device, storage medium and electronic device for a controller, which relates to the technical field of industrial control. The data synchronization method for the controller provided by the present application includes: dividing the data to be synchronized into global variable data and task variable data; in the global variable synchronization stage, obtaining the global variable data and performing the synchronization of the global variable data; in the task variable synchronization stage, obtaining the task variable data and performing the synchronization of the task variable data. The present application reduces the impact of the synchronization process on the task execution process of the initial state controller and reduces the synchronization cost of the master-slave controller structure.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of industrial control technology, and particularly relates to a data synchronization method, device, storage medium, and electronic device for a controller. Background Art

[0002] Industrial applications have relatively high requirements for the stability and reliability of controllers. Generally, a dual-master-slave redundant configuration is used to ensure the maximum availability of the controller. The use of hot standby redundancy technology is mainly to improve the fault tolerance of the controller. Both the working controller and the standby controller perform self-diagnosis and mutual diagnosis. When the working controller fails and the standby controller is normal, the master-slave relationship is automatically switched. To avoid / reduce the disturbance to the controlled object, it is required that the switching time be as short as possible, which requires high data synchronization efficiency.

[0003] Currently, in the existing controller synchronization methods, usually when the main program is running, all the data of the controller is synchronized first in the initial highest-level task, which takes a long time for high-priority tasks. Moreover, for application programs with a large amount of synchronized data, there are also requirements for the network interface bandwidth, with high costs and limited amounts of synchronized data that can be transmitted. Summary of the Invention

[0004] This application aims to provide a data synchronization method, device, storage medium, and electronic device for a controller, which can reduce the bandwidth requirements and costs in the synchronization process of the master-slave controllers.

[0005] According to the first aspect of this application, a data synchronization method for a controller is provided, including:

[0006] Dividing the data to be synchronized into global variable data and task variable data;

[0007] In the global variable synchronization stage, obtaining the global variable data and synchronizing the global variable data;

[0008] In the task variable synchronization stage, obtaining the task variable data and synchronizing the task variable data.

[0009] In some embodiments, in the task variable synchronization stage, obtaining the task variable data and synchronizing the task variable data includes:

[0010] Determining a first target storage area corresponding to the task variable data; wherein, the first target storage area is the storage area after the synchronization of the task variable data;

[0011] When there is a first virtual function table in the first target storage area, determining a second target storage location of the task variable data according to the first target storage location of the first virtual function table;

[0012] Store the task variable data according to the second target storage location.

[0013] In some embodiments, it further includes:

[0014] According to the synchronization process of the task variable data, divide the task variable synchronization stage into a task data synchronization stage and a program data synchronization stage;

[0015] According to the division of the task variable synchronization stage, divide the task variable data into first variable data and second variable data; wherein, the first variable data is the variable data of the task process, and the second variable data is the variable data of the object program in the task process;

[0016] In the task data synchronization stage, obtain the first variable data and perform the synchronization of the first variable data;

[0017] In the program data synchronization stage, obtain the second variable data and perform the synchronization of the second variable data.

[0018] In some embodiments, in the program data synchronization stage, obtaining the second variable data and performing the synchronization of the second variable data includes:

[0019] Determine the second target storage area of the task variable data, and the second target storage area is the storage area after the synchronization of the second variable data;

[0020] When there is a second virtual function table in the second target storage area, determine the fourth target storage location of the second variable data according to the third target storage location of the second virtual function table;

[0021] Store the second variable data according to the fourth target storage location.

[0022] In some embodiments, in the global variable synchronization stage, obtaining the global variable data and performing the synchronization of the global variable data includes:

[0023] Determine the third target storage area of the global variable data; wherein, the third target storage area is the storage area after the synchronization of the global variable data;

[0024] When there is a third virtual function table in the third target storage area, determine the sixth target storage location of the global variable data according to the fifth target storage location of the third virtual function table;

[0025] Store the global variable data according to the sixth target storage location.

[0026] In some embodiments, the global variable data includes data of the file to be executed, configuration file data, and memory information table, and the controller includes a main controller and at least one slave controller; in the global variable synchronization stage, obtaining the global variable data and performing the synchronization of the global variable data includes:

[0027] When the controller is powered on, obtain the data of the file to be executed, the configuration file data, and the memory information table of the main controller;

[0028] Synchronously store the data of the file to be executed, the configuration file data, and the memory information table in the storage area corresponding to each slave controller;

[0029] Among them, the data of the file to be executed is the file data corresponding to the main program to be executed by the main controller, the configuration file data is the relevant file data of the configuration parameters of the main controller, and the memory information table includes the storage information of all variable data that the main controller needs to call.

[0030] According to the data synchronization method provided in the first aspect, during the operation of the main controller, synchronization can be performed based on the variable data required for the current execution step, without synchronizing all variable data when the main controller starts to execute, effectively reducing the impact of the data synchronization process on the controller execution thread. Moreover, during the storage process of the synchronized data by the slave controller, the virtual function table can be detected, and the synchronized data can be stored based on the virtual function table, effectively avoiding the synchronized data from overwriting the relevant data of the virtual function in the slave controller, and thus effectively avoiding reducing the processing performance of the slave controller.

[0031] According to the second aspect of the present application, a data synchronization method for a controller is provided, including:

[0032] Obtain global variable data and store the global variable data in the system cache;

[0033] Send a global variable synchronization instruction to the slave controller; wherein, the global variable synchronization instruction is used to instruct the slave controller to obtain the global variable data from the system cache;

[0034] Obtain task variable data and store the task variable data in the system cache;

[0035] Send a task variable synchronization instruction to the slave controller; wherein, the task variable synchronization instruction is used to instruct the slave controller to obtain the task variable data from the system cache.

[0036] In some embodiments, the global variable data includes the data of the file to be executed, the configuration file data, and the memory information table; the obtaining the global variable data and storing the global variable data in the system cache includes:

[0037] Obtain the data of the file to be executed, the configuration file data, and the memory information table;

[0038] Synchronously store the data of the file to be executed, the configuration file data, and the memory information table in the system cache;

[0039] Among them, the data of the file to be executed is the file data corresponding to the main program to be executed by the main controller, the data of the configuration file is the relevant file data of the configuration parameters of the main controller, and the memory information table includes the storage information of all variable data that the main controller needs to call.

[0040] In some embodiments, after sending the task variable synchronization instruction to the slave controller, it further includes:

[0041] Obtain program variable data and store the program variable data in the system cache;

[0042] Send a program variable synchronization instruction to the slave controller; wherein, the program variable synchronization instruction is used to instruct the slave controller to obtain the program variable data from the system cache.

[0043] Through the second aspect of the present application, when performing data synchronization, data synchronization can be carried out in their respective corresponding stages based on different stages such as global, task process, and program process, without centralized data synchronization, effectively reducing the impact of the data synchronization process on the controller execution thread.

[0044] According to the third aspect of the present application, a data synchronization method for a controller is provided, including:

[0045] Receive a global variable synchronization instruction sent by the main controller;

[0046] Obtain global variable data from the system cache and store the global variable data in the first storage area; wherein, the first storage area is the designated storage area for the global variable;

[0047] Receive the task variable synchronization instruction sent by the main controller;

[0048] Obtain task variable data from the system cache and store the task variable data in the second storage area; wherein, the second storage area is the designated storage area for the task variable data.

[0049] In some embodiments, obtaining the task variable data from the system cache and storing the task variable data in the second storage area includes:

[0050] When there is a fourth virtual function table in the second storage area, obtain the seventh target storage location of the fourth virtual function table;

[0051] Determine the eighth target storage location of the task variable data according to the seventh target storage location;

[0052] Store the task variable data according to the eighth target storage location.

[0053] In some embodiments, it further includes:

[0054] Receive the program variable synchronization instruction sent by the master controller;

[0055] Obtain program variable data from the system cache and store the program variable data in a third storage area; wherein, the third storage area is a specified storage area in the second storage area for storing the program variable data.

[0056] In some embodiments, the obtaining program variable data from the system cache and storing the program variable data in a third storage area includes:

[0057] When there is a fifth virtual function table in the third storage area, obtain the ninth target storage location of the fifth virtual function table;

[0058] Determine the tenth target storage location of the program variable data according to the ninth target storage location;

[0059] Store the program variable data according to the tenth target storage location.

[0060] In some embodiments, the obtaining global variable data from the system cache and storing the global variable data in a first storage area includes:

[0061] When there is a sixth virtual function table in the first storage area, obtain the eleventh target storage location of the sixth virtual function table;

[0062] Determine the twelfth target storage location of the global variable data according to the eleventh target storage location;

[0063] Store the global variable data according to the twelfth target storage location.

[0064] In some embodiments, the global variable data includes data of an executable file to be executed, configuration file data, and a memory information table; the obtaining global variable data from the system cache and storing the global variable data in a first storage area includes:

[0065] Obtain the data of the executable file to be executed, the configuration file data, and the memory information table from the system cache;

[0066] Synchronously store the data of the executable file to be executed, the configuration file data, and the memory information table in the first storage area;

[0067] Wherein, the data of the executable file to be executed is the file data corresponding to the main program to be executed by the master controller, the configuration file data is the relevant file data of the configuration parameters of the master controller, and the memory information table includes the storage information of all variable data to be called by the master controller.

[0068] Through the third aspect of the present application, during the use of multiple controllers, the impact of the synchronization process on the controller's execution program can be reduced. Especially when the master controller is initially started and executes high-priority tasks, the amount of synchronized data between the master and slave controllers can be greatly reduced, fully developing the performance of the processor itself. At the same time, data transmission is synchronized as needed before each task and program execution, realizing the distribution of data to be synchronized in different execution stages, without the need to write a large amount of data in a short time, thereby effectively reducing the requirement for network interface bandwidth and overall reducing the controller cost.

[0069] In the fourth aspect of the present application, a data synchronization device for a controller is provided. The device includes:

[0070] A classification module for dividing the data to be synchronized into global variable data and task variable data;

[0071] A data synchronization module for obtaining the global variable data and synchronizing the global variable data during the global variable synchronization stage; and, during the task variable synchronization stage, obtaining the task variable data and synchronizing the task variable data.

[0072] In some embodiments, the data synchronization module includes:

[0073] A determination sub-module for determining a first target storage area corresponding to the task variable data; wherein, the first target storage area is the storage area after the synchronization of the task variable data; and, when there is a first virtual function table in the first target storage area, determining a second target storage location of the task variable data according to the first target storage location of the first virtual function table;

[0074] A storage sub-module for storing the task variable data according to the second target storage location.

[0075] In some embodiments, the classification module is further configured to divide the task variable synchronization stage into a task data synchronization stage and a program data synchronization stage according to the synchronization process of the task variable data; and, according to the division of the task variable synchronization stage, divide the task variable data into first variable data and second variable data; wherein, the first variable data is the variable data of the task process, and the second variable data is the variable data of the object program in the task process;

[0076] The data synchronization module is further configured to obtain the first variable data and synchronize the first variable data during the task data synchronization stage; and, during the program data synchronization stage, obtain the second variable data and synchronize the second variable data.

[0077] In some embodiments, the data synchronization module includes:

[0078] A determination sub-module, configured to determine a second target storage area for the task variable data; wherein, the second target storage area is the storage area after synchronization of the second variable data; and, when there is a second virtual function table in the second target storage area, determine a fourth target storage location for the second variable data according to a third target storage location of the second virtual function table;

[0079] A storage sub-module, configured to store the second variable data according to the fourth target storage location.

[0080] In some embodiments, the data synchronization module includes:

[0081] A determination sub-module, configured to determine a third target storage area for the global variable data; wherein, the third target storage area is the storage area after synchronization of the global variable data; and, when there is a third virtual function table in the third target storage area, determine a sixth target storage location for the global variable data according to a fifth target storage location of the third virtual function table;

[0082] A storage sub-module, configured to store the global variable data according to the sixth target storage location.

[0083] In some embodiments, the data synchronization module includes:

[0084] An acquisition sub-module, configured to acquire the to-be-executed file data, configuration file data, and memory information table of the main controller when the controller is powered on;

[0085] A storage sub-module, configured to synchronously store the to-be-executed file data, the configuration file data, and the memory information table in the storage area corresponding to each slave controller;

[0086] Wherein, the to-be-executed file data is the file data corresponding to the main program to be executed by the main controller, the configuration file data is the relevant file data of the configuration parameters of the main controller, and the memory information table includes the storage information of all variable data to be called by the main controller.

[0087] According to the fourth aspect of the present application, all data to be synchronized can be synchronized in stages during different processes executed by the main controller, without occupying a large amount of resources for data synchronization during the initial startup state or the execution process of high-priority tasks after startup, improving the execution performance of each thread of the controller after initial startup; at the same time, when there is a virtual function pointer in a class function, when storing the data to be synchronized during the synchronization process, the storage location of the virtual function table can be skipped, thereby effectively avoiding the virtual function table being overwritten and reducing the impact of synchronization between different controllers on the controller itself.

[0088] In a fifth aspect of the present application, there is provided a data synchronization device for a controller, the device includes:

[0089] A first storage module, configured to obtain global variable data and store the global variable data in the system cache;

[0090] A sending module, configured to send a global variable synchronization instruction to a slave controller; wherein, the global variable synchronization instruction is used to instruct the slave controller to obtain the global variable data from the system cache;

[0091] The first storage module is further configured to obtain task variable data and store the task variable data in the system cache;

[0092] The sending module is further configured to send a task variable synchronization instruction to the slave controller; wherein, the task variable synchronization instruction is used to instruct the slave controller to obtain the task variable data from the system cache.

[0093] In some embodiments, the first storage module is further configured to obtain program variable data and store the program variable data in the system cache;

[0094] The sending module is further configured to send a program variable synchronization instruction to the slave controller, and the program variable synchronization instruction is used to instruct the slave controller to obtain the program variable data from the system cache.

[0095] In some embodiments, the first storage module is further configured to obtain the data of the file to be executed, the configuration file data, and the memory information table; and synchronously store the data of the file to be executed, the configuration file data, and the memory information table in the system cache;

[0096] Wherein, the data of the file to be executed is the file data corresponding to the main program to be executed by the master controller, the configuration file data is the relevant file data of the configuration parameters of the master controller, and the memory information table includes the storage information of all variable data to be called by the master controller.

[0097] According to the fifth aspect of the present application, when performing data synchronization, data synchronization can be performed in respective corresponding stages based on different stages such as global, task process, and program process, without centralized data synchronization, effectively reducing the impact of the data synchronization process on the execution threads of the controller.

[0098] A sixth aspect of the present application provides a data synchronization device for a controller, the device comprising:

[0099] A receiving module, configured to receive a global variable synchronization instruction sent by a master controller;

[0100] A second storage module, configured to obtain global variable data from the system cache and store the global variable data in a first storage area; wherein, the first storage area is a designated storage area for the global variable;

[0101] The receiving module is used to receive the task variable synchronization instruction sent by the main controller;

[0102] The second storage module is used to obtain task variable data from the system cache and store the task variable data in a second storage area; wherein, the second storage area is the designated storage area for the task variable data.

[0103] In some embodiments, the second storage module is further used to, when there is a fourth virtual function table in the second storage area, obtain the seventh target storage location of the fourth virtual function table; and, determine the eighth target storage location of the task variable data according to the seventh target storage location; and, store the task variable data according to the eighth target storage location.

[0104] In some embodiments, the receiving module is further used to receive the program variable synchronization instruction sent by the main controller;

[0105] The second storage module is further used to obtain program variable data from the system cache and store the program variable data in a third storage area; wherein, the third storage area is the designated storage area in the second storage area for storing the program variable data.

[0106] In some embodiments, the second storage module is further used to, when there is a fifth virtual function table in the third storage area, obtain the ninth target storage location of the fifth virtual function table; and, determine the tenth target storage location of the program variable data according to the ninth target storage location; and, store the program variable data according to the tenth target storage location.

[0107] In some embodiments, the second storage module is further used to, when there is a sixth virtual function table in the first storage area, obtain the eleventh target storage location of the sixth virtual function table; and, determine the twelfth target storage location of the global variable data according to the eleventh target storage location; and, store the global variable data according to the twelfth target storage location.

[0108] In some embodiments, the global variable data includes data of an executable file, configuration file data, and a memory information table;

[0109] The second storage module is further used to obtain the data of the executable file, the configuration file data, and the memory information table from the system cache; and, synchronously store the data of the executable file, the configuration file data, and the memory information table in the first storage area;

[0110] Among them, the data of the file to be executed is the file data corresponding to the main program to be executed by the main controller, the data of the configuration file is the relevant file data of the configuration parameters of the main controller, and the memory information table includes the storage information of all variable data that the main controller needs to call.

[0111] Through the sixth aspect of the present application, during the use of multiple controllers, the impact of the synchronization process on the program executed by the controller can be reduced. Especially when the main controller is initially started to execute high-priority tasks, the amount of synchronized data between the master and slave controllers can be greatly reduced, fully developing the performance of the processor itself. At the same time, data transmission is synchronized as needed before each task and program execution, realizing the distribution of data to be synchronized in different execution stages, without the need to write a large amount of data in a short time, thus effectively reducing the requirement for network interface bandwidth and overall reducing the controller cost.

[0112] The seventh aspect of the present application provides a computer-readable storage medium, on which a computer program is stored. When the program is executed by a processor, the above data synchronization method is implemented.

[0113] The eighth aspect of the present application provides an electronic device, including:

[0114] A processor;

[0115] A memory storing a computer program, which when executed by the processor causes the processor to execute the above data synchronization method. BRIEF DESCRIPTION OF THE DRAWINGS

[0116] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following will briefly introduce the drawings required for the description of the embodiments. Obviously, the following drawings are only some embodiments of the present application. For those of ordinary skill in the art, other drawings can also be obtained based on these drawings without exceeding the scope claimed by the present application.

[0117] Figure 1 is a schematic flowchart of a data synchronization method for a controller provided by the present application;

[0118] Figure 2 is a schematic diagram of the data structure of a controller provided by the present application;

[0119] Figure 3 is a schematic flowchart of the processing process of a main controller provided by the present application;

[0120] Figure 4 is a schematic flowchart of the processing process of a slave controller provided by the present application;

[0121] Figure 5It is a schematic flowchart of a data synchronization method for a controller provided by this application;

[0122] Figure 6 It is a schematic flowchart of a data synchronization method for a controller provided by this application;

[0123] Figure 7 It is a schematic structural diagram of a data synchronization device for a controller provided by this application;

[0124] Figure 8 It is a schematic structural diagram of a data synchronization device for a controller provided by this application;

[0125] Figure 9 It is a schematic structural diagram of a data synchronization device for a controller provided by this application;

[0126] Figure 10 It is a schematic structural diagram of an electronic device provided by this application. Detailed implementation manners

[0127] Next, the technical solutions in the embodiments of this application will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of this application. Obviously, the described embodiments are some, but not all, of the embodiments of this application. Based on the embodiments in this application, all other embodiments obtained by those skilled in the art without creative efforts fall within the protection scope of this application.

[0128] In the field of industrial control technology, generally high requirements are placed on the stability and reliability of the controller. The controller is used to issue control instructions to related devices based on industrial production requirements, control the operation of related devices, and conduct industrial production. Currently, the stability of the controller is usually improved through a dual-machine or multi-machine master-slave redundancy configuration, that is, a main controller is set to take the lead, and one or more slave controllers are set as backup controllers. During the production process, the slave controller is used as the regular processor of the main controller to execute task threads. When the main controller fails or is updated, the slave controller can replace the main controller to control the production process, thereby effectively ensuring the stability of the controller during the production process, improving production efficiency and reducing maintenance costs.

[0129] In a multi - controller solution with a master - slave redundant configuration for two or more machines, both the working controller (master controller) and the standby controller (slave controller) perform self - diagnosis and mutual diagnosis. When the working controller fails and the standby controller is normal, the master - slave relationship is automatically switched. To avoid / reduce the disturbance to the controlled object, the switching time is required to be as short as possible, which means the data synchronization efficiency needs to be high. In existing controller synchronization methods, usually when the main program runs, all the data of the controller is preferentially synchronized in the initial highest - level task, resulting in a large amount of time consumption for high - priority tasks. Moreover, for application programs with a large amount of synchronized data, there are also high requirements for the network interface bandwidth for data transmission or writing, with high costs and limited amounts of data that can be transmitted synchronously. Among them, for the case of multiple slave controllers, the priorities of each slave controller can be preset, and then when the master controller needs to be replaced, the slave controller with the highest priority is selected as the master controller in the order from high to low according to the priorities of the slave controllers.

[0130] The present application provides a data synchronization method for a controller. In a control system, when the main program is executed, the global variable data is synchronized, and the variables in specific tasks or programs are not synchronized. When the task thread is executed, the task variable data corresponding to the task thread is synchronized. Thus, data synchronization can be carried out step by step as needed, and the synchronization tasks are distributed to different execution processes, reducing the occupation time of high - priority tasks and the data transmission volume.

[0131] Attached Figure 1 shows a data synchronization method for a controller according to an exemplary embodiment, which is applied in a control system.

[0132] According to the synchronization process of the data to be synchronized by the controller, the synchronization stage of the data to be synchronized can be divided into a global variable synchronization stage and a task variable synchronization stage.

[0133] Before the main program is executed, the variables can be defined and declared by the operation software of the control system according to the scope of action of global variables, task variables, and program variables, and the variable data is allocated to the corresponding data area of the master controller for storage.

[0134] When the controller is powered on, the master / slave relationship of the controller can be established according to the pre-setting in the control system. After that, the master controller can obtain the target file and configuration file from the control system for initialization, and then generate a memory information table based on the storage information of the data to be synchronized in the storage area. Then, the file data such as the target file, configuration file, and memory information table are synchronized to the slave controller for the initialization operation of the slave controller. Among them, the target file is the file to be executed of the main program that the controller directly executes after being compiled by the control system, and the configuration file is a file composed of information such as the number of tasks, task cycles, the number of specific object programs included in the task, and cycles in the main program. After that, when the master controller executes the main program, it will obtain the data of the global variables applied in the main program, execute the main program, and synchronize the data of the global variables. Usually, when the controller is powered on and started with specific control tasks, at this time, the synchronization of the data of the global variables and the synchronization of the data of the file to be executed, configuration file, and memory information table can be regarded as a synchronization stage, that is, the global variable synchronization stage.

[0135] During the normal execution of the main program, the execution of specific task processes will be involved, and based on different objects in the task process, usually a task process will include multiple object-oriented program processes. The scopes of the task variables and program variables defined above are the task variables corresponding to the task process and the program variables corresponding to the program process. When the present application performs data synchronization, when it executes to the task process, it can synchronize the data corresponding to the task variables and the data corresponding to the program variables in the task process. At this time, the synchronization of the data corresponding to the task variables and the data corresponding to the program variables can be regarded as a synchronization stage, that is, the task variable synchronization stage.

[0136] According to the synchronization process described above, the synchronization stages of all the data to be synchronized can be divided into the global variable synchronization stage and the task variable synchronization stage. The specific data synchronization process can be as follows:

[0137] S101: Divide the data to be synchronized into global variable data and task variable data.

[0138] After dividing the synchronization stage in the above manner, the synchronization of the data of the global variables synchronized in the global variable synchronization stage and the data of the file to be executed, configuration file, and memory information table can be divided into global variable data.

[0139] Similarly, divide the data corresponding to the task variables and the data corresponding to the program variables in the task variable synchronization stage into task variable data.

[0140] S102: In the global variable synchronization stage, obtain the global variable data and perform the synchronization of the global variable data.

[0141] In the global variable synchronization phase, all variable data of the main program to be executed by the controller can be defined in the relevant software of the operating system before the controller is powered on. Variables can include basic variable types defined by the IEC61131 standard, structure variables based on combinations of basic variables, function block instance variables, and class instance variables. Among them, global variables are used for program reading and writing across tasks within the controller, task variables are used for program reading and writing within this task, and program variables are used for reading and writing within the scope of this program. A task refers to a task executed by the controller, and each task includes one or more object programs.

[0142] As Figure 2 shown, the global variable definition node, task definition node, task variable definition node, and program node of the controller can be displayed on the programming software interface. Each program node has a definition interface for program variables. In the code generation and compilation phase, variables can be allocated to corresponding positions in the data area, and the obtained data area can be compactly distributed according to the global variable data area and task data area. The task data area is then sequentially distributed according to task variables and each program variable.

[0143] Based on the power-on of the controller, a master / slave relationship is established for the controller, so that the master controller can obtain the data of the file to be executed and the configuration file data from the control system, perform initialization operations, and then store the variable data in the corresponding data area according to the defined all variable data. Such as the global data area and each task data area, the memory of the data area can be compactly allocated in the order of global variables, each task variable, and program variables. Among them, the data area can be the data area allocated by the operating system for the master controller, or the data area of the master controller itself.

[0144] Optionally, during the initialization process of the master controller, the obtained data can be verified through the compilation process, and limit conditions can be set, such as only allowing one task program to write to a global variable and allowing multiple task programs to read. Thus, it can be judged whether there is incorrect data in the data and the influence on the data writing process can be avoided.

[0145] In addition, a memory information table can be generated to record the starting position and length of the virtual function table pointer of the class instance object in the data area, and information such as the data type definition of the defined variable data, the relative offset address of the member variables in the structure, and the storage address of the obtained data of the file to be executed and the configuration file data. That is, the memory information table includes the storage information of all variable data that the master controller needs to call.

[0146] In some embodiments, global variables can be aggregated into a temporary global structure, task variables at each level can be aggregated to form a temporary task structure, variables declared within each program can be aggregated into a temporary program structure, and variable data type definitions (such as structures or classes) and several temporary structure definitions can be output as an analyzable file, for example, a C++ style header file. By invoking the structure offset analysis module, for example, the structure layout analysis module of GCC (GNU Compiler Collection) or LLVM (Low Level Virtual Machine) can be called to obtain the relative offset addresses of member variables within the structure, and then they are allocated to the data area again according to the principles of memory alignment and compact arrangement. The relative offset addresses of global variables, task variables, and program variables in the data area can be obtained in the offline phase, and then the class instances in the data area can be traversed.

[0147] For example, the starting offset address of the virtual function table pointer of this class instance is the offset address of the last declared member variable in the class plus the variable length. Taking program variables as an example, Figure 2 in, the program variable can have a class instance inst1 of type A, which has two member variables a2 and b2 in the data area. To achieve object-oriented polymorphism, the compiler uses the technique of dynamic binding. Each class containing virtual functions contains a virtual function table. Class A contains virtual functions vfunc1 and vfunc2. Since class A contains virtual functions, class A has a virtual function table.

[0148]

[0149]

[0150] The virtual function table is an array of pointers, and its elements are pointers to virtual functions. Each element corresponds to a function pointer of a virtual function. The virtual function table belongs to the class, not to a specific object. A class only needs one virtual function table. All objects of the same class use the same virtual function table. To specify the virtual function table of an object, the object contains a pointer to the virtual function table to point to the virtual function table it uses. To enable each class object to have a virtual function table pointer, the compiler adds a pointer *__vptr to the class to point to the virtual function table. When a class object is created, it has this pointer, and the value of this pointer will be automatically set to point to the virtual function table of the class. The length of the virtual function table can be the total number of bytes of the class instance minus the total number of bytes of the class member variables.

[0151] Optionally, the global variables may include data of files to be executed, data of configuration files, and a memory information table. The controller includes a main controller and at least one slave controller. When the controller is powered on, the data of files to be executed, the data of configuration files, and the memory information table of the main controller can be obtained; the data of files to be executed, the data of configuration files, and the memory information table are synchronously stored in the storage area corresponding to each slave controller; wherein, the data of files to be executed is the file data corresponding to the main program to be executed by the main controller, the data of configuration files is the relevant file data of the configuration parameters of the main controller, and the memory information table includes the storage information of all variable data to be called by the main controller.

[0152] After the initialization operation of the main controller is completed, the operating system can store the data of files to be executed, the data of configuration files, the memory information table, and the global variable data as global variable data in the system cache of the operating system, and send a synchronization instruction of the global variable data to each slave controller. Alternatively, the operating system stores the data of files to be executed, the data of configuration files, the memory information table, and the global variable data as global variable data in the system cache of the operating system through the main controller, and sends a synchronization instruction of the global variable data to each slave controller.

[0153] The synchronization instruction of the global variable data may include the storage address of the global variable data in the system cache of the operating system.

[0154] Thus, the slave controller can obtain the global variable data stored at the storage address according to the storage address in the synchronization instruction of the global variable data. After obtaining the global variable data, the slave controller can store the global variable data according to the memory information table therein.

[0155] Optionally, a third target storage area for storing the global variable data may be determined in the storage area of the slave controller or in the storage area corresponding to the slave controller in the control system, so that after the synchronization is completed, the global variable is stored in this storage area.

[0156] After determining the third target storage area, the slave controller can detect whether there is a third virtual function table in the third target area. The third virtual function table is the virtual function table based on its own virtual functions in the main program process of the slave controller. For example, the class instance of the slave controller itself includes a class instance containing a virtual function pointer.

[0157] When there is a third virtual function table in the third target storage area, the sixth target storage position corresponding to the global variable function can be re-determined according to the fifth target storage position of the third virtual function table, and the global variable data is stored according to the sixth target storage position.

[0158] In some embodiments, the slave controller can determine the sixth target storage location of the global variable data by obtaining the fifth target storage location of the third virtual function table and obtaining the data corresponding to the data structure having an association relationship in the global variable data from the memory information table, taking this type of data as a whole data block, and reallocating storage locations in the storage area other than the fifth target storage location in the third target storage area according to the data block.

[0159] Optionally, when the third target storage area is the storage area allocated for the slave controller in the data area of the control system, the step of detecting whether there is a third virtual function table in the third target area can be detected by the operating system or the operating system through the master controller.

[0160] In some embodiments, after the operating system or the master controller determines the third target area corresponding to the slave controller for storing the global variable function, it can detect whether there is a third virtual function table in the third target area. When it is determined that there is a third virtual function table in the third target storage area, obtain the fifth target storage location of the third virtual function table, and according to the fifth target storage location, re-determine the sixth target storage location corresponding to the global variable function, and store the global variable data according to the sixth target storage location.

[0161] S103: In the task variable synchronization stage, obtain task variable data and perform synchronization of the task variable data.

[0162] In step S102, after the master controller is initialized, it can read the task variable data of the tasks in the main program and execute the task process. When the controller executes the task process, it can store the task variable data in the system cache of the operating system and send a task variable synchronization instruction to the slave controller. Or, the operating system synchronizes the task variable data in the storage area corresponding to the slave controller through the master controller.

[0163] Optionally, the first target storage area corresponding to the task variable data can be determined. The first target storage area is the storage area after the task variable data is synchronized; when there is a first virtual function table in the first target storage area, determine the second target storage location of the task variable data according to the first target storage location of the first virtual function table; store the task variable data according to the second target storage location.

[0164] During implementation, the storage location corresponding to the task variable data, that is, the first target storage area, can be determined in the storage area corresponding to the slave controller. If the slave controller does not have its own data storage area, then the first target storage area is the storage area corresponding to the task variable data in the storage area corresponding to the slave controller in the data area of the operating system. If the slave controller has its own data storage area, then the first target storage area is the storage area corresponding to the task variable in the slave controller.

[0165] For a slave controller with a storage area, the slave controller can determine whether there is a first virtual function table in the first target storage area. When it is determined that there is a first virtual function table in the first target storage area, obtain the first target storage location of the first virtual function table, determine the second target storage location of the task variable data according to the first target storage location, and store the task variable data according to the second target storage location.

[0166] Optionally, according to the synchronization process of the task variable data, the task variable synchronization stage can be divided into a task data synchronization stage and a program data synchronization stage; according to the division of the task variable synchronization stage, the task variable data is divided into first variable data and second variable data, where the first variable data is the variable data of the task process, and the second variable data is the variable data of the object program in the task process; in the task data synchronization stage, obtain the first variable data and perform the synchronization of the first variable data; in the program data synchronization stage, obtain the second variable data and perform the synchronization of the second variable data.

[0167] In some embodiments, according to the data synchronization process when the main controller is currently executing a task process or a specific object program process in the task process, the data synchronization stage when executing the task process is used as the task data synchronization stage, and the data synchronization stage when the main program executes a specific program process is used as the program data synchronization stage. Thus, the task variable synchronization stage can be divided into a task data synchronization stage and a program data synchronization stage. Furthermore, the task variable data and related configuration parameters synchronized in the task data synchronization stage are used as the first variable data, and the program variable data and related configuration parameters synchronized in the program data synchronization stage are used as the second variable data.

[0168] Optionally, determine the second target storage area of the task variable data, where the second target storage area is the storage area after the synchronization of the second variable data; when there is a second virtual function table in the second target storage area, determine the fourth target storage location of the task variable data according to the third target storage location of the second virtual function table; store the second variable data according to the fourth target storage location.

[0169] In the same way as the task variable data synchronization process, when it is determined that there is a second virtual function table, determine the fourth target storage location of the second variable data according to the third target storage location of the second virtual function table and store the second variable data.

[0170] In addition, the slave controller can perform a refresh operation once after the synchronization of any one of the global variable data, task variable data, and task variable data is completed, or set a refresh period to periodically refresh the data of the slave controller, and verify the global variable data, task variable data, and task variable data. Then, when receiving the running command from the master controller, it can ensure that the global variable data, task variable data, and task variable data are all verified data. At this time, the slave controller can act as the processor processing thread of the master controller.

[0171] Optionally, in the periodic refresh and verification scheme, if the target task variable data corresponding to the target task or the target program variable data corresponding to the target program has not been verified yet, when the slave controller receives the running command of the target task or the target program sent by the master controller, the slave controller performs a refresh operation to verify the target task variable data or the target program variable data, and then executes the thread of the target task or the thread of the target program.

[0172] During the implementation process, the execution mode of the master and slave controllers can refer to Figure 3 、 4 's execution timing. As Figure 3 shown, after the master controller is powered on and initialized, the execution process of each task can be as follows:

[0173] Call the hook function before task execution;

[0174] Read the bus data associated with this task;

[0175] Send the relevant data in the data area, that is, the task variable data, to the slave controller;

[0176] Send a synchronous running command to the slave controller;

[0177] Run the program, that is, run the task process;

[0178] Write the bus data;

[0179] Call the hook function after task execution.

[0180] Among them, in the task hierarchy, tasks are pre-allocated priorities. Usually, according to the priorities of the tasks, from high to low, tasks with higher task priorities are preferentially executed. For example, after the task is powered on and starts, after completing the initialization operation, that is, based on the operation of the main program, the task process with the highest priority is executed.

[0181] And the execution timing of the slave controller, as Figure 4 shown, after dividing the master and slave controllers, the execution process of the slave controller as a processor to execute tasks under the control of the master controller is as follows:

[0182] The task execution thread waits for and receives the enable semaphore from the redundant communication thread;

[0183] In this step, in the redundant communication thread, the above data synchronization process will be carried out first. For the task process, real-time data will be received, stored in the buffer, and data verification will be carried out after the data reception is complete to avoid data loss.

[0184] When storing data, according to the information in the memory information table, the storage location corresponding to the virtual function table of the slave controller can be skipped, that is, the data in the buffer is fragmented and synchronized to the data area. Based on the received activation semaphore including the synchronization running message, the slave controller is refreshed and initialized, waits for the execution semaphore, executes the relevant task process, and after starting the execution, the following operations are carried out.

[0185] Call the hook function before task execution;

[0186] Read the bus data associated with this task;

[0187] Run the program, that is, run the task process;

[0188] Call the hook function after task execution.

[0189] Therefore, according to the above data synchronization method, all the data to be synchronized can be synchronized in stages during the execution of different processes by the master controller, without occupying a large amount of resources for data synchronization during the initial startup state or during the execution of high-priority tasks after startup, improving the execution performance of each thread of the controller after initial startup; at the same time, when there is a virtual function pointer in the class function, when storing the data to be synchronized during the synchronization process, the storage location of the virtual function table can be skipped, thereby effectively avoiding the virtual function table being overwritten and reducing the impact of synchronization between different controllers on the controller itself.

[0190] Figure 5 A data synchronization method for a controller according to another exemplary embodiment is shown. In the master controller, the specific data synchronization process can be as follows:

[0191] S201: Obtain global variable data and store the global variable data in the system cache.

[0192] Before the controller is powered on, all variable data of the main program to be executed by the controller is defined in the relevant software of the operating system. For example, variables can include basic variable types defined by the IEC61131 standard, structure variables based on basic variable combinations, function block instance variables, and class instance variables. Among them, global variables are used for program reading and writing between tasks within the controller, task variables are used for program reading and writing within this task, and program variables are used for reading and writing within the scope of this program. A task refers to a task executed by the controller, and each task includes one or more object programs.

[0193] As Figure 2 shown, the global variable definition node, task definition node, task variable definition node, and program node can be displayed on the programming software interface. Each program node has a definition interface for program variables. During the code generation and compilation stage, variables can be allocated to corresponding positions in the data area, and the obtained data area can be compactly distributed according to the global variable data area and task data area. The task data area is sequentially distributed according to task variables and each program variable.

[0194] Based on the power-on of the controller, the master / slave relationship of the controller is established, so that the master controller can obtain the data of the file to be executed and the configuration file data from the control system, perform initialization operations, and then store the variable data in the corresponding data area according to the defined all variable data during the synchronization stage. Such as the global data area and each task data area, the memory of the data area can be compactly allocated in the order of global variables, each task variable, and program variables. Among them, the data area can be the data area allocated by the operating system for the master controller or the data area of the master controller itself.

[0195] According to the storage of data in the data area, a memory information table can be generated to record the starting position and length of the virtual function table pointer of the class instance object in the data area, and record information such as the data type definition of the defined variable data, the relative offset address of the member variables in the structure, and the storage addresses of the obtained data of the file to be executed and the configuration file data. That is, the memory information table includes the storage information of all variable data that the master controller needs to call. That is, the global variable data can include the data of the file to be executed, the configuration file data, and the memory information table.

[0196] Optionally, the data of the file to be executed, the configuration file data, and the memory information table can be obtained; the data of the file to be executed, the configuration file data, and the memory information table are synchronously stored in the system cache; among them, the data of the file to be executed is the file data corresponding to the main program to be executed by the master controller, the configuration file data is the relevant file data of the configuration parameters of the master controller, and the memory information table includes the storage information of all variable data that the master controller needs to call.

[0197] In some embodiments, after the master controller is initialized, the file to be executed can be executed based on the obtained data of the file to be executed, and the main program process can be entered. At the same time, the data of the file to be executed, the configuration file data, and the memory information table can be obtained, stored in the system cache of the control system, and the corresponding storage addresses in the system cache are recorded. Among them, the memory information table can record the starting position and length of the virtual function table pointer of the class instance object in the data area, and record storage information such as the data type definition of the defined variable data, the relative offset address of the member variables in the structure, and the storage addresses of the obtained data of the file to be executed and the configuration file data.

[0198] S202: Send a global variable synchronization instruction to the slave controller. The global variable synchronization instruction is used to instruct the slave controller to obtain global variable data from the system cache.

[0199] After storing the data of the file to be executed, the configuration file data, and the memory information table in the system cache of the control system, a global variable synchronization instruction can be sent to all slave controllers, and the storage addresses of the data of the file to be executed, the configuration file data, and the memory information table in the system cache of the control system can be carried in the global variable synchronization instruction. So that the slave controller can obtain the global variable data from the system cache according to the storage address, and complete the initialization operation of the slave controller based on the global variable data, achieving the effect that the slave controller can execute the main program and can execute the main program-related processing tasks based on the instructions of the main program.

[0200] In the specific implementation process, the master controller can send a running command to the slave controller when executing the main program, so that the slave controller executes related tasks as the processor of the master controller. For example, during the running of the main program, the master controller can send a running command of A to the slave controller based on function A of the main program. After receiving the running command, the slave controller can execute function A and return the execution result to the master controller.

[0201] S203: Obtain task variable data and store the task variable data in the system cache.

[0202] When the master controller executes to a specific task process in the main program, it can obtain the task variable data, store it in the system cache of the operating system, and send a task variable synchronization instruction to the slave controller to synchronize the task variable data.

[0203] In some embodiments, after the main program runs, the task process with the highest priority can be executed based on the priority of the task process. When executing this task process, the task variable data corresponding to this task process can be obtained. The task variable data can include the data of the variables of this task process and the program variable data corresponding to each program in this task process. Through the storage information in the memory information table, obtain the task variable data from the corresponding data area, store the obtained task variable data in the system cache, and record the storage location.

[0204] S204: Send a task variable synchronization instruction to the slave controller. The task variable synchronization instruction is used to instruct the slave controller to obtain task variable data from the system cache.

[0205] After the main controller stores the task variable data in the system cache, it can send a task variable synchronization instruction including the storage location of the task variable data in the system cache to the slave controller, so that the slave controller can obtain the task variable data from the corresponding location in the system cache and store it in the storage location of the corresponding task variable data of the slave controller.

[0206] Optionally, the task variable data synchronization process can synchronize only the data corresponding to the variables of the task process. When executing to a specific program process, the program variable data is synchronized again.

[0207] In some embodiments, when executing to the specific program of the task process, the program variable data can be obtained, stored in the system cache; a program variable synchronization instruction is sent to the slave controller, and the program variable synchronization instruction is used to instruct the slave controller to obtain the program variable data from the system cache.

[0208] Optionally, when the data area of the slave controller is the storage area allocated by the control system for the slave controller, during the synchronization process of the data to be synchronized by the main controller, it can be detected whether there is a virtual function table in the target storage area corresponding to the data to be synchronized. When there is a virtual function table in the target area, the position of the virtual function table is obtained, and according to the storage information of the data in the memory information table and the storage area corresponding to the slave controller, the new storage position of the data to be synchronized is determined.

[0209] Thus, through the above technical solutions of the present application, when performing data synchronization, it is possible to perform data synchronization in their respective corresponding stages based on different stages such as global, task process, and program process, without centralized data synchronization, effectively reducing the impact of the data synchronization process on the execution threads of the controller.

[0210] Figure 6 Shows a data synchronization method for a controller according to another exemplary embodiment, compared with the Figure 5 scheme in, in the slave controller, the specific data synchronization process can be as follows:

[0211] S301: Receive the global variable synchronization instruction sent by the main controller.

[0212] Based on the power-on of the controller, the master / slave relationship of the controller is established. Thus, after the main controller obtains the data of the file to be executed and the configuration file data from the control system, and after performing initialization operations, after storing the data of the file to be executed, the configuration file data, and the memory information table in the system cache of the control system, it can send a global variable synchronization instruction to all slave controllers, and carry the storage addresses of the data of the file to be executed, the configuration file data, and the memory information table in the system cache of the control system in the global variable synchronization instruction. Correspondingly, the slave controller receives the global variable synchronization instruction sent by the main controller.

[0213] S302: Obtain the global variable data from the system cache and store the global variable data in the first storage area, where the first storage area is the designated storage area for the global variables.

[0214] After receiving the global variable synchronization instruction from the controller, the slave controller can obtain the global variable data from the system cache according to the storage address, store it in its own data area or the data area allocated by the control system for it, and then complete the initialization operation of the slave controller based on the global variable data.

[0215] Optionally, the global variable data includes the data of the file to be executed, the configuration file data, and the memory information table. The process of obtaining the global variable data from the system cache and storing the global variable data in the first storage area may include: obtaining the data of the file to be executed, the configuration file data, and the memory information table from the system cache; synchronously storing the data of the file to be executed, the configuration file data, and the memory information table in the first storage area; where the data of the file to be executed is the file data corresponding to the main program to be executed by the master controller, the configuration file data is the relevant file data of the configuration parameters of the master controller, and the memory information table includes the storage information of all variable data to be called by the master controller.

[0216] After obtaining the global variable data, the slave controller can determine the access area in its own data area to store the global variable data, or store the global variable data in the data area allocated by the control system for the slave controller. And during the storage process, it can detect whether there is a virtual function table in the determined storage area.

[0217] Optionally, when there is a sixth virtual function table in the first storage area, obtain the eleventh target storage location of the sixth virtual function table; according to the eleventh target storage location, determine the twelfth target storage location of the global variable data; store the global variable data according to the twelfth target storage location.

[0218] In some embodiments, the slave controller can determine the first storage area allocated for the global variable data by judging whether there is a class instance with a virtual function table in the class instance during the stage from power-on to the execution of the specific task process. When there is a class instance with a virtual function pointer in the class instance, it is determined that there is a sixth virtual function table corresponding to the virtual function pointer in the first storage area. Determine the storage location of the sixth virtual function table, that is, the eleventh target storage location, based on the virtual function pointer, so that the new twelfth target storage location of the global variable can be determined according to the eleventh target storage location, and the global variable data is stored in the twelfth target storage location, thus avoiding overwriting the eleventh target storage location.

[0219] When storing specifically, according to the memory information table, the association relationships between data in the global variable data can be obtained, such as relative storage positions, structures, etc. The data with association relationships is used as an overall data block, and the effective storage positions of all data in the global variable data are re-determined. The effective storage position is an area in the first storage area that will not overwrite the first target storage position.

[0220] S303: Receive the task variable synchronization instruction sent by the master controller.

[0221] When the master controller executes the task process, it can obtain the task variable data, store the task variable data in the system cache of the control system, record the storage position of the task variable data in the cache, and send a task variable synchronization instruction including the storage position to the slave controller; correspondingly, the slave controller will receive the task variable synchronization instruction including the storage position.

[0222] S304: Obtain the task variable data from the system cache and store the task variable data in the second storage area, where the second storage area is the designated storage area for the task variable data.

[0223] The slave controller can obtain the task variable data from the system cache according to the storage position carried in the task variable synchronization instruction, and determine the second storage area of the task variable data according to the storage information in the memory information table.

[0224] Optionally, when there is a fourth virtual function table in the second storage area, obtain the seventh target storage position of the fourth virtual function table; determine the eighth target storage position of the task variable data according to the seventh target storage position; store the task variable data according to the eighth target storage position.

[0225] During implementation, the slave controller can determine whether the class instance in the task process contains a class instance with a virtual function table. When the class instance contains a class instance with a virtual function pointer, it is determined that there is a fourth virtual function table corresponding to the virtual function pointer in the second storage area. Obtain the seventh target storage position of the fourth virtual function table, determine a new eighth target storage position of the task variable data in the second storage area according to the seventh target storage position, and store the task variable data according to the eighth target storage position, thereby effectively avoiding overwriting the seventh target storage position and ensuring the normal call of class functions including virtual function pointers in the program process.

[0226] Optionally, receive the program variable synchronization instruction sent by the master controller; obtain the program variable data from the system cache and store the program variable data in the third storage area, where the third storage area is the designated storage area in the second storage area for storing the program variable data.

[0227] In the process of synchronizing task variable data, the variable data in the task process can be further divided into program processes for synchronization. When the main controller executes the program in the task process, the program variable data can be stored in the system cache of the operating system, and the storage address of the program variable data in the system cache can be recorded. Then, a program variable synchronization instruction including the storage address is sent to the slave controller.

[0228] Correspondingly, after receiving the program variable synchronization instruction sent by the master control, the slave controller can obtain the program variable data according to the storage address of the program variable data in the system cache, and determine, according to the memory information table, that the program variable data corresponds to the third storage area in the data area corresponding to the slave controller, and store the program variable data in the third storage area.

[0229] Optionally, when the fifth virtual function table exists in the third storage area, the ninth target storage position of the fifth virtual function table is obtained; according to the ninth target storage position, the tenth target storage position of the program variable data is determined; and the program variable data is stored according to the tenth target storage position.

[0230] If there is a class function including a virtual function pointer in the program process, that is, when it is determined that there is a fifth virtual function table in the third storage area, the ninth target storage position of the fifth virtual function table can be obtained, and according to the ninth target storage position, a new tenth target storage position for storing program variable data can be determined in the third storage area. Based on the storage information of the data of the variable of the program process in the memory information table, the program variable data is stored in the tenth target storage position.

[0231] Through the above-mentioned method of the present application, the impact of the synchronization process on the controller execution program can be reduced during the use of multiple controllers, especially when the main controller is initially started to execute a high-priority task, the amount of synchronization data between the master and slave controllers can be greatly reduced, and the performance of the processor itself can be fully developed. At the same time, data transmission is synchronized as needed before each task and program is executed, so that the data to be synchronized can be distributed in different execution stages, and there is no need to write a large amount of data in a short period of time, thereby effectively reducing the requirements for network port bandwidth and reducing the controller cost as a whole.

[0232] Attached Figure 7 A data synchronization device of a controller according to another exemplary embodiment is shown in FIG. 1 , the device comprising:

[0233] The classification module is also used to divide the data to be synchronized into global variable data and task variable data;

[0234] A data synchronization module, which is used to obtain the global variable data during the global variable synchronization phase and synchronize the global variable data; and, during the task variable synchronization phase, obtain the task variable data and synchronize the task variable data.

[0235] In some embodiments, the data synchronization module includes:

[0236] A determination sub-module, which is used to determine the first target storage area corresponding to the task variable data, where the first target storage area is the storage area after the synchronization of the task variable data; and, when there is a first virtual function table in the first target storage area, determine the second target storage location of the task variable data according to the first target storage location of the first virtual function table;

[0237] A storage sub-module, which is used to store the task variable data according to the second target storage location.

[0238] In some embodiments, the classification module is further used to divide the task variable synchronization phase into a task data synchronization phase and a program data synchronization phase according to the synchronization process of the task variable data;

[0239] The classification module is further used to divide the task variable data into first variable data and second variable data according to the division of the task variable synchronization phase, where the first variable data is the variable data of the task process, and the second variable data is the variable data of the object program in the task process;

[0240] The data synchronization module is further used to obtain the first variable data during the task data synchronization phase and synchronize the first variable data; and, during the program data synchronization phase, obtain the second variable data and synchronize the second variable data.

[0241] In some embodiments, the data synchronization module includes:

[0242] A determination sub-module, which is used to determine the second target storage area of the task variable data, where the second target storage area is the storage area after the synchronization of the second variable data; and, when there is a second virtual function table in the second target storage area, determine the fourth target storage location of the second variable data according to the third target storage location of the second virtual function table;

[0243] A storage sub-module, which is used to store the second variable data according to the fourth target storage location.

[0244] In some embodiments, the data synchronization module includes:

[0245] A determination sub-module, configured to determine a third target storage area for the global variable data, where the third target storage area is the storage area after synchronization of the global variable data; and, when there is a third virtual function table in the third target storage area, determine a sixth target storage location of the global variable data according to a fifth target storage location of the third virtual function table;

[0246] A storage sub-module, configured to store the global variable data according to the sixth target storage location.

[0247] In some embodiments, the data synchronization module includes:

[0248] An acquisition sub-module, configured to, when the controller is powered on, acquire the to-be-executed file data, configuration file data, and memory information table of the main controller;

[0249] A storage sub-module, configured to synchronously store the to-be-executed file data, the configuration file data, and the memory information table in the storage area corresponding to each slave controller;

[0250] Wherein, the to-be-executed file data is the file data corresponding to the main program to be executed by the main controller, the configuration file data is the relevant file data of the configuration parameters of the main controller, and the memory information table includes the storage information of all variable data to be called by the main controller.

[0251] Thus, according to the above data synchronization device, all data to be synchronized can be synchronized in stages when the main controller executes different processes, without occupying a large amount of resources for data synchronization during the initial startup state or during the execution of high-priority tasks after startup, improving the execution performance of each thread of the controller after initial startup; at the same time, when there is a virtual function pointer in a class function and storing the data to be synchronized during the synchronization process, the storage location of the virtual function table can be skipped, thereby effectively avoiding the virtual function table from being overwritten and reducing the impact of synchronization between different controllers on the controller itself.

[0252] Appendix Figure 8 Figure [X] shows a data synchronization device of a controller according to another exemplary embodiment. The device includes:

[0253] A first storage module, configured to acquire global variable data and store the global variable data in the system cache;

[0254] A sending module, configured to send a global variable synchronization instruction to the slave controller, where the global variable synchronization instruction is used to instruct the slave controller to acquire the global variable data from the system cache;

[0255] A first storage module, configured to acquire task variable data and store the task variable data in the system cache;

[0256] A sending module, configured to send a task variable synchronization instruction to a slave controller, where the task variable synchronization instruction is used to instruct the slave controller to obtain task variable data from a system cache.

[0257] In some embodiments, the first storage module is further configured to obtain to-be-executed file data, configuration file data, and a memory information table; and synchronously store the to-be-executed file data, configuration file data, and memory information table in the system cache.

[0258] The to-be-executed file data is file data corresponding to a main program to be executed by the main controller, the configuration file data is related file data of configuration parameters of the main controller, and the memory information table includes storage information of all variable data to be called by the main controller.

[0259] In some embodiments, the first storage module is further configured to obtain program variable data and store the program variable data in the system cache.

[0260] The sending module is further configured to send a program variable synchronization instruction to the slave controller, where the program variable synchronization instruction is used to instruct the slave controller to obtain program variable data from the system cache.

[0261] Thus, through the above data synchronization device of the present application, when performing data synchronization, data can be synchronized at their respective corresponding stages based on different stages such as global, task process, and program process, without centralized data synchronization, effectively reducing the impact of the data synchronization process on the execution threads of the controller.

[0262] Appendix Figure 9 The figure shows a data synchronization device of a controller according to another exemplary embodiment. The device includes:

[0263] A receiving module, configured to receive a global variable synchronization instruction sent by the main controller.

[0264] A second storage module, configured to obtain global variable data from the system cache and store the global variable data in a first storage area, where the first storage area is a designated storage area for global variables.

[0265] A receiving module, configured to receive a task variable synchronization instruction sent by the main controller.

[0266] A second storage module, configured to obtain task variable data from the system cache and store the task variable data in a second storage area, where the second storage area is a designated storage area for task variable data.

[0267] In some embodiments, the second storage module is further configured to, when there is a fourth virtual function table in the second storage area, obtain a seventh target storage location of the fourth virtual function table; and, determine an eighth target storage location of the task variable data according to the seventh target storage location; and store the task variable data according to the eighth target storage location.

[0268] In some embodiments, the receiving module is further configured to receive a program variable synchronization instruction sent by the main controller;

[0269] The second storage module is further configured to obtain program variable data from the system cache and store the program variable data in a third storage area, where the third storage area is a specified storage area in the second storage area for storing program variable data.

[0270] In some embodiments, the second storage module is further configured to, when there is a fifth virtual function table in the third storage area, obtain a ninth target storage location of the fifth virtual function table; and, determine a tenth target storage location of the program variable data according to the ninth target storage location; and store the program variable data according to the tenth target storage location.

[0271] In some embodiments, the second storage module is further configured to, when there is a sixth virtual function table in the first storage area, obtain an eleventh target storage location of the sixth virtual function table; and, determine a twelfth target storage location of the global variable data according to the eleventh target storage location; and store the global variable data according to the twelfth target storage location.

[0272] In some embodiments, the global variable data includes data of a file to be executed, configuration file data, and a memory information table.

[0273] The second storage module is further configured to obtain the data of the file to be executed, the configuration file data, and the memory information table from the system cache; and synchronously store the data of the file to be executed, the configuration file data, and the memory information table in the first storage area.

[0274] Wherein, the data of the file to be executed is the file data corresponding to the main program to be executed by the main controller, the configuration file data is the related file data of the configuration parameters of the main controller, and the memory information table includes the storage information of all variable data to be called by the main controller.

[0275] Through the above data synchronization device of the present application, during the use of multiple controllers, the impact of the synchronization process on the controller execution program can be reduced. Especially when the master controller is initially started and executes high-priority tasks, the amount of synchronized data between the master and slave controllers can be greatly reduced, fully developing the performance of the processor itself. At the same time, data transmission is synchronized as needed before each task and program execution, realizing the distribution of data to be synchronized in different execution stages, without the need to write a large amount of data in a short time, thereby effectively reducing the requirement for network interface bandwidth and overall reducing the controller cost.

[0276] According to a computer-readable storage medium of another exemplary embodiment, a computer program is stored thereon, and when the program is executed by a processor, the above data synchronization method is implemented.

[0277] Through the description of the above embodiments, those skilled in the art can easily understand that the exemplary embodiments described herein can be implemented by software or by a combination of software and necessary hardware. According to the technical solutions of the embodiments of the present application, they can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (such as a CD-ROM, USB flash drive, mobile hard disk, etc.) or on the network, including several instructions to enable a computing device (such as a personal computer, server, or network device, etc.) to execute the above methods according to the embodiments of the present application.

[0278] The software product can adopt any combination of one or more readable media. The readable medium can be a readable signal medium or a readable storage medium. The readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or component, or any combination of the above. More specific examples (non-exhaustive list) of the readable storage medium include: an electrical connection having one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.

[0279] The computer-readable storage medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries the readable program code. Such a propagated data signal can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. The readable storage medium can also be any readable medium other than the readable storage medium, which can send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, device, or component. The program code contained on the readable storage medium can be transmitted by any appropriate medium, including but not limited to wireless, wired, optical cable, RF, etc., or any suitable combination of the above.

[0280] The program code for performing the operations of the present application can be written in any combination of one or more programming languages, including object-oriented programming languages such as Java, C++, etc., and also including conventional procedural programming languages such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computing device, partially on the user's device, executed as a stand-alone software package, partially on the user's computing device and partially on a remote computing device, or entirely on a remote computing device or server. In the case of a remote computing device, the remote computing device can be connected to the user's computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computing device (e.g., by connecting through the Internet using an Internet service provider).

[0281] Those skilled in the art can understand that the above-mentioned various modules can be distributed in the device according to the description of the embodiments, or can be correspondingly changed and distributed in one or more devices that are uniquely different from this embodiment. The modules of the above embodiments can be combined into one module, or can be further split into multiple sub-modules.

[0282] Through the description of the above embodiments, those skilled in the art can easily understand that the exemplary embodiments described herein can be implemented by software, or can be implemented by a combination of software and necessary hardware. Therefore, the technical solutions according to the embodiments of the present application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, including several instructions to enable a computing device (which can be a personal computer, a server, a mobile terminal, or a network device, etc.) to execute the method according to the embodiments of the present application.

[0283] Figure 10 The structural schematic diagram of an electronic device according to an exemplary embodiment is shown.

[0284] An electronic device, comprising:

[0285] A processor;

[0286] A memory storing a computer program, which when executed by the processor causes the processor to execute the above data synchronization method.

[0287] It should be understood that the above device embodiments are merely illustrative, and the devices disclosed in the present invention can also be implemented in other ways. For example, the division of the units / modules described in the above embodiments is only a logical function division, and there can be other division methods in actual implementation. For example, multiple units, modules or components can be combined, or can be integrated into another system, or some features can be ignored or not executed.

[0288] In addition, without special instructions, in each embodiment of the present invention, each functional unit / module can be integrated in one unit / module, or each unit / module can exist physically alone, or two or more units / modules can be integrated together. The above integrated unit / module can be implemented in the form of hardware or in the form of a software program module.

[0289] When the integrated unit / module is implemented in the form of hardware, the hardware can be a digital circuit, an analog circuit, etc. The physical implementation of the hardware structure includes but is not limited to transistors, memristors, etc. Without special instructions, the processor or chip can be any suitable hardware processor, such as CPU, GPU, FPGA, DSP, and ASIC, etc. Without special instructions, the on-chip cache, off-chip memory, and memory can be any suitable magnetic storage medium or magneto-optical storage medium, such as resistive random access memory (RRAM), dynamic random access memory (DRAM), static random access memory (SRAM), enhanced dynamic random access memory (EDRAM), high-bandwidth memory (HBM), hybrid memory cube (HMC), etc.

[0290] When the integrated unit / module is implemented in the form of a software program module and sold or used as an independent product, it can be stored in a computer-readable memory. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a memory and includes several instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in various embodiments of this disclosure. The aforementioned memory includes various media that can store program codes, such as USB flash drives, read-only memories (ROM, Read-Only Memory), random access memories (RAM, Random Access Memory), mobile hard disks, magnetic disks, or optical discs.

[0291] The embodiments of this application have been introduced in detail above. Specific examples are used in this article to elaborate on the principle and implementation manner of this application. The description of the above embodiments is only used to help understand the method and its core idea of this application. At the same time, any changes or deformations made by those skilled in the art based on the idea of this application, within the specific implementation manner and application scope of this application, fall within the scope of protection of this application. In summary, the content of this specification should not be construed as a limitation to this application.

Claims

1. A data synchronization method for a controller, characterized in that, including: dividing the data to be synchronized into global variable data and task variable data; in the global variable synchronization stage, obtaining the global variable data and performing the synchronization of the global variable data, including: determining a third target storage area for the global variable data; wherein, the third target storage area is the storage area after the synchronization of the global variable data; when there is a third virtual function table in the third target storage area, determining a sixth target storage location for the global variable data according to a fifth target storage location of the third virtual function table; storing the global variable data according to the sixth target storage location; in the task variable synchronization stage, obtaining the task variable data and performing the synchronization of the task variable data, including: determining a first target storage area corresponding to the task variable data; wherein, the first target storage area is the storage area after the synchronization of the task variable data; when there is a first virtual function table in the first target storage area, determining a second target storage location for the task variable data according to a first target storage location of the first virtual function table; storing the task variable data according to the second target storage location.

2. The data synchronization method according to claim 1, wherein further including: dividing the task variable synchronization stage into a task data synchronization stage and a program data synchronization stage according to the synchronization process of the task variable data; dividing the task variable data into first variable data and second variable data according to the division of the task variable synchronization stage; wherein, the first variable data is the variable data of the task process, and the second variable data is the variable data of the object program in the task process; in the task data synchronization stage, obtaining the first variable data and performing the synchronization of the first variable data; in the program data synchronization stage, obtaining the second variable data and performing the synchronization of the second variable data.

3. The data synchronization method according to claim 2, wherein The "in the program data synchronization stage, obtaining the second variable data and performing the synchronization of the second variable data" includes: determining a second target storage area for the task variable data; wherein, the second target storage area is the storage area after the synchronization of the second variable data; when there is a second virtual function table in the second target storage area, determining a fourth target storage location for the second variable data according to a third target storage location of the second virtual function table; storing the second variable data according to the fourth target storage location.

4. The data synchronization method according to claim 1, wherein The global variable data includes executable file data, configuration file data, and memory information tables, and the controller includes a main controller and at least one slave controller; The "in the global variable synchronization stage, obtaining the global variable data and performing the synchronization of the global variable data" includes: when the controller is powered on, obtaining the executable file data, configuration file data, and memory information tables of the main controller; synchronously storing the executable file data, the configuration file data, and the memory information tables in the storage areas corresponding to each slave controller; Among them, the file data to be executed is the file data corresponding to the main program to be executed by the main controller, the configuration file data is the relevant file data of the configuration parameters of the main controller, and the memory information table includes the storage information of all variable data to be called by the main controller.

5. A data synchronization method for a controller, characterized in that, It includes: Receiving a global variable synchronization instruction sent by the main controller; Obtaining global variable data from the system cache and storing the global variable data in a first storage area; wherein, the first storage area is the designated storage area for the global variables; Receiving a task variable synchronization instruction sent by the main controller; Obtaining task variable data from the system cache and storing the task variable data in a second storage area; wherein, the second storage area is the designated storage area for the task variable data; The obtaining task variable data from the system cache and storing the task variable data in the second storage area includes: When there is a fourth virtual function table in the second storage area, obtaining the seventh target storage location of the fourth virtual function table; Determining the eighth target storage location of the task variable data according to the seventh target storage location; Storing the task variable data according to the eighth target storage location; The obtaining global variable data from the system cache and storing the global variable data in the first storage area includes: When there is a sixth virtual function table in the first storage area, obtaining the eleventh target storage location of the sixth virtual function table; Determining the twelfth target storage location of the global variable data according to the eleventh target storage location; Storing the global variable data according to the twelfth target storage location.

6. The data synchronization method according to claim 5, wherein It also includes: Receiving a program variable synchronization instruction sent by the main controller; Obtaining program variable data from the system cache and storing the program variable data in a third storage area; wherein, the third storage area is the designated storage area in the second storage area for storing the program variable data.

7. The data synchronization method according to claim 6, wherein The obtaining program variable data from the system cache and storing the program variable data in the third storage area includes: When there is a fifth virtual function table in the third storage area, obtaining the ninth target storage location of the fifth virtual function table; Determining the tenth target storage location of the program variable data according to the ninth target storage location; Storing the program variable data according to the tenth target storage location.

8. The data synchronization method according to claim 5, wherein The global variable data includes file data to be executed, configuration file data and a memory information table; the obtaining global variable data from the system cache and storing the global variable data in the first storage area includes: Obtaining the file data to be executed, the configuration file data and the memory information table from the system cache; Synchronously storing the file data to be executed, the configuration file data and the memory information table in the first storage area; Among them, the to-be-executed file data is the file data corresponding to the main program to be executed by the main controller, the configuration file data is the relevant file data of the configuration parameters of the main controller, and the memory information table includes the storage information of all variable data to be called by the main controller.

9. A data synchronization device for a controller, characterized in that, It includes: A classification module, configured to divide the to-be-synchronized data into global variable data and task variable data; A data synchronization module, configured to, in the global variable synchronization stage, obtain the global variable data and perform synchronization of the global variable data; and, in the task variable synchronization stage, obtain the task variable data and perform synchronization of the task variable data; Among them, the data synchronization module includes: A determination sub-module, configured to determine a first target storage area corresponding to the task variable data; where the first target storage area is the storage area after synchronization of the task variable data; and, when there is a first virtual function table in the first target storage area, determine a second target storage location of the task variable data according to a first target storage location of the first virtual function table; A storage sub-module, configured to store the task variable data according to the second target storage location; Among them, the determination sub-module is further configured to determine a third target storage area of the global variable data; where the third target storage area is the storage area after synchronization of the global variable data; and, when there is a third virtual function table in the third target storage area, determine a sixth target storage location of the global variable data according to a fifth target storage location of the third virtual function table; The storage sub-module is further configured to store the global variable data according to the sixth target storage location.

10. The data synchronization device according to claim 9, wherein The classification module is further configured to divide the task variable synchronization stage into a task data synchronization stage and a program data synchronization stage according to the synchronization process of the task variable data; and, according to the division of the task variable synchronization stage, divide the task variable data into first variable data and second variable data; where the first variable data is the variable data of the task process, and the second variable data is the variable data of the object program in the task process; The data synchronization module is further configured to, in the task data synchronization stage, obtain the first variable data and perform synchronization of the first variable data; and, in the program data synchronization stage, obtain the second variable data and perform synchronization of the second variable data.

11. The data synchronization device according to claim 10, wherein The data synchronization module includes: A determination sub-module, configured to determine a second target storage area of the task variable data; where the second target storage area is the storage area after synchronization of the second variable data; and, when there is a second virtual function table in the second target storage area, determine a fourth target storage location of the second variable data according to a third target storage location of the second virtual function table; A storage sub-module, configured to store the second variable data according to the fourth target storage location.

12. The data synchronization device according to claim 9, wherein The data synchronization module includes: An acquisition sub-module, configured to acquire the data of the file to be executed, the configuration file data, and the memory information table of the main controller when the controller is powered on; A storage sub-module, configured to synchronously store the data of the file to be executed, the configuration file data, and the memory information table in the storage area corresponding to each slave controller; Wherein, the data of the file to be executed is the file data corresponding to the main program to be executed by the main controller, the configuration file data is the relevant file data of the configuration parameters of the main controller, and the memory information table includes the storage information of all variable data to be called by the main controller.

13. A data synchronization device for a controller, characterized in that It includes: A receiving module, configured to receive the global variable synchronization instruction sent by the main controller; And receive the task variable synchronization instruction sent by the main controller; A second storage module, configured to acquire the global variable data from the system cache and store the global variable data in a first storage area; wherein, the first storage area is the designated storage area for the global variable; and acquire the task variable data from the system cache and store the task variable data in a second storage area; wherein, the second storage area is the designated storage area for the task variable data; The second storage module is further configured to, when there is a fourth virtual function table in the second storage area, acquire the seventh target storage location of the fourth virtual function table; determine the eighth target storage location of the task variable data according to the seventh target storage location; and store the task variable data according to the eighth target storage location; The second storage module is further configured to, when there is a sixth virtual function table in the first storage area, acquire the eleventh target storage location of the sixth virtual function table; determine the twelfth target storage location of the global variable data according to the eleventh target storage location; and store the global variable data according to the twelfth target storage location.

14. The data synchronization device according to claim 13, wherein The receiving module is further configured to receive the program variable synchronization instruction sent by the main controller; The second storage module is further configured to acquire the program variable data from the system cache and store the program variable data in a third storage area; wherein, the third storage area is the designated storage area in the second storage area for storing the program variable data.

15. The data synchronization device according to claim 14, wherein The second storage module is further configured to, when there is a fifth virtual function table in the third storage area, acquire the ninth target storage location of the fifth virtual function table; determine the tenth target storage location of the program variable data according to the ninth target storage location; and store the program variable data according to the tenth target storage location.

16. The data synchronization device according to claim 13, wherein The global variable data includes the data of the file to be executed, the configuration file data, and the memory information table; The second storage module is further configured to acquire the data of the file to be executed, the configuration file data, and the memory information table from the system cache; and synchronously store the data of the file to be executed, the configuration file data, and the memory information table in the first storage area; Among them, the file data to be executed is the file data corresponding to the main program to be executed by the main controller, the configuration file data is the relevant file data of the configuration parameters of the main controller, and the memory information table includes the storage information of all variable data to be called by the main controller.

17. A computer-readable storage medium, characterized in that, A computer program is stored thereon, and when the program is executed by a processor, the method according to any one of claims 1-8 is implemented.

18. An electronic device, characterized in that, Including: A processor; A memory storing a computer program, and when the computer program is executed by the processor, the processor is caused to execute the method according to any one of claims 1-8.

Citation Information

Patent Citations

  • Redundant system-oriented host and standby data synchronization method, apparatus and device, and medium

    CN114528152A

  • Data synchronization method of robot system and robot system

    CN114722050A