Method and system for recovering program entering error state

By adopting instructions redundancy, software traps and program passwords in industrial automatic control programs, the program error state recovery problem caused by external interference is solved, and the effect of high reliability and rapid recovery is achieved.

CN119847803APending Publication Date: 2025-04-18ZHEJIANG SUPCON RES +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411910150.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-24
Publication Date
2025-04-18

AI Technical Summary

Technical Problem

In an industrial automatic control environment, external interference causes the CPU to receive error data or the PC pointer to fly away from the normal path, causing the program to enter an error state, which makes it difficult for the existing technology to effectively restore.

Method used

Using a combination of instruction redundancy, software traps and program passwords, the program is restored to the previous stable state by inserting blank instructions and software collapse into the program's modular control subroutine, and the subroutine ID is used to perform error detection and failure mode switching.

Benefits of technology

It effectively improves the reliability of the program in complex electromagnetic environments, can quickly capture and restore error states caused by external interference, and reduce production losses and downtime.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119847803A_ABST
    Figure CN119847803A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of program recovery, and provides a method for recovering a program entering an error state, which comprises the following steps of: S1, modularizing an industrial automatic control program, and adding a blank instruction and software collapse behind a breakpoint of each control subprogram and in a blank program area; s2, distributing a different sub-program ID to each control sub-program as a program password; s3, in the program execution process, starting the control subprograms with the subprogram IDs being n according to the sequence, when error data including operands and instruction codes are received, enabling the program to enter a fault mode through a blank instruction and software collapse, or when displacement of a PC pointer is detected, enabling the program to enter the fault mode through software collapse or directly entering the fault mode; the fault mode restores all the data into the state when the last control subprogram is executed. According to the technical scheme, a method of combining instruction redundancy, a software trap and a program password is adopted, so that the program is recovered when entering an error state.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of program recovery, and in particular to a method and system for recovering a program from an error state. Background Art

[0002] With the rapid development of industrial automatic control technology, automated equipment has gradually replaced manual operation. However, due to insufficient awareness of reliability, accidents are common, and the reliability of the control system is particularly important. Reliability is mainly divided into hardware and software reliability. Hardware reliability is mainly reflected in the selection of components and PCB layout, while software reliability is mainly reflected in reducing the number of problems and quickly returning to normal after the program has problems.

[0003] The present invention is mainly aimed at innovating software reliability. Assuming that the program itself has no bugs, the program may enter an error state due to two reasons: (1) Due to external interference, the CPU receives incorrect data, which causes the program to be unable to recognize the correct operands and instruction codes, and the entire program fails. The causes of this error include: The impact of electromagnetic interference on data transmission: In the industrial automatic control environment, there are a large number of electromagnetic devices and signals, which will generate electromagnetic interference. When the CPU receives data through the data bus, electromagnetic interference may change the state of the electrical signal on the data line. For example, a specific voltage value combination that originally represents a certain operand or instruction code may be changed by interference, causing the CPU to receive an incorrect data pattern. This erroneous data does not conform to the operand and instruction code format expected by the program, resulting in the program being unable to correctly recognize it.

[0004] Impact of interference on storage units: External interference may also affect storage units (such as memory or cache) that store operands and instruction codes. The data in the storage unit is stored in binary form, and 0 and 1 are represented by different states of electrical signals. Interference may cause the electrical signals in the storage unit to flip, causing the stored data to change. When the program reads operands and instruction codes from the storage unit, the data read is the data that has been changed by interference, and the correct content cannot be recognized.

[0005] Interference causes timing disorder: The operation of the computer system is carried out according to a strict timing. The reading of instructions, the acquisition of operands, and the execution of instructions all have a specific time sequence. External interference may affect the system's clock signal or other timing control signals. For example, interference may cause the clock signal to jitter, resulting in deviations in the reading of data and the execution of instructions. This timing disorder will cause the program to read data at the wrong time point, making it impossible to correctly identify operands and instruction codes, resulting in program errors.

