Power-down data saving method, apparatus and device, and readable storage medium
By stopping the call to a new program task in the power-down device and determining the task status, the power-down data is saved from the volatile storage area to the non-volatile storage area, the problem of errors in saving data after power-down in traditional solutions is solved, and the consistency and correctness of the data are achieved.
Patent Information
- Application Number
- PCT/CN2024/123444
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-12-19
- Filing Date
- 2024-10-08
- Publication Date
- 2025-06-26
AI Technical Summary
In traditional solutions, there is a greater risk of critical data stored after power failure, which is mainly because new critical data may be generated at the moment of power failure, resulting in a risk of change in the saved data.
By including a volatile storage area and a nonvolatile storage area in the power-down device, if a power-down signal is received, the new program task is stopped and the task status of the executed target program task is determined. If the task status is completed, the power-down data is saved from the volatile storage area to the nonvolatile storage area.
Ensure that the old and new power-down data in the nonvolatile storage area are consistent after the power-down occurs, and data errors are avoided.
Smart Images

Figure CN2024123444_26062025_PF_FP_ABST
Abstract
Description
Power-off data preservation method, device, equipment and readable storage medium
[0001] This application claims priority to Chinese patent application No. 202311762342.2 filed on December 19, 2023, the entire contents of which are incorporated by reference into this application. Technical Field
[0002] The present application relates to the technical field of PLC (Programmable Logic Controller), and in particular to a method, device, equipment, and readable storage medium for preserving power-off data. Background Art
[0003] During the operation of the PLC program, some key data generated requires that the values at the time of the last operation be retained after the PLC is restarted. Under normal circumstances, the data generated during the last operation are stored in volatile memory. When the volatile memory is powered off, all data will be lost. Therefore, after the power is cut off and restarted, the data during the last operation will also be lost. In order to solve this problem, some traditional technical solutions currently available will write the key data that needs to be retained after a power outage into a non-volatile memory to ensure that the data from the last operation can be retained after a power outage and restart. However, since the occurrence of power outages is unpredictable, new key data may be generated at the moment of power outage, that is, there is a risk that the key data will be changed when the key data is saved. Therefore, in traditional solutions, there is a greater risk that the key data saved after a power outage will be erroneous data. Technical issues
[0004] The main purpose of this application is to provide a method for preserving data after power failure, aiming to solve the technical problem that in traditional solutions, there is a high risk that key data saved after power failure will be erroneous data. Technical Solutions
[0005] To achieve the above objectives, the present application provides a power-off data preservation method, which is applied to a power-off device, wherein the power-off device includes a volatile storage area and a non-volatile storage area. The power-off data preservation method includes:
[0006] If the power-off device receives a power-off signal, it stops calling new program tasks;
[0007] The task status of the executed target program tasks is determined, and if the task status of each target program task is execution completion, the power-off data corresponding to the target program task is saved from the volatile storage area to the non-volatile storage area.
[0008] In one embodiment, the volatile storage area includes a data area and a holding area, and the step of stopping calling new program tasks if the power-off device receives a power-off signal includes:
[0009] If the power-off device receives a power-off signal, the control variable is changed to a stop state to stop calling the forward synchronization function corresponding to the new program task, wherein the forward synchronization function is used to save the power-off data corresponding to the program task from the data area to the holding area.
[0010] In one embodiment, the step of determining the task status of the executed target program tasks, if the task status of each of the target program tasks is execution completion, saving the power-off data corresponding to the target program tasks from the volatile storage area to the non-volatile storage area includes:
[0011] Monitor the state variables of the forward synchronization function corresponding to the executed target program task;
[0012] Determining a task state of the executed target program task based on the state variable;
[0013] If the task status of each target program task is execution completion, the power-off data corresponding to each target program task is saved from the holding area to the non-volatile storage area.
[0014] In one embodiment, the step of determining the task status of the executed target program task based on the state variable further includes:
[0015] In the case where the state variable represents the overall execution state of each target program task, if the state variable is a preset initial value, it is determined that the task state of each target program task is execution completion;
[0016] If the state variable is not a preset initial value, it is determined that there is a target program task whose task status is being executed.
[0017] In one embodiment, the step of determining the task status of the executed target program task based on the state variable further includes:
[0018] In the case where one target program task corresponds to one state variable, if each state variable represents an end state, it is determined that the task state of each target program task is execution completion;
[0019] If there is a state variable representing the execution state, it is determined that there is a target program task with a task state of being executed.
[0020] In one embodiment, the power-off data preservation method further includes:
[0021] monitoring the control variable;
[0022] The calling and execution of the program task is controlled based on the control variable, and the state variable is updated based on the execution status of the program task.
[0023] In one embodiment, the step of controlling the calling and execution of the program task based on the control variable further comprises:
[0024] If the control variable is in the stop state, then the calling and execution of the new program task is stopped;
[0025] If the control variable is in an enabled state, the program task is executed based on a preset execution cycle.
[0026] In one embodiment, the step of updating the state variable based on the execution status of the program task includes:
[0027] In the case where the state variable represents the overall execution state of each target program task, for any target program task, when the target program task starts to be executed, the state variable is increased by a preset value;
[0028] When the target program task is executed, the state variable is subtracted from a preset value.
[0029] In one embodiment, the step of updating the state variable based on the execution status of the program task further includes:
[0030] In the case where one target program task corresponds to one state variable, for any target program task, when the target program task starts to be executed, the state variable corresponding to the target program task is updated to represent the execution state;
[0031] When the target program task is executed, the state variable corresponding to the target program task is updated to represent the end state.
[0032] In one embodiment, the power-off data is generated when the application is running, and the power-off data saving method further includes:
[0033] During the application compilation process, for any power-off data that will be generated during the running of the application, a program task corresponding to the power-off data is generated;
[0034] Generate control variables used to control the execution of each program task call.
[0035] To achieve the above-mentioned object, the present application further provides a power-off data preservation device, which is applied to a power-off device, wherein the power-off device includes a volatile storage area and a non-volatile storage area, and the power-off data preservation device includes:
[0036] The stop module is used to stop calling new program tasks if the power-off device receives a power-off signal;
[0037] The saving module is used to determine the task status of the executed target program tasks, and if the task status of each target program task is execution completion, save the power-off data corresponding to the target program task from the volatile storage area to the non-volatile storage area.
[0038] To achieve the above-mentioned purpose, the present application also provides a power-off data preservation device, which includes: a memory, a processor, and a power-off data preservation program stored in the memory and executable on the processor. When the power-off data preservation program is executed by the processor, the steps of the power-off data preservation method described above are implemented.
[0039] To achieve the above objectives, the present application also provides a readable storage medium, on which a power-off data preservation program is stored. When the power-off data preservation program is executed by a processor, the steps of the power-off data preservation method as described above are implemented. Beneficial effects
[0040] The embodiment of the present application proposes a method, device, equipment and readable storage medium for saving power-off data. It is applied to a power-off device, and the power-off device includes a volatile storage area and a non-volatile storage area. If the power-off device receives a power-off signal, it stops calling new program tasks; determines the task status of the executed target program tasks, and if the task status of each of the target program tasks is completed, saves the power-off data corresponding to the target program tasks from the volatile storage area to the non-volatile storage area. Compared with the traditional saving scheme, the embodiment of the present application will first stop calling new program tasks for execution after a power outage occurs, thereby avoiding the new program tasks being called for execution and causing new changes to the power-off data that needs to be saved, and after stopping calling new program tasks, it will determine the task status of the executed target program tasks, and if the task status of the target program tasks is all completed, save the power-off data in the holding area to the non-volatile storage area, thereby ensuring that the power-off data that needs to be changed in the holding area has been changed before being saved to the non-volatile storage area. Therefore, through the above method, the present application can ensure the consistency of the power-off data in the non-volatile storage area after a power-off occurs, thereby avoiding the occurrence of data errors. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] FIG1 is a schematic diagram of the device structure of the hardware operating environment involved in the embodiment of the present application;
[0042] FIG2 is a flow chart of a first embodiment of the power-off data preservation method of the present application;
[0043] FIG3 is a flow chart of a second embodiment of the power-off data preservation method of the present application;
[0044] FIG4 is a schematic diagram of the first frame of the power-off data preservation method of the present application;
[0045] FIG5 is a schematic diagram of the second frame of the power-off data preservation method of the present application;
[0046] FIG6 is a schematic structural diagram of a power-off data preservation device in the power-off data preservation method of the present application.
[0047] The realization of the objectives, functional features and advantages of this application will be further explained in conjunction with embodiments and with reference to the accompanying drawings. Modes for Carrying Out the Invention
[0048] It should be understood that the specific embodiments described herein are only used to explain the present application and are not intended to limit the present application.
[0049] As shown in FIG1 , FIG1 is a schematic diagram of the device structure of the hardware operating environment involved in the embodiment of the present application.
[0050] The device in the embodiment of the present application can be a PLC, or it can be an electronic terminal device with network communication function such as a PC, a smart phone, a tablet computer, or a portable computer.
[0051] As shown in Figure 1, the device may include: a processor 1001, such as a CPU, a network interface 1004, a user interface 1003, a memory 1005, and a communication bus 1002. The communication bus 1002 is used to enable communication between these components. The user interface 1003 may include a display and an input unit such as a keyboard. The user interface 1003 may also include a standard wired interface or a wireless interface. The network interface 1004 may include a standard wired interface or a wireless interface (such as a Wi-Fi interface). The memory 1005 may be a high-speed RAM memory or a non-volatile memory, such as a disk storage device. The memory 1005 may also be a storage device independent of the processor 1001.
[0052] In one embodiment, the device may also include a camera, RF (Radio Frequency) circuits, sensors, audio circuits, a WiFi module, and the like. These sensors include light sensors, motion sensors, and other sensors. Light sensors may include ambient light sensors and proximity sensors. The ambient light sensor can adjust the brightness of the display based on ambient light levels, while the proximity sensor can turn off the display and / or backlight when the mobile terminal is brought to the ear. A gravity accelerometer, a type of motion sensor, can detect acceleration in all directions (typically three axes) and, when stationary, can detect the magnitude and direction of gravity. This can be used for applications that recognize the mobile terminal's posture (e.g., switching between landscape and portrait modes, related games, magnetometer posture calibration), vibration recognition-related functions (e.g., pedometers and tapping). Mobile terminals may also be equipped with other sensors, such as gyroscopes, barometers, hygrometers, thermometers, and infrared sensors, which are not detailed here.
[0053] Those skilled in the art will understand that the device structure shown in FIG1 does not constitute a limitation on the device, and may include more or fewer components than shown, or a combination of certain components, or a different arrangement of components.
[0054] As shown in FIG1 , the memory 1005 as a computer storage medium may include an operating system, a network communication module, a user interface module, and a power-off data preservation program.
[0055] In the device shown in FIG1 , the network interface 1004 is primarily used to connect to a backend server and communicate data with the backend server; the user interface 1003 is primarily used to connect to a client (user end) and communicate data with the client; and the processor 1001 can be used to call a power-off data preservation program stored in the memory 1005. The power-off data preservation program is applied to a power-off device, which includes a volatile storage area and a non-volatile storage area. The processor 1001 can perform the following operations:
[0056] If the power-off device receives a power-off signal, it stops calling new program tasks;
[0057] The task status of the executed target program tasks is determined, and if the task status of each target program task is execution completion, the power-off data corresponding to the target program task is saved from the volatile storage area to the non-volatile storage area.
[0058] In one embodiment, the processor 1001 may call the power-off data preservation program stored in the memory 1005 and further perform the following operations:
[0059] The volatile storage area includes a data area and a holding area. If the power-off device receives a power-off signal, the step of stopping calling a new program task includes:
[0060] If the power-off device receives a power-off signal, the control variable is changed to a stop state to stop calling the forward synchronization function corresponding to the new program task, wherein the forward synchronization function is used to save the power-off data corresponding to the program task from the data area to the holding area.
[0061] In one embodiment, the processor 1001 may call the power-off data preservation program stored in the memory 1005 and further perform the following operations:
[0062] The step of determining the task status of the executed target program tasks, and if the task status of each target program task is execution completion, saving the power-off data corresponding to the target program task from the volatile storage area to the non-volatile storage area includes:
[0063] Monitor the state variables of the forward synchronization function corresponding to the executed target program task;
[0064] Determining a task state of the executed target program task based on the state variable;
[0065] If the task status of each target program task is execution completion, the power-off data corresponding to each target program task is saved from the holding area to the non-volatile storage area.
[0066] In one embodiment, the processor 1001 may call the power-off data preservation program stored in the memory 1005 and further perform the following operations:
[0067] The step of determining the task status of the executed target program task based on the state variable further comprises:
[0068] In the case where the state variable represents the overall execution state of each target program task, if the state variable is a preset initial value, it is determined that the task state of each target program task is execution completion;
[0069] If the state variable is not a preset initial value, it is determined that there is a target program task whose task status is being executed.
[0070] In one embodiment, the processor 1001 may call the power-off data preservation program stored in the memory 1005 and further perform the following operations:
[0071] The step of determining the task status of the executed target program task based on the state variable further comprises:
[0072] In the case where one target program task corresponds to one state variable, if each state variable represents an end state, it is determined that the task state of each target program task is execution completion;
[0073] If there is a state variable representing the execution state, it is determined that there is a target program task with a task state of being executed.
[0074] In one embodiment, the processor 1001 may call the power-off data preservation program stored in the memory 1005 and further perform the following operations:
[0075] The power-off data preservation method further includes:
[0076] monitoring the control variable;
[0077] The calling and execution of the program task is controlled based on the control variable, and the state variable is updated based on the execution status of the program task.
[0078] In one embodiment, the processor 1001 may call the power-off data preservation program stored in the memory 1005 and further perform the following operations:
[0079] The step of calling and executing the program task based on the control variable control further includes:
[0080] If the control variable is in the stop state, then the calling and execution of the new program task is stopped;
[0081] If the control variable is in an enabled state, the program task is executed based on a preset execution cycle.
[0082] In one embodiment, the processor 1001 may call the power-off data preservation program stored in the memory 1005 and further perform the following operations:
[0083] The step of updating the state variable based on the execution status of the program task includes:
[0084] In the case where the state variable represents the overall execution state of each target program task, for any target program task, when the target program task starts to be executed, the state variable is increased by a preset value;
[0085] When the target program task is executed, the state variable is subtracted from a preset value.
[0086] In one embodiment, the processor 1001 may call the power-off data preservation program stored in the memory 1005 and further perform the following operations:
[0087] The step of updating the state variable based on the execution status of the program task also includes:
[0088] In the case where one target program task corresponds to one state variable, for any target program task, when the target program task starts to be executed, the state variable corresponding to the target program task is updated to represent the execution state;
[0089] When the target program task is executed, the state variable corresponding to the target program task is updated to represent the end state.
[0090] In one embodiment, the processor 1001 may call the power-off data preservation program stored in the memory 1005 and further perform the following operations:
[0091] The power-off data is generated when the application is running, and the power-off data saving method further includes:
[0092] During the application compilation process, for any power-off data that will be generated during the running of the application, a program task corresponding to the power-off data is generated;
[0093] Generate control variables used to control the execution of each program task call.
[0094] 2, the first embodiment of the power-off data preservation method of the present application is applied to a power-off device.
[0095] The power-off data preservation method comprises:
[0096] Step S10: If the power-off device receives a power-off signal, it stops calling new program tasks;
[0097] It should be noted that in this application, the aforementioned power outage refers to a device power outage, such as a PLC device power outage. Accordingly, the aforementioned power-off device can be a PLC device. In the subsequent steps, the PLC device power outage will be used as an example for explanation. In different application scenarios, different applications will run on the PLC to implement different functions. For example, a function may be to record the number of products produced. Accordingly, the product number is critical data that needs to be retained after a power outage. It is understood that in actual applications, the PLC's volatile memory is typically divided into two areas: a user area, also known as the data area, which can store data generated during application operation, including power-off data (it is worth noting that there will typically be multiple power-off data, and the distribution of these data is usually relatively dispersed). The aforementioned program task can be used to synchronously copy the power-off data scattered in the data area to another area in the volatile memory, also known as the retention area, thereby consolidating the power-off data for easier storage. The program task can correspond to a forward synchronization function (also known as an implicit function). In traditional storage solutions, a power-off signal immediately triggers the saving of data in the holding area. However, if power-off data is being copied from the data area to the holding area and the copying is not complete, the data ultimately saved in the non-volatile memory will be erroneous data. For example, assume that multiple power-off data generated in the nth cycle are currently being copied from the data area to the holding area, where some power-off data have been copied but another part is being copied. If a power-off occurs at this time, the power-off data in the holding area will be immediately triggered to be saved in the non-volatile memory. At this time, part of the power-off data saved in the non-volatile memory is generated in the nth cycle, and part is generated in the n-1th cycle. Therefore, the power-off data saved in the non-volatile memory is equivalent to data from different cycles, that is, erroneous data. After the PLC is powered on again, these inconsistent data may cause the PLC device to operate abnormally. To address the above problem, this embodiment proposes a power-off data saving method to ensure the consistency of the power-off data in the non-volatile memory. The data integration (power-off data from the data area to the holding area) and data preservation (holding area to the non-volatile storage area) can be implemented by different programs in the PLC or integrated together.
[0098] In one embodiment, when the PLC suddenly loses power, a power-off signal is triggered. Accordingly, after the power-off device receives the power-off signal, it stops calling new program tasks to avoid new changes in the power-off data stored in the volatile storage area. Among them, the program tasks that have not been completed can continue to be executed.
[0099] Step S20 , determining the task status of the executed target program tasks, and if the task status of each target program task is execution completion, saving the power-off data corresponding to the target program task from the volatile storage area to the non-volatile storage area.
[0100] In one embodiment, unlike the traditional solution, in order to avoid power-off data saving errors after a power-off occurs, this embodiment does not immediately save the power-off data stored in the volatile storage area to the non-volatile storage area, but first determines the task status of the executed target program task, wherein the task status of any target program task can be divided into execution completed and execution in progress. After determining that the task status of each target program task is execution completed, the power-off data corresponding to the target program task can be saved from the volatile storage area to the non-volatile storage area. If there is a target program task with a task status of execution in progress, then wait until all target program tasks are completed before saving the power-off data in the volatile storage area to the non-volatile storage area. It can be understood that if the target program tasks have all been executed to completion, it means that the power-off data in the holding area will not change. Therefore, the power-off data in the volatile storage area can be saved to the non-volatile memory at this time to achieve the persistence of the power-off data.
[0101] In this embodiment, the above method is applied to a power-off device, and the power-off device includes a volatile storage area and a non-volatile storage area. If the power-off device receives a power-off signal, it stops calling new program tasks; determines the task status of the executed target program tasks, and if the task status of each of the target program tasks is execution completed, saves the power-off data corresponding to the target program tasks from the volatile storage area to the non-volatile storage area. Compared with the traditional preservation scheme, the embodiment of the present application will first stop calling new program tasks for execution after a power outage occurs, thereby avoiding new changes to the power-off data that need to be saved due to the new program tasks being called for execution, and after stopping calling new program tasks, it will determine the task status of the executed target program tasks, and if the task status of the target program tasks is execution completed, save the power-off data in the holding area to the non-volatile storage area, thereby ensuring that the power-off data that needs to be changed in the holding area has been changed before being saved to the non-volatile storage area. Therefore, through the above method, the present application can ensure the consistency of the power-off data in the non-volatile storage area after a power-off occurs (that is, the data generated in the same cycle), thereby avoiding data errors.
[0102] In one embodiment, the volatile storage area includes a data area and a holding area, and the step of stopping calling new program tasks if the power-off device receives a power-off signal includes:
[0103] Step S110: If the power-off device receives a power-off signal, the control variable is changed to a stop state to stop calling the forward synchronization function corresponding to the new program task, wherein the forward synchronization function is used to save the power-off data corresponding to the program task from the data area to the holding area.
[0104] In one embodiment, in actual applications, the volatile storage area can be divided into a data area and a holding area, and the calling of program tasks is controlled by setting a control variable. After the power-off device receives a power-off signal, the power-off device can change the control variable to a stop state, thereby stopping the calling of the forward synchronization function corresponding to the new program task. The forward synchronization function corresponding to the program task is used to save the power-off data corresponding to the program task from the data area to the holding area.
[0105] In one embodiment, the step of determining the task status of the executed target program tasks, if the task status of each of the target program tasks is execution completion, saving the power-off data corresponding to the target program tasks from the volatile storage area to the non-volatile storage area includes:
[0106] Step S210, monitoring the state variables of the forward synchronization function corresponding to the executed target program task;
[0107] Step S220, determining the task status of the executed target program task based on the state variable;
[0108] Step S230 : If the task status of each target program task is execution completion, the power-off data corresponding to each target program task is saved from the holding area to the non-volatile storage area.
[0109] It should be noted that in this embodiment, a state variable may be configured for each forward synchronization function to represent the execution status of the forward synchronization function, that is, to represent the task status of the program task corresponding to the forward synchronization function. Therefore, the task status of the executed target program task can be determined using the state variable. If the task status of each target program task is determined to be completed based on the state variable, the power-off data corresponding to each target program task can be saved from the holding area to the non-volatile storage area.
[0110] In one embodiment, the step of determining the task status of the executed target program task based on the state variable further includes:
[0111] Step S21, when the state variable represents the overall execution state of each target program task, if the state variable is a preset initial value, determining that the task state of each target program task is execution completion;
[0112] Step S22: If the state variable is not the preset initial value, it is determined that there is a target program task whose task status is "being executed".
[0113] In one embodiment, the form in which a state variable represents the different task states of a target program task can be selected based on actual needs. For example, a single state variable can be used to represent the overall execution state of each target program task. In this case, if a target program task begins execution, the state variable can be increased by a preset value. Conversely, if the target program task completes execution, the state variable can be decreased by a preset value. Therefore, if each target program task has completed execution, the state variable should be at the preset initial value. Therefore, if the state variable is determined to be at the preset initial value, it can be determined that all integrated tasks have completed execution. Conversely, if the state variable is not at the preset initial value, it can be determined that there is an integrated task in progress. It should be noted that since, in this embodiment, a single state variable represents the overall execution state of each target program task, it is possible that multiple target program tasks may update the state variable simultaneously. Therefore, to avoid conflicts, a lock can be set when updating the state variable. That is, only the target program task that "holds" the lock can update the state variable. The lock is released immediately after the update is complete, allowing other target program tasks to occupy the lock and update the state variable.
[0114] In one embodiment, the step of determining the task status of the executed target program task based on the state variable further includes:
[0115] Step S23, when one target program task corresponds to one state variable, if all the state variables represent an end state, then determining that the task state of all the target program tasks is execution completed;
[0116] Step 24: If there is a state variable representing the execution state, it is determined that there is a target program task with a task state of being executed.
[0117] In one embodiment, a state variable may be set corresponding to each target program task. That is, a state variable only represents the execution status of the target program task corresponding to the state variable. For example, the state variable may be set to a first state value (the first state value represents the end state), which indicates that the corresponding target program task is completed. When the state variable is set to a second state value (the second state value represents the execution state), it indicates that the corresponding target program task is in progress. Therefore, when determining whether all target program tasks have been completed, it is necessary to determine whether all state variables are the first state value. If all state variables are the first state value, it can be determined that all target program tasks have been completed. Conversely, if there is a state variable with the second state value, it can be determined that there is a target program task in progress.
[0118] Furthermore, it should be noted that if the state variable determines that a target program task is currently being executed, the power-off data in the representation holding area will still change. Therefore, the process can return to the step of determining the task status of the executed target program task based on the state variable until all target program tasks have been completed according to the state variable.
[0119] 3, a second embodiment of the present application is proposed based on the first embodiment of the power-off data preservation method of the present application. In this embodiment, the same or similar contents as the above embodiments can be referred to the above introduction and will not be repeated hereafter. The power-off data preservation method further includes:
[0120] Step A10, monitoring the control variable;
[0121] Step A20: Control the calling and execution of the program task based on the control variable, and update the state variable based on the execution status of the program task.
[0122] In one embodiment, the control variables are used to control the invocation of the target program task. Therefore, for a power-off device, before preparing to execute the target program task (e.g., after reaching a preset execution cycle), the control variables can be read once, i.e., monitored. The invocation and execution of the program task are controlled based on the control variables, where the control variables can indicate whether the target program task is permitted to be invoked. The state variables are then updated based on the execution status of the program task. Furthermore, it should be noted that the specific method for updating the state variables of any program task can be determined based on the representation of the state variables, and this will not be further elaborated here.
[0123] In one embodiment, the step of controlling the calling and execution of the program task based on the control variable further comprises:
[0124] Step A211: If the control variable is in the stop state, stop calling and executing the new program task;
[0125] In step A212, if the control variable is in the enabled state, the program task is executed based on a preset execution cycle.
[0126] In one embodiment, in actual application, two values can be set for the control variable, namely, a first control value and a second control value, wherein the first control value represents a stopped state, and the second control value represents an allowed state. Accordingly, if the control variable is detected to be at the first control value, the execution of new target program tasks can be prohibited, and the execution of the target program tasks in progress can continue. After the execution of the target program tasks in progress is completed, the state variable is updated so that the state variable represents that all target program tasks have been executed. Conversely, if the control variable is at the second control value, the target program tasks can be executed normally based on the preset execution cycle.
[0127] In one embodiment, the step of updating the state variable based on the execution status of the program task includes:
[0128] Step A2211: when the state variable represents the overall execution state of each target program task, for any target program task, when the target program task starts to execute, the state variable is increased by a preset value;
[0129] Step A2212: when the target program task is completed, subtract a preset value from the state variable.
[0130] In one embodiment, when a state variable represents the overall execution state of each target program task, for any target program task, when the target program task starts executing, the state variable can be increased by a preset value. For example, if the initial value of the state variable is set to 0, the preset value is 1, and the current value of the state variable is 0, a target program task starts executing, the state variable is increased by the preset value, that is, 0+1=1, so the updated value of the state variable is 1. If the target program task is completed, the state variable can be subtracted by 1, for example, based on the above example 1-1=0, so the updated value of the state variable is 0. It can be understood that in the above case, if all target program tasks are executed, the state variable should be the initial value. Conversely, if the state variable is not the initial value, it indicates that there is still a target program task being executed at this time. Refer to Figure 4, which is a first framework diagram of the present application. As shown in the figure, the data area includes power-off data 1 to n. Accordingly, there are target program tasks 1 to n that copy the power-off data 1 to n from the data area to the holding area respectively, and the target program tasks 1 to n will update a state variable based on their own execution status, for example, increase the state variable by +1 or -1.
[0131] In one embodiment, the step of updating the state variable based on the execution status of the program task further includes:
[0132] Step A221: In the case where one target program task corresponds to one state variable, for any target program task, when the target program task starts to execute, the state variable corresponding to the target program task is updated to represent the execution state;
[0133] Step A222: When the target program task is completed, the state variable corresponding to the target program task is updated to represent the end state.
[0134] In one embodiment, in the case of another form of expression of the state variable, that is, any target program task corresponds to a state variable. In this case, each state variable can also have two values, if a first state value and a second state value, wherein the first state value represents the execution state and the second state value represents the end state, for any target program task, when the target program task starts to execute, the state variable corresponding to the target program task is updated to the first state value. Accordingly, after the target program task is executed, the state variable corresponding to the target program task is updated to the second state value. In actual applications, each state variable can form a state array, and each state variable is an element in the state array. Referring to Figure 5, which is a second framework diagram of the present application, as shown in the figure, the data area includes power-off data 1 to n, and accordingly, there are target program tasks 1 to n that copy power-off data 1 to n from the data area to the holding area respectively, and target program task 1 will update state variable 1 based on its own execution status, ..., target program task n will update state variable n based on its own execution status.
[0135] In one embodiment, the power-off data is generated when the application is running, and the power-off data saving method further includes:
[0136] Step A01, during the application compilation process, for any power-off data that will be generated during the application running process, generating a program task corresponding to the power-off data;
[0137] Step A02: Generate control variables for controlling the execution of each program task call.
[0138] In one embodiment, power-off data is generated when an application is running, wherein the application is a user program used to implement a specific function and can be run in a PLC. Before the application is run, it needs to be compiled by a compiler, for example, a compiler in an IDE (Integrated Development Environment). During the compilation process, the compiler can generate a program task for any power-off data that will be generated during the operation of the application, as well as control variables for controlling the call and execution of each program task. In addition, state variables representing each program task (or the forward synchronization function corresponding to the program task) can also be generated. It is worth noting that the above-mentioned IDE can be configured in the PLC or in the upper computer of the PLC, and no specific restrictions are made in this embodiment.
[0139] In addition, referring to FIG6 , an embodiment of the present application further provides a power-off data storage device 100, which is applied to a power-off device. The power-off device includes a volatile storage area and a non-volatile storage area. The power-off data storage device 100 includes:
[0140] The stop module 10 is used to stop calling new program tasks if the power-off device receives a power-off signal;
[0141] The saving module 20 is configured to determine the task status of the executed target program tasks, and if the task status of each target program task is execution completion, save the power-off data corresponding to the target program task from the volatile storage area to the non-volatile storage area.
[0142] In one embodiment, the volatile storage area includes a data area and a holding area, and the stop module 10 is further configured to:
[0143] If the power-off device receives a power-off signal, the control variable is changed to a stop state to stop calling the forward synchronization function corresponding to the new program task, wherein the forward synchronization function is used to save the power-off data corresponding to the program task from the data area to the holding area.
[0144] In one embodiment, the storage module 20 is further configured to:
[0145] Monitor the state variables of the forward synchronization function corresponding to the executed target program task;
[0146] Determining a task state of the executed target program task based on the state variable;
[0147] If the task status of each target program task is execution completion, the power-off data corresponding to each target program task is saved from the holding area to the non-volatile storage area.
[0148] In one embodiment, the storage module 20 is further configured to:
[0149] In the case where the state variable represents the overall execution state of each target program task, if the state variable is a preset initial value, it is determined that the task state of each target program task is execution completion;
[0150] If the state variable is not a preset initial value, it is determined that there is a target program task whose task status is being executed.
[0151] In one embodiment, the storage module 20 is further configured to:
[0152] In the case where one target program task corresponds to one state variable, if each state variable represents an end state, it is determined that the task state of each target program task is execution completion;
[0153] If there is a state variable representing the execution state, it is determined that there is a target program task with a task state of being executed.
[0154] In one embodiment, the power-off data storage device 100 further includes a monitoring module 30, and the monitoring module 30 is configured to:
[0155] monitoring the control variable;
[0156] The calling and execution of the program task is controlled based on the control variable, and the state variable is updated based on the execution status of the program task.
[0157] In one embodiment, the monitoring module 30 is further configured to:
[0158] If the control variable is in the stop state, then the calling and execution of the new program task is stopped;
[0159] If the control variable is in an enabled state, the program task is executed based on a preset execution cycle.
[0160] In one embodiment, the monitoring module 30 is further configured to:
[0161] In the case where the state variable represents the overall execution state of each target program task, for any target program task, when the target program task starts to be executed, the state variable is increased by a preset value;
[0162] When the target program task is executed, the state variable is subtracted from a preset value.
[0163] In one embodiment, the monitoring module 30 is further configured to:
[0164] In the case where one target program task corresponds to one state variable, for any target program task, when the target program task starts to be executed, the state variable corresponding to the target program task is updated to represent the execution state;
[0165] When the target program task is executed, the state variable corresponding to the target program task is updated to represent the end state.
[0166] In one embodiment, the power-off data storage device 100 further includes a compiling module 40, and the monitoring module 40 is configured to:
[0167] During the application compilation process, for any power-off data that will be generated during the running of the application, a program task corresponding to the power-off data is generated;
[0168] Generate control variables used to control the execution of each program task call.
[0169] The power-failure data preservation device provided in this application utilizes the power-failure data preservation method of the aforementioned embodiment, resolving the technical issue in conventional solutions where there is a significant risk of erroneous data being stored as critical data after a power failure. Compared to the prior art, the beneficial effects of the power-failure data preservation device provided in this embodiment of the application are the same as those of the power-failure data preservation method provided in the first embodiment above. Other technical features of the power-failure data preservation device are the same as those disclosed in the aforementioned embodiment and are not further elaborated here.
[0170] In addition, an embodiment of the present application also proposes a power-off data preservation device, which includes: a memory, a processor, and a power-off data preservation program stored in the memory and runnable on the processor. When the power-off data preservation program is executed by the processor, the steps of the power-off data preservation method described above are implemented.
[0171] The specific implementation of the power-off data preservation device of the present application is basically the same as the various embodiments of the power-off data preservation method described above, and will not be repeated here.
[0172] In addition, an embodiment of the present application further provides a readable storage medium, on which a power-off data preservation program is stored. When the power-off data preservation program is executed by a processor, the steps of the power-off data preservation method described above are implemented.
[0173] The specific implementation of the medium of the present application is basically the same as the embodiments of the above-mentioned power-off data preservation method, and will not be repeated here.
[0174] It should be noted that, in this document, the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, article, or system comprising a series of elements includes not only those elements but also other elements not explicitly listed, or elements inherent to such process, method, article, or system. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of other identical elements in the process, method, article, or system comprising the element.
[0175] The serial numbers of the above embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.
[0176] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus the necessary general hardware platform, and of course can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) as described above, and includes a number of instructions for enabling a terminal device (which can be a PLC, computer, server, or network device, etc.) to execute the methods described in each embodiment of the present application.
[0177] The above are merely embodiments of the present application and are not intended to limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made using the contents of the present application specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present application.
Claims
1. A power-off data preservation method, applied to a power-off device, wherein the power-off device comprises a volatile storage area and a non-volatile storage area, wherein: The power-off data preservation method comprises: If the power-off device receives a power-off signal, it stops calling new program tasks; The task status of the executed target program tasks is determined, and if the task status of each of the target program tasks is execution completion, the power-off data corresponding to the target program tasks is saved from the volatile storage area to the non-volatile storage area.
2. The power-off data preservation method according to claim 1, wherein: The volatile storage area includes a data area and a holding area. If the power-off device receives a power-off signal, the step of stopping calling a new program task includes: If the power-off device receives a power-off signal, the control variable is changed to a stop state to stop calling the forward synchronization function corresponding to the new program task, wherein the forward synchronization function is used to save the power-off data corresponding to the program task from the data area to the holding area.
3. The power-off data preservation method according to claim 2, wherein: The step of determining the task status of the executed target program tasks, and if the task status of each of the target program tasks is execution completion, saving the power-off data corresponding to the target program tasks from the volatile storage area to the non-volatile storage area comprises: Monitor the state variables of the forward synchronization function corresponding to the executed target program task; Determining the task status of the executed target program task based on the state variable; If the task status of each target program task is execution completion, the power-off data corresponding to each target program task is saved from the holding area to the non-volatile storage area.
4. The power-off data preservation method according to claim 3, wherein: The step of determining the task status of the executed target program task based on the state variable also includes: In the case where the state variable represents the overall execution state of each target program task, if the state variable is a preset initial value, it is determined that the task state of each target program task is execution completion; If the state variable is not a preset initial value, it is determined that there is a target program task whose task status is being executed.
5. The power-off data preservation method according to claim 3, wherein: The step of determining the task status of the executed target program task based on the state variable also includes: In the case where one target program task corresponds to one state variable, if each of the state variables represents an end state, it is determined that the task state of each of the target program tasks is execution completion; If there is a state variable representing the execution state, it is determined that there is a target program task whose task state is being executed.
6. The power-off data preservation method according to claim 3, wherein: The power-off data preservation method further comprises: monitoring the control variable; The calling and execution of the program task is controlled based on the control variable, and the state variable is updated based on the execution status of the program task.
7. The power-off data preservation method according to claim 6, wherein: The step of calling and executing the program task based on the control variable control also includes: If the control variable is in a stopped state, then the calling and executing of new program tasks is stopped; If the control variable is in an enabling state, the program task is executed based on a preset execution cycle.
8. The power-off data preservation method according to claim 6, wherein: The step of updating the state variable based on the execution status of the program task includes: In the case where the state variable represents the overall execution state of each target program task, for any target program task, when the target program task starts to be executed, the state variable is increased by a preset value; When the target program task is executed, the state variable is subtracted from a preset value.
9. The power-off data preservation method according to claim 6, wherein: The step of updating the state variable based on the execution status of the program task also includes: In the case where a target program task corresponds to a state variable, for any target program task, when the target program task starts to be executed, the state variable corresponding to the target program task is updated to represent the execution state; When the target program task is executed, the state variable corresponding to the target program task is updated to represent the end state.
10. The power-off data preservation method according to any one of claims 1 to 9, wherein: The power-off data is generated when the application is running, and the power-off data saving method further includes: During the application compilation process, for any power-off data to be generated during the running of the application, a program task corresponding to the power-off data is generated; Generate control variables used to control the execution of each program task call.
11. A power-off data storage device, wherein: Applied to a power-off device, the power-off device includes a volatile storage area and a non-volatile storage area, and the power-off data storage device includes: The stop module is used to stop calling new program tasks if the power-off device receives a power-off signal; The saving module is used to determine the task status of the executed target program tasks, and if the task status of each target program task is execution completion, save the power-off data corresponding to the target program task from the volatile storage area to the non-volatile storage area.
12. A power-off data storage device, wherein: The power-off data preservation device comprises: a memory, a processor, and a power-off data preservation program stored in the memory and executable on the processor. When the power-off data preservation program is executed by the processor, the steps of the power-off data preservation method according to any one of claims 1 to 10 are implemented.
13. A readable storage medium, wherein: The readable storage medium is a computer-readable storage medium, and a power-off data preservation program is stored on the readable storage medium. When the power-off data preservation program is executed by a processor, the steps of the power-off data preservation method according to any one of claims 1 to 10 are implemented.
Citation Information
Patent Citations
Controller and power fail safeguard method
CN103345189A
Power-down data storage and recovery algorithm prolonging service life of non-volatile memory
CN104317671A
Power failure protection device and method for storage server
CN115833354A
Power failure data storage method, device and equipment and readable storage medium
CN117707853A
Electronic control unit and electronic control system
US20230027587A1