Detailed Description
In the following description, for purposes of explanation, numerous specific details are set forth in order to provide a thorough understanding of one or more embodiments. It may be evident, however, that such embodiment(s) may be practiced without these specific details. In other instances, well-known structures and devices are shown in block diagram form in order to facilitate describing one or more embodiments.
In order to describe the communication method and system with self-checking function in detail, embodiments of the present invention will be described in detail below with reference to the accompanying drawings.
Fig. 1 shows a flow of a communication method having a self-test function according to an embodiment of the present invention.
As shown in fig. 1, a communication method with a self-checking function according to an embodiment of the present invention includes:
s110: defining a communication protocol, including defining bytes, defining instructions consisting of bytes, and defining instruction sequences.
The definition instructions are provided with at least two groups, each group of definition instructions comprises at least one definition byte, one definition byte is 8 bits, namely 1byte is 8 bits, and the number of bytes (or definition bytes, the same below) in each definition instruction can be set by itself. And the order of the definition instructions comprises the sequential order of all the definition instructions.
S120: the execution end receives the instruction information sent by the control end and verifies the number of bytes received by the instruction information in the preset time.
The control end sends instruction information to the execution end through a defined communication protocol, and after the execution end receives the instruction information, the execution end firstly carries out byte check on the instruction information.
S130: when the number of bytes is less than a defined instruction, the execution end sends an error code to the control end; otherwise, performing defined instruction verification on the instruction information.
In the step, the execution end firstly verifies the number of bytes received by the instruction information within the preset time, if the number of bytes received within the preset time is less than one definition instruction, namely the number of bytes received within the preset time is less than the number of bytes contained in one definition instruction, the execution end returns an error code to the control end to inform the control end that interference is generated.
In an embodiment of the present invention, the time calculation formula of the execution end receiving a definition command is:
wherein t represents the time when the execution end receives a definition instruction; a represents the number of definition bytes contained in a definition instruction; 8 represents a definition byte 8 bits, the unit is bit; m represents communication rate or baud rate, the unit is bit, and the value range of m is 1200-115200.
In the transmission process of the instruction information, the information may be interfered by the outside, and the receiving time of the instruction is prolonged, and in order to ensure that the execution end can completely receive the instruction information sent by the control end and then judge, the preset time can be set to be not less than the time for the execution end to receive a defined instruction, namely the preset time is greater than t.
S140: when the instruction information does not belong to the defined instruction range, the execution end sends an error code to the control end; otherwise, checking the instruction information according to the defined instruction sequence.
When the number of bytes verified in step S130 satisfies the number of bytes of a defined instruction, further verifying the instruction information, and determining whether the instruction information belongs to the range of the defined instruction in the defined communication protocol, and when the instruction information does not belong to the range of the defined instruction, the execution end sending an error code to the control end; otherwise, checking the instruction information according to the defined instruction sequence.
S150: when the instruction information does not accord with the defined instruction sequence, the execution end sends an error code to the control end; otherwise, the execution end executes the instruction action sent by the control end.
When the instruction information verified in step S140 belongs to the defined instruction range, further determining a defined instruction sequence for the instruction information, and when the instruction information does not conform to the defined instruction sequence, sending an error code to the control end by the execution end; otherwise, the execution end responds to the instruction action sent by the control end.
In one embodiment of the invention, the communication protocol between the execution end and the control end is RS-232, RS-422 or RS-485.
The control terminal is a PC (personal computer) terminal, a control chip, or the like having a control capability, and the execution terminal is a test device, a detection device, an execution device, or the like.
As a specific example, four bytes (definition bytes) are defined as one instruction (definition instruction), and three instructions are defined at the same time, including definition instruction a, definition instruction B, and definition instruction C, and the definition instruction order is: define instruction A → define instruction B → define instruction C; the value of m is defined as 9600 in bit.
The time calculation formula of the execution end receiving a definition instruction is as follows:
where t is in ms.
And setting the preset time to be 10ms according to the time for the execution end to receive a definition command.
According to the above example, the process of performing self-checking on the instruction information sent by the control end by the execution end includes:
the method comprises the following steps: and the execution end receives the instruction information sent by the control end, checks the number of bytes received by the control end within 10ms, and if the number of bytes received within 10ms is less than 4, the execution end returns an error code to the control end to inform the control end that interference is generated. When the byte received within 10ms is equal to 4, step two is performed.
Step two: carrying out definition instruction verification on the instruction information, comparing the received instruction information with a definition instruction A, a definition instruction B and a definition instruction C respectively, and returning an error code to the control end to inform the control end of interference generation when the received instruction information does not belong to the range of the definition instruction A, the definition instruction B and the definition instruction C; otherwise, when the instruction information is the definition instruction A, the definition instruction B or the definition instruction C, the third step is executed.
Step three: checking the order of the definition instructions of the instruction information, for example, if the definition instruction which should be received currently is a and the instruction information is a definition instruction B, that is, the order of the current instruction information does not conform to the order of the definition instructions: when the instruction A → the instruction B → the instruction C is defined, an error code is returned to the control end to inform the control end of the interference generation; otherwise, the instruction information is correct, and the execution end executes the corresponding action according to the instruction information.
In the process of sending the instruction to the execution end, the control end may send a plurality of instruction information according to different execution actions, and after the instruction sequence is set, the execution end can be effectively prevented from responding to an error instruction.
Corresponding to the communication method with the self-checking function, the invention also provides a communication system with the self-checking function.
Specifically, fig. 3 shows a block configuration of a communication system having a self-test function according to an embodiment of the present invention.
As shown in fig. 3, the communication system 200 with self-checking function according to the embodiment of the present invention includes a control end 210, configured to send instruction information and control an action of an execution end through the instruction information; the execution end 230 is used for receiving the instruction information sent by the control end and completing corresponding execution actions according to the instruction information; the self-test unit 240 is located in the execution end 230, the self-test unit 240 is used for verifying instruction information sent by the control end, and when the instruction information is wrong, the execution end sends an error code to the control end; otherwise, the execution end executes the instruction action sent by the control end; and the data line 220 is used for connecting hardware between the control end and the execution end and transmitting instruction information sent by the control end.
Specifically, the self-test unit 240 further includes a byte check module, a defined instruction check module, and a defined instruction sequence check module.
The byte checking module is used for checking the number of bytes received by the instruction information within the preset time; when the number of bytes is less than a defined instruction, the execution end sends an error code to the control end; otherwise, performing defined instruction verification on the instruction information.
The defined instruction checking module is used for carrying out defined instruction checking on the instruction information checked by the byte checking module, and when the instruction information does not belong to the defined instruction range, the execution end sends an error code to the control end; otherwise, checking the instruction information according to the defined instruction sequence.
The defined instruction sequence checking module is used for checking the defined instruction sequence of the instruction information checked by the defined instruction checking module, and when the instruction information does not conform to the defined instruction sequence, the execution end sends an error code to the control end; otherwise, the execution end executes the instruction action sent by the control end.
The communication system with the self-checking function provided by the present invention corresponds to the communication method with the self-checking function, and the related contents may refer to the description in the embodiment of the communication method with the self-checking function, which is not repeated herein. For example, the control terminal is a terminal having control capability such as a PC terminal or a control chip, and the execution terminal is a test device, a detection device, or an execution device.
According to the communication method and the communication system with the self-checking function, provided by the invention, the interference signal is effectively shielded through the self-defined communication protocol, so that the problems of no response or disordered response of the execution end and the like caused by communication interference can be solved, and the effect of improving the stability and the accuracy of the execution end equipment is achieved.
The communication method and system having the self-checking function according to the present invention are described above by way of example with reference to the accompanying drawings. However, it should be understood by those skilled in the art that various modifications can be made to the communication method and system with self-checking function provided in the present invention without departing from the scope of the present invention. Therefore, the scope of the present invention should be determined by the contents of the appended claims.