[0006] (2) Due to CPU interference, the PC pointer may fly directly to another program segment or a blank segment, causing the program to fail to run normally. The reasons for this error include: The impact of electromagnetic interference on the PC pointer register: In a complex industrial environment, there are a large number of electromagnetic interference sources. These interferences may affect the normal operation of the PC pointer register. The PC pointer register is a key register that stores the current program execution location. When electromagnetic interference affects this register, the value in the register may be changed incorrectly. For example, electromagnetic interference may cause some bits in the register to flip, causing the pointer value that originally pointed to the correct program location to become the address of another program segment or a blank segment, causing the PC pointer to fly directly to the wrong location.

[0007] Abnormal instruction execution causes PC pointer to lose control: When the CPU receives an incorrect instruction code (possibly due to data errors caused by external interference), the execution process of the instruction may be abnormal. Some incorrect instructions may cause errors in the update of the PC pointer. For example, some illegal instructions may cause the PC pointer to perform some inappropriate jump operations instead of sequential or conditional jumps according to normal program logic. This incorrect update of the PC pointer caused by abnormal instruction execution will cause the PC pointer to fly to another program segment or a blank segment, which will cause the program to fail to proceed normally.

[0008] The impact of system timing disorder on PC pointer: The normal operation of computer system depends on accurate timing control. If the system is disturbed and the timing is disordered, the update of PC pointer will also be affected. For example, under normal circumstances, PC pointer will be updated according to the type of instruction and execution result after each instruction cycle. But if the timing is disordered, it may cause PC pointer to be updated at the wrong time point, or the updated value is wrong. This incorrect update of PC pointer due to timing disorder may cause PC pointer to jump to the wrong program segment or blank segment, thus affecting the normal operation of the program. Summary of the invention

[0009] In view of the above problems, the purpose of the present invention is to provide a method and system for recovering a program from an error state, which uses a method combining instruction redundancy, software traps and program passwords to recover a program from an error state.

[0010] The above-mentioned object of the present invention is achieved through the following technical solutions: A method for recovering a program from an error state, comprising the following steps: S1: Modularize the program of industrial automatic control, add blank instructions and software collapse after the breakpoint of each control subroutine and in the blank program area; S2: assigning a different subprogram ID as a program password to each of the control subprograms; S3: During the execution of the program, the control subroutine with the subroutine ID of n is started in sequence. When error data including operands and instruction codes are received, the program enters a fault mode through the blank instruction and the software collapse, or when a PC pointer shift is detected, the software collapse is performed or the fault mode is directly entered. The fault mode restores all data to the state when the previous control subroutine is executed.

[0011] Furthermore, it is characterized in that, in step S1, the blank instruction is specifically: The blank instruction is inserted after each of the control subroutines, and when the operands and the instruction codes cannot be recognized normally, the program is provided with an opportunity to readjust and correctly recognize the operands and the instruction codes.

[0012] Furthermore, in step S1, the software collapses, specifically: The software collapse is used to capture the erroneously executed program when the operand and the instruction code cannot be correctly identified and when the PC pointer is shifted, so that the program jumps to the fault mode for execution.

[0013] Furthermore, in step S2, a different subprogram ID is assigned to each control subprogram as the program password, specifically: Each of the control subroutines performs only one function and has only one exit; Setting up a register of the subprogram ID, and assigning a different subprogram ID to each control subprogram; After each control subroutine is executed, the current subroutine ID is returned and compared with the subroutine ID in the register. If they are the same, the next subroutine ID is executed. If they are different, the program jumps to the fault mode for execution.

[0014] Further, in step S3, when receiving error data including operands and instruction codes, the program enters a fault mode through the blank instruction and the software collapse, specifically: Starting the control subroutine with the subroutine ID being n, and determining whether the error data including the operand and the instruction code is received; If the error data is received, when it is determined that the operation code and the instruction code cannot be correctly identified, the error information is captured by the software collapse after the control subroutine, and the error mode is jumped to; If the error data is not received, the control subroutine is run normally, and after the control subroutine is finished running, the next control subroutine is jumped to for execution.

[0015] Further, in step S3, when the PC pointer is detected to be shifted, the software collapses or directly enters the fault mode, specifically: Start the control subroutine with the subroutine ID n, and determine whether the PC pointer shifts into a blank segment; If it is determined that the PC pointer has shifted into a blank segment, the shifted PC pointer is captured by the software collapse after the control subroutine, and the fault mode is entered; If it is determined that the PC pointer has not shifted into the blank segment, the control subroutine is run normally, and after the control subroutine is finished running, the subroutine ID of the running control subroutine is compared with the subroutine ID stored in the register. When the subroutine IDs are consistent, the current control subroutine is finished and the next control subroutine is executed. When the subroutine IDs are inconsistent, the program jumps directly to the fault mode for execution.

[0016] Further, in step S3, the fault mode restores all data to the state when the last control subroutine is executed, specifically: After each execution of the control subroutine, the data after the execution is stored in the register. If the fault mode is not called when the control subroutine is executed next time, the data stored in the register will be updated. Otherwise, if the fault mode is called when the control subroutine is executed next time or after the execution is completed, the data in the register will be used to reassign it.

[0017] A system for recovering from a program entering an error state for executing the method for recovering from a program entering an error state as described above, comprising: Program modularization module, used to modularize the program of industrial automatic control, adding blank instructions and software collapse after the breakpoint of each control subroutine and in the blank program area; A program password allocation module, used for allocating a different subprogram ID as a program password to each of the control subprograms; A program execution module is used to start the control subroutine with the subroutine ID n in sequence during the program execution process, and when receiving erroneous data including operands and instruction codes, the program enters a fault mode through the blank instruction and the software collapse, or when a PC pointer shift is detected, the software collapse is performed or the fault mode is directly entered, and the fault mode restores all data to the state when the previous control subroutine is executed.

[0018] A computer device comprises a memory and one or more processors, wherein the memory stores computer codes, and when the computer codes are executed by the one or more processors, the one or more processors execute the above method.

[0019] A computer-readable storage medium stores computer codes. When the computer codes are executed, the method described above is executed.

[0020] Compared with the prior art, the present invention has at least one of the following beneficial effects: (1) A method for recovering a program from an error state is provided, comprising: S1: modularizing the program of industrial automatic control, adding blank instructions and software collapse after the breakpoint of each control subroutine and in the blank program area; S2: assigning a different subroutine ID to each control subroutine as a program password; S3: during the execution of the program, starting the control subroutine with the subroutine ID n in sequence, and when receiving error data including operands and instruction codes, the program enters a fault mode through the blank instructions and the software collapse, or when a PC pointer shift is detected, the program enters the fault mode through the software collapse or directly enters the fault mode, and the fault mode restores all data to the state when the previous control subroutine is executed. The above technical solution adopts a method combining instruction redundancy, software traps and program passwords to recover the program from an error state.

[0021] (2) By adding blank instructions after the breakpoint of the control subroutine and in the blank program area, it can effectively provide buffer time and error correction opportunities when facing situations such as transient electromagnetic interference that may cause instruction and operand recognition errors. For example, in an industrial automation production line, the precise control program of the motor may have instruction code or operand reading errors due to electromagnetic pulse interference generated by the start and stop of nearby large equipment. The existence of blank instructions allows the processor to have additional clock cycles to stabilize the signal and re-identify the instructions and operands correctly, thereby avoiding the entire program crashing or generating erroneous control signals due to small interference, greatly improving the reliability of the program running in complex electromagnetic environments.

[0022] (3) Software traps are placed at specific locations to effectively capture PC pointers that have run away. In automated control systems, due to the large size of the code and the long running time, minor loopholes in memory management or data processing may cause the PC pointer to deviate from the normal execution path. Software traps are like safety nets. Once the PC pointer "runs away" and enters an area where a trap is set (such as after a subroutine breakpoint or a blank program area), it can be quickly pulled back to the normal program flow or guided to fault handling mode, preventing the program from falling into chaos or an infinite loop due to PC pointer errors, thus ensuring that the program runs stably for a long time.

[0023] (4) Assign a unique subroutine ID as the program password to each control subroutine, so that the execution path of the program can be accurately monitored during the program execution. When an abnormality occurs during program operation, by comparing the current subroutine ID with the ID stored in the register, it can be quickly determined whether the PC pointer has flown to the wrong subroutine. For example, in a complex automated assembly production line control system, it contains multiple subroutines with different functions, such as part grabbing subroutines, part assembly subroutines, quality inspection subroutines, etc. If an error occurs during the execution of the quality inspection subroutine and the ID detection finds that the PC pointer has flown to the part grabbing subroutine, the error can be quickly located in the program flow jump link, which helps developers quickly find the root cause of the error and improves the efficiency of error detection and location.

[0024] (5) When the program enters the fault mode, all data can be restored to the state when the previous control subroutine was executed. This is particularly important in industrial automation control because many industrial production processes are continuous and related. For example, in the automation control system of the chemical production process, if an error occurs in a subroutine during execution, the fault mode can restore the relevant data (such as the recorded data of reaction temperature, pressure, material flow and other parameters) to the state when the previous stable subroutine was executed, avoiding the loss of control of the entire production process or the generation of a large amount of waste due to errors. After the error occurs, the system can quickly recover to a relatively safe and restartable state, reducing production losses and downtime caused by errors, and improving production efficiency and economic benefits. BRIEF DESCRIPTION OF THE DRAWINGS

[0025] Figure 1 The overall flow chart of the method for recovering from an error state of a program of the present invention; Figure 2 It is a schematic diagram of the modularization of the program of the present invention; Figure 3 This is a processing flow chart of the present invention when receiving erroneous data; Figure 4 It is a processing flow chart when the PC pointer flies away of the present invention; Figure 5 The overall structural diagram of the system for recovering from an error state when the program of the present invention enters the error state. DETAILED DESCRIPTION

[0026] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0027] Those skilled in the art will appreciate that, unless otherwise stated, the singular forms "a", "an", "said" and "the" used herein may also include plural forms. It should be further understood that the term "comprising" used in the specification of the present invention refers to the presence of the features, integers, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or groups thereof.

[0028] First embodiment like Figure 1 As shown, this embodiment provides a method for recovering a program from an error state, comprising the following steps: S1: Modularize the program of industrial automatic control, add blank instructions and software collapse after the breakpoint of each control subroutine and in the blank program area.

[0029] like Figure 2 As shown, in this embodiment, blank instructions and software traps are added after the breakpoint of each control subroutine and in the blank program area. After the subroutine is run normally, it will jump to another subroutine through instructions. If wrong data is received, the program cannot recognize the correct operands and instruction codes, which will cause the jump failure. Then the program continues to run, and the blank instructions enable the program to recognize the operands and instruction codes normally again, and then the software trap is used to make the program jump to the fault mode.

[0030] Examples of blank instructions and software collapse formats are as follows: NOP NOP NOP JMP ERROR For blank instructions, the blank instructions are inserted after each of the control subroutines. When the operands and the instruction codes cannot be recognized normally, the program is given an opportunity to readjust and correctly recognize the operands and the instruction codes.

[0031] Definition: Blank instructions are special instructions inserted into the program instruction sequence. They have no actual operating function in the normal program logic execution and are usually some empty operation (NOP, No-Operation) instructions.

[0032] Working principle: In the instruction redundancy method, the problem is solved by inserting several blank instructions before the normal instructions. For example, when the program has errors in operand and instruction code recognition due to some interference, these additional blank instructions can act as a buffer. It is like setting a buffer before a road (instruction sequence) prone to errors, giving the program a chance to readjust before executing the key instructions, so that the program can recognize the operand and instruction code normally again.

[0033] Example: In assembly language, the NOP instruction is a typical blank instruction. It does not perform any actual arithmetic, logic or data transfer operations, but only takes up one instruction cycle. In many microprocessor architectures, the machine code format of the NOP instruction is fixed. For example, in some 8-bit microcontrollers, the machine code of the NOP instruction may be 0x00. When these NOP instructions are inserted before critical instructions, even if there is a small deviation in program execution, there is a chance to restore the normal execution order when the critical instruction is executed.

[0034] Setting a blank instruction also has the following benefits: (1) Time buffer angle Computers execute instructions in a certain clock cycle. When blank instructions (such as NOP instructions) are inserted, it is equivalent to adding extra clock cycles to the normal instruction sequence. It is like a busy production line where each process (instruction) is closely connected, but there is a little confusion. Inserting blank instructions is like adding some waiting time between processes.

[0035] For example, in a microprocessor, the reading, decoding and execution of instructions have strict timing. If the operands and instruction codes cannot be correctly identified at the normal timing due to some interference (such as electromagnetic interference causing signal delays or errors), these extra blank instruction cycles can give the system time to stabilize the signal and resynchronize, so that the next normal instruction can be read and decoded at the correct timing, and then the operands and instruction codes can be correctly identified.

[0036] (2) Instruction sequence to adjust the angle From the perspective of the instruction pipeline, modern processors usually use instruction pipeline technology to improve execution efficiency. Ideally, instructions can flow smoothly through various stages (such as instruction fetch, decoding, execution, etc.) like products on the pipeline. However, when errors occur, the instruction pipeline may be blocked or erroneous instructions may enter the pipeline early.

[0037] Inserting blank instructions changes the layout of the instruction sequence. Suppose the original instruction sequence has confused the boundaries between the instruction code and the operand due to an error, just like the layout of the text in a book is messed up. After inserting blank instructions, it is equivalent to inserting some blank pages between the messed up text, and re-dividing the boundaries of the instructions. This allows the processor to have the opportunity to re-determine the correct instruction code and operand position when it starts reading instructions again, and restore the normal instruction pipeline process.

[0038] (3) Signal interference recovery angle When the program is subject to external interference (such as electromagnetic interference, power fluctuations, etc.), the instruction code and operand signals stored in the memory or register may change. These changes may cause the instruction decoding unit to be unable to correctly recognize them.

[0039] The insertion of blank instructions can be seen as a means of self-healing the system. This is because during the execution of blank instructions, the hardware circuits (such as memory controllers, instruction decoders, etc.) have the opportunity to correct the erroneous signal state caused by previous interference. For example, some storage units may be in an unstable intermediate state due to interference. During the execution of blank instructions, the circuit can restore these storage units to the correct state through internal error correction mechanisms (such as refresh circuits, signal reconstruction, etc.), so that subsequent instructions can be correctly recognized.

[0040] As for software collapse, the software collapse is used to capture the erroneously executed program when the operand and the instruction code cannot be correctly identified and when the PC pointer is shifted, so that the program jumps to the fault mode for execution.

[0041] Definition: A software trap is a mechanism used to capture program counter (PC) pointer exceptions. When the PC pointer "runs away" due to interference, erroneous jumps, etc., that is, deviates from the normal program execution path, the software trap can capture the PC pointer.

[0042] How it works: Software traps are usually placed in blank areas of a program or after breakpoints in a subroutine. These traps are essentially special instruction sequences that trigger when the PC pointer accidentally enters these areas. Once triggered, the software trap redirects the PC pointer back to the normal execution of the program, just like setting some traps in the "wilderness" of the program (blank areas or unexpected execution areas). When the execution flow of the program breaks into these areas like a lost animal (a running PC pointer), the trap will catch it and bring it back to the right path (normal program).

[0043] Example: Assume that in a simple embedded C program, there is a memory area that is used to store data instead of executable code. To prevent the PC pointer from accidentally jumping to this data area, we can place a software trap at the beginning of this data area. This software trap may be a jump instruction. When the PC pointer jumps to this data area (i.e., triggers the software trap), the jump instruction will transfer the PC pointer to a special error handling routine or the reset entry point of the program, thereby preventing the program from crashing or generating unpredictable behavior due to incorrect execution.

[0044] S2: Allocate a different subprogram ID as a program password to each of the control subprograms.

[0045] In this embodiment, step S2 is specifically as follows: each of the control subroutines executes only one function and has only one exit; a register for the subroutine ID is set up, and a different subroutine ID is assigned to each of the control subroutines; when each of the control subroutines is executed, the current subroutine ID is returned and compared with the subroutine ID in the register, if they are the same, the next subroutine ID is executed, if they are different, the program jumps to the fault mode execution.

[0046] Each control subroutine performs only one function and has only one exit. This design principle greatly simplifies the logical structure and process control of the program. From a functional perspective, for example, in the control system of an automated packaging production line, there may be a "carton forming" control subroutine whose only function is to fold flat carton materials into a carton of a predetermined shape. This single-function design allows the code inside the subroutine to focus on achieving this specific task, avoiding the mixing of functions and code redundancy.

[0047] Having only one exit ensures the certainty of the program execution path. In the "Carton Forming" subroutine, no matter what situation is encountered during the execution (such as normal completion of folding, detection of material abnormalities, etc.), it will eventually return to the main program or the next related subroutine through a single exit. This makes it easier to debug and maintain the program, because developers can clearly track the execution flow of the program, and when problems arise, they can quickly locate the possible error location. For example, if it is found that the shape of the packaged carton does not meet the requirements, knowing that the "Carton Forming" subroutine has only one exit, developers can focus on checking the code logic inside the subroutine without having to perform complex troubleshooting at multiple possible exits.

[0048] Setting up a register specifically for storing subroutine IDs is a key part of the entire error detection and recovery mechanism. In industrial automation control systems, there are usually many control subroutines with different functions, such as the "carton forming", "article filling", "box sealing" and other subroutines in the packaging production line mentioned above. Assigning a unique ID to each such control subroutine is like giving each subroutine a unique identity.

[0049] For example, we can assign ID 10 to the "carton forming" subroutine, ID 20 to the "article filling" subroutine, ID 30 to the "carton sealing" subroutine, etc. These IDs are stored in the subroutine ID register as an important reference during program execution. When the main program calls these subroutines in sequence according to the production process, the ID information in this register can accurately know which subroutine should be executed and which subroutines have been executed, thereby effectively managing the execution order and logic of the entire program.

[0050] When each control subroutine is executed, the ID of the current subroutine is returned and compared with the ID in the register. This comparison operation is the core step to detect whether the program has an abnormal jump (such as a PC pointer error). Taking the packaging production line as an example, if the ID returned after the "item filling" subroutine is executed is 20, which is consistent with the ID 20 of the "item filling" subroutine that should be executed currently stored in the register, then it means that the program is executed according to the normal process, and the PC pointer has not "flew" to other subroutines. At this time, the next scheduled subroutine can be smoothly executed, such as the "box sealing" subroutine.

[0051] However, if the returned ID is not the same as the ID in the register, for example, the returned ID is 10 (the ID of the "carton forming" subroutine), this indicates that the program is abnormal. It may be due to electromagnetic interference, memory errors, etc. that the PC pointer mistakenly jumps to the "carton forming" subroutine instead of continuing to execute the "carton sealing" subroutine according to the normal process. In this case, the program will immediately jump to the fault mode execution. The fault mode will take a series of pre-set measures, such as recording error information, trying to restore data to the last stable state, etc., to minimize the impact of the error on the entire industrial automation production process, ensure the safety and stability of the production line, and provide strong support for subsequent troubleshooting and repair.

[0052] S3: During the execution of the program, the control subroutine with the subroutine ID of n is started in sequence. When error data including operands and instruction codes are received, the program enters a fault mode through the blank instruction and the software collapse, or when a PC pointer shift is detected, the software collapse is performed or the fault mode is directly entered. The fault mode restores all data to the state when the previous control subroutine is executed.

[0053] In this embodiment, if Figure 3 As shown, when receiving erroneous data including operands and instruction codes, the program enters a fault mode through the blank instruction and the software collapse, specifically: Starting the control subroutine with the subroutine ID being n, and determining whether the error data including the operand and the instruction code is received; If the error data is received, when it is determined that the operation code and the instruction code cannot be correctly identified, the error information is captured by the software collapse after the control subroutine, and the error mode is jumped to; If the error data is not received, the control subroutine is run normally, and after the control subroutine is finished running, the next control subroutine is jumped to for execution.

[0054] In this embodiment, if Figure 4 As shown, when the PC pointer is detected to be shifted, the software collapses or directly enters the fault mode, specifically: Start the control subroutine with the subroutine ID n, and determine whether the PC pointer shifts into a blank segment; If it is determined that the PC pointer has shifted into a blank segment, the shifted PC pointer is captured by the software collapse after the control subroutine, and the fault mode is entered; If it is determined that the PC pointer has not shifted into the blank segment, the control subroutine is run normally, and after the control subroutine is finished running, the subroutine ID of the running control subroutine is compared with the subroutine ID stored in the register. When the subroutine IDs are consistent, the current control subroutine is finished and the next control subroutine is executed. When the subroutine IDs are inconsistent, the program jumps directly to the fault mode for execution.

[0055] Further, in step S3, the fault mode restores all data to the state when the last control subroutine is executed, specifically: After each execution of the control subroutine, the data after the execution is stored in the register. If the fault mode is not called when the control subroutine is executed next time, the data stored in the register will be updated. Otherwise, if the fault mode is called when the control subroutine is executed next time or after the execution is completed, the data in the register will be reassigned and the control subroutine corresponding to the subroutine ID in the register will be re-executed.

[0056] Second embodiment like Figure 5 As shown, this embodiment provides a system for recovering from a program entering an error state for executing the method for recovering from a program entering an error state in the first embodiment, comprising: Program modularization module 1 is used to modularize the program of industrial automatic control, and add blank instructions and software collapse after the breakpoint of each control subroutine and in the blank program area; A program password allocation module 2, used for allocating a different subprogram ID as a program password to each of the control subprograms; The program execution module 3 is used to start the control subroutine with the subroutine ID n in sequence during the program execution process, and when receiving erroneous data including operands and instruction codes, the program enters the fault mode through the blank instruction and the software collapse, or when the PC pointer shift is detected, the software collapse is performed or the fault mode is directly entered, and the fault mode restores all data to the state when the previous control subroutine is executed.

[0057] A computer-readable storage medium stores computer code. When the computer code is executed, the above method is executed. A person skilled in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by instructing related hardware through a program. The program can be stored in a computer-readable storage medium. The storage medium can include: a read-only memory (ROM), a random access memory (RAM), a disk or an optical disk, etc.

[0058] The above is only a preferred embodiment of the present invention, and the protection scope of the present invention is not limited to the above embodiments. All technical solutions under the concept of the present invention belong to the protection scope of the present invention. It should be pointed out that for ordinary technicians in this technical field, some improvements and modifications without departing from the principle of the present invention should also be regarded as the protection scope of the present invention.

[0059] The technical features of the above-described embodiments may be arbitrarily combined. To make the description concise, not all possible combinations of the technical features in the above-described embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0060] It should be noted that the above embodiments can be freely combined as needed. The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principle of the present invention, and these improvements and modifications should also be considered as the protection scope of the present invention.

Claims

1. A method for recovering a program from an error state, characterized in that: The following steps are involved: S1: Modularize the program of industrial automatic control, add blank instructions and software collapse after the breakpoint of each control subroutine and in the blank program area; S2: assigning a different subprogram ID as a program password to each of the control subprograms; S3: During the execution of the program, the control subroutine with the subroutine ID of n is started in sequence. When error data including operands and instruction codes are received, the program enters a fault mode through the blank instruction and the software collapse, or when a PC pointer shift is detected, the software collapse is performed or the fault mode is directly entered. The fault mode restores all data to the state when the previous control subroutine is executed.

2. The method for recovering from a program entering an error state according to claim 1, characterized in that: In step S1, the blank instruction is specifically: The blank instruction is inserted after each of the control subroutines, and when the operands and the instruction codes cannot be recognized normally, the program is provided with an opportunity to readjust and correctly recognize the operands and the instruction codes.

3. The method for recovering from a program entering an error state according to claim 1, characterized in that: In step S1, the software collapses, specifically: The software collapse is used to capture the erroneously executed program when the operand and the instruction code cannot be correctly identified and when the PC pointer is shifted, so that the program jumps to the fault mode for execution.

4. The method for recovering from a program entering an error state according to claim 1, characterized in that: In step S2, a different subprogram ID is assigned to each control subprogram as the program password, specifically: Each of the control subroutines performs only one function and has only one exit; Setting up a register of the subprogram ID, and assigning a different subprogram ID to each control subprogram; After each control subroutine is executed, the current subroutine ID is returned and compared with the subroutine ID in the register. If they are the same, the next subroutine ID is executed. If they are different, the program jumps to the fault mode for execution.

5. The method for recovering from a program entering an error state according to claim 1, characterized in that: In step S3, when receiving error data including operands and instruction codes, the program enters a fault mode through the blank instruction and the software collapse, specifically: Starting the control subroutine with the subroutine ID being n, and determining whether the error data including the operand and the instruction code is received; If the error data is received, when it is determined that the operation code and the instruction code cannot be correctly identified, the error information is captured by the software collapse after the control subroutine, and the error mode is jumped to; If the error data is not received, the control subroutine is run normally, and after the control subroutine is finished running, the next control subroutine is jumped to for execution.

6. The method for recovering from a program entering an error state according to claim 4, characterized in that: In step S3, when the PC pointer is detected to be shifted, the software collapses or directly enters the fault mode, specifically: Start the control subroutine with the subroutine ID n, and determine whether the PC pointer shifts into a blank segment; If it is determined that the PC pointer has shifted into a blank segment, the shifted PC pointer is captured by the software collapse after the control subroutine, and the fault mode is entered; If it is determined that the PC pointer has not shifted into the blank segment, the control subroutine is run normally, and after the control subroutine is finished running, the subroutine ID of the running control subroutine is compared with the subroutine ID stored in the register. When the subroutine IDs are consistent, the current control subroutine is finished and the next control subroutine is executed. When the subroutine IDs are inconsistent, the program jumps directly to the fault mode for execution.

7. The method for recovering from a program entering an error state according to claim 1, characterized in that: In step S3, the fault mode restores all data to the state when the last control subroutine is executed, specifically: After each execution of the control subroutine, the data after the execution is stored in the register. If the fault mode is not called when the control subroutine is executed next time, the data stored in the register will be updated. Otherwise, if the fault mode is called when the control subroutine is executed next time or after the execution is completed, the data in the register will be used to reassign it.

8. A system for recovering from a program entering an error state for executing the method for recovering from a program entering an error state as claimed in any one of claims 1 to 7, characterized in that: include: Program modularization module, used to modularize the program of industrial automatic control, adding blank instructions and software collapse after the breakpoint of each control subroutine and in the blank program area; A program password allocation module, used for allocating a different subprogram ID as a program password to each of the control subprograms; A program execution module is used to start the control subroutine with the subroutine ID n in sequence during the program execution process, and when receiving erroneous data including operands and instruction codes, the program enters a fault mode through the blank instruction and the software collapse, or when a PC pointer shift is detected, the software collapse is performed or the fault mode is directly entered, and the fault mode restores all data to the state when the previous control subroutine is executed.

9. A computer device comprising a memory and one or more processors, wherein the memory stores computer codes, and when the computer codes are executed by the one or more processors, the one or more processors execute the method according to any one of claims 1 to 7. 10 . A computer-readable storage medium storing a computer code. When the computer code is executed, the method according to claim 1 is executed.