Method for processing communication data between master machine and slave machine

By using duty cycle-based bit value identification and byte-level full frame verification in master-slave communication, the problem of signal immunity in serial communication under clock deviation is solved and the accuracy and compatibility of data transmission are improved. .

CN118826953APending Publication Date: 2024-10-22YIMOON(SHANGHAI) TECH CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202310928405.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-07-26
Publication Date
2024-10-22

AI Technical Summary

Technical Problem

When there is a deviation in the clocks of the master and slave devices, the signal immunity of the serial communication method is poor, resulting in a high probability of bit signal misreading, which in turn affects the accuracy of data verification and analysis, especially when the slave is low power consumption. equipment and relies on the host for power supply.

Method used

The 0/1 bit value identification method based on duty cycle is used to replace the traditional absolute bit signal amplitude identification, and after the slave sends the byte, the host sends a low-level signal to extend the byte interval, and uses byte-level full frame correction. Verification replaces bit-level verification, reducing communication processing difficulty and error rate.

Benefits of technology

It improves the bit signal error tolerance rate and data sending and receiving accuracy of the master and slave machines, reduces the data volume and verification complexity, and enhances device compatibility.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118826953A_ABST
    Figure CN118826953A_ABST
Patent Text Reader

Abstract

The embodiment of the invention relates to a method for processing communication data between a host and a slave. The method comprises the following steps: the host enters a host data sending stage after obtaining a host data frame; in the host data sending stage, a section of front high-level signal is firstly sent to the slave, then a host data frame is sent to the slave, and the slave data receiving stage is entered when the sending is finished; in the slave data receiving stage, slave bit signal receiving is carried out based on a waiting time window sliding mechanism, a section of interval low-level signal is sent to a slave every time receiving of byte data of the slave is completed, and a slave data analysis stage is entered when no slave bit signal is received in a waiting time window; and in a slave data analysis stage, performing format verification on the obtained slave data frame, and determining whether retransmission or normal processing is performed based on a verification result. According to the invention, the communication processing difficulty of the master and slave can be reduced, and the data transceiving accuracy of the master and slave is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of communication technology and data processing technology, and in particular to a communication data processing method between a master and a slave. Background Art

[0002] Conventional master-slave communication mostly uses serial communication protocol, and each time it is initiated by the master and responded by the slave. According to the principle of serial communication protocol, the sender uses the bit signal as the minimum signal unit to send a single byte (BYTE) or a multi-byte string, and the receiver uses the bit signal as the minimum signal unit to receive a single byte or a multi-byte string. If the bit signal is a high-level signal, the corresponding bit value is 1, and if the bit signal is a low-level signal, the corresponding bit value is 0; and in the process of sending and receiving a single byte or multiple bytes, it is necessary to set and check the corresponding start bit, data bit, end bit and check bit of each byte to ensure the correctness of data transmission and reception. This standard serial communication method will not cause any problems when the clock deviation between the master and slave devices is extremely small and the slave device is an independently powered device. However, when the slave device is a low-power device that requires power from the host, or when there is a certain deviation in the clocks of the master and slave devices, the following abnormal situations may occur: 1) The slave signal has poor anti-interference ability, and the bit signal often has insufficient amplitude, which will increase the probability of misreading the start, data, end or check bit of a single byte. If byte verification and data analysis are performed according to the standard serial communication method, the corresponding probability of verification and analysis failure will also increase; 2) The slave clock deviation is large, and the bit signal is prone to non-standard signal width, which will also increase the probability of misreading the start, data, end or check bit of a single byte. If byte verification and data analysis are performed according to the standard serial communication method, the corresponding probability of verification and analysis failure will also increase. Summary of the invention

[0003] The purpose of the present invention is to provide a communication data processing method between a master and a slave in view of the defects of the prior art; in the process of the bit signal communication between the master and the slave, the method replaces the traditional processing method of identifying the 0 / 1 bit value with the absolute bit signal amplitude by the processing method of identifying the 0 / 1 bit value based on the duty cycle, thereby improving the bit signal fault tolerance of the master and the slave; and after each byte is sent by the slave, the byte sending interval of the slave is extended by sending a fixed-length low-level signal from the host side, and the byte sending and receiving errors of the master and the slave are reduced by the speed reduction method, and the byte sending and receiving success rate of the master and the slave are improved; and the corresponding start, end and check bits are no longer set in each byte, but the traditional bit-level byte check method is replaced by the byte-level full-frame check method, thereby reducing the number of data sending and receiving, improving the sending and receiving efficiency, and reducing the check complexity without losing the data check function. The improved serial communication method provided by the method of the present invention can not only reduce the communication processing difficulty of the master and the slave, improve the data sending and receiving accuracy of the master and the slave, but also have better equipment compatibility.

[0004] To achieve the above object, an embodiment of the present invention provides a method for processing communication data between a master and a slave, the method comprising:

[0005] When the first host obtains the first host data frame sent to the first slave, the first host identifies whether the host communication working stage is in the host communication initial stage; if so, the host communication working stage is switched to the host data sending stage; the host communication working stage includes the host communication initial stage, the host data sending stage, the slave data receiving stage and the slave data parsing stage;

[0006] When the host communication working stage is the host data sending stage, the first host sends a high-level signal with a signal duration not less than a preset leading duration to the first slave; and when the high-level signal is sent, the first host data frame is sequentially divided into a plurality of first host byte data; and all the first host byte data are traversed in sequence; and when traversing, the first host byte data currently traversed is used as the corresponding current host byte data, and the current host byte data is sent in a single byte; and when the single byte sending is finished, whether the current host byte data is the last one of the first host byte data is identified; if not, the next first host byte data is switched to continue traversal; if so, the host communication working stage is switched to the slave data receiving stage;

[0007] When the host communication working stage is the slave data receiving stage, the first host uses the current time as the starting time and postpones a time period of the preset host waiting time as the corresponding current waiting time window, and receives the slave bit signal of the first slave within the current waiting time window. If a slave bit signal is received in the current waiting time window, the next slave bit signal is received with the current time as the new starting time and postponed by a time period of the preset host waiting time as the new current waiting time window. If a slave bit signal is not received within the current waiting time window, the host communication working stage is switched to the slave data parsing stage; and when each slave bit signal is received, the current slave bit signal is converted into a numerical data based on a preset 0 / 1 value high and low level duty cycle to obtain the corresponding first slave bit data; and eight consecutive first slave bit data are used to form a corresponding first slave byte data and save it; and when each first slave byte data is obtained, a low-level signal with a signal length not less than the preset byte interval length is sent to the first slave;

[0008] When the host communication working stage is the slave data parsing stage, the first host forms a corresponding first slave data frame with all the first slave byte data obtained; and performs data frame format verification on the first slave data frame to generate a corresponding first verification result; if the first verification result is a verification failure, the cumulative number of retransmissions begins to be counted and the host communication working stage is switched to the host data sending stage to retransmit the first host data frame until the count value of the cumulative number of retransmissions exceeds the preset maximum number of retransmissions; if the first verification result is a verification success, the first slave data frame is subjected to slave data processing and the host communication working stage is switched to the host communication initial stage.

[0009] The method further comprises:

[0010] When the first slave is in any stage of the slave communication working stage, once receiving a high-level signal with a signal duration of the preset leading time length sent by the first host, the slave communication working stage is switched to the host data receiving stage; the slave communication working stage includes a slave communication initial stage, a host data receiving stage, a master-slave data parsing and packaging stage, and a slave data sending stage;

[0011] When the slave communication working stage is the host data receiving stage, the first slave receives the host bit signal of the first host; and when each host bit signal is received, the current host bit signal is converted into numerical data based on the 0 / 1 value high and low level duty ratio to obtain the corresponding second host bit data; and eight consecutively obtained second host bit data form a corresponding second host byte data and save it; and identify whether the current second host byte data matches the preset frame header identifier, and if so, delete the other second host byte data before the current second host byte data; and identify whether the current second host byte data matches the preset frame end identifier, and if so, switch the slave communication working stage to the master-slave data parsing and encapsulation stage;

[0012] When the slave communication working stage is the master-slave data parsing and encapsulating stage, the first slave composes a corresponding second host data frame from all the obtained second host byte data; and performs a data frame format check on the second host data frame to generate a corresponding second check result; if the second check result is a check success, a return frame data preparation process is performed according to the second host data frame to obtain a corresponding second slave data frame, and the slave communication working stage is switched to the slave data sending stage; if the second check result is a check failure, the slave communication working stage is switched to the slave communication initial stage;

[0013] When the slave communication working stage is the slave data sending stage, the first slave sequentially divides the second slave data frame into multiple second slave byte data; and traverses all the second slave byte data in sequence; and when traversing, the second slave byte data currently traversed is used as the corresponding current slave byte data, and the current slave byte data is sent as a single byte; and when the single byte sending ends, it is identified whether the current slave byte data is the last second slave byte data; if not, after confirming that a low-level signal with a signal length of the preset byte interval length sent by the first host is received, it switches to the next second slave byte data to continue traversing; if so, the slave communication working stage is switched to the slave communication initial stage.

[0014] Preferably, the complete data format of any data frame should be a data sequence sequentially spliced ​​by the preset frame header identifier, parameter sequence length, data frame type, data frame parameter sequence, data frame check code and the preset frame tail identifier;

[0015] The data length of the frame header identifier is one byte;

[0016] The data length of the parameter sequence length is a preset first byte length;

[0017] The data length of the data frame type is one byte;

[0018] The data length of the data frame parameter sequence matches the corresponding parameter sequence length;

[0019] The data length of the data frame check code is a preset second byte length;

[0020] The data length of the frame tail identifier is one byte;

[0021] The data frame type includes a data type and an instruction type;

[0022] The data frame check code is check code data obtained by performing check code calculation on a data sequence formed by sequentially splicing the parameter sequence length, the data frame type and the data frame parameter sequence based on a preset check code algorithm.

[0023] Preferably, the sending of the current host byte data in single byte specifically includes:

[0024] Sequentially divide the current host byte data into a plurality of first host bit data;

[0025] All the first host bit data are sequentially traversed; and during the traversal, the first host bit data currently traversed is used as the corresponding current host bit data; and when the current host bit data is 0, a first host bit signal with a signal duration equal to the preset first bit signal duration and a high-low level duty ratio that satisfies the preset 0-value high-low level duty ratio is generated and sent to the first slave; and when the current host bit data is 1, a second host bit signal with a signal duration equal to the first bit signal duration and a high-low level duty ratio that satisfies the preset 1-value high-low level duty ratio is generated and sent to the first slave; the first and second host bit signals are both composed of a low-level signal starting with a falling edge and a subsequent high-level signal; the ratio of the high-level signal duration to the low-level signal duration in the first host bit signal satisfies the 0-value high-low level duty ratio; the ratio of the high-level signal duration to the low-level signal duration in the second host bit signal satisfies the 1-value high-low level duty ratio;

[0026] And at the end of the traversal, confirm that the single byte sending is completed.

[0027] Preferably, the converting the current slave bit signal into numerical data based on the preset 0 / 1 value high and low level duty ratio to obtain the corresponding first slave bit data specifically includes:

[0028] Detecting the duration of the low-level signal in the current slave bit signal to obtain a corresponding first low-level duration; and detecting the duration of the high-level signal in the current slave bit signal to obtain a corresponding first high-level duration; and using the ratio of the first high-level duration to the first low-level duration as the corresponding first high-low level duty ratio;

[0029] If the absolute difference between the first high-low level duty cycle and the preset 1-value high-low level duty cycle is smaller than a preset small duty cycle difference threshold, the corresponding first slave bit data is set to 1;

[0030] If the absolute difference between the first high-low level duty cycle and the preset high-low level duty cycle of 0 is smaller than the small duty cycle difference threshold, the corresponding first slave bit data is set to 0.

[0031] Preferably, performing data frame format verification on the first slave data frame to generate a corresponding first verification result specifically includes:

[0032] Using the first byte of the first slave data frame as the corresponding first frame header;

[0033] Using the last byte of the first slave data frame as the corresponding first frame tail;

[0034] Taking the sub-data segment in the first slave data frame whose starting position is the next byte position of the first frame header and whose data length is the first byte length as the corresponding first parameter sequence length;

[0035] Using the next byte of the first parameter sequence length in the first slave data frame as the corresponding first data frame type;

[0036] Using the sub-data segment in the first slave data frame whose end position is the previous byte position of the first frame tail and whose data length is the second byte length as the corresponding first data frame check code;

[0037] Taking the sub-data segment in the first slave data frame whose starting position is the next byte position of the first data frame type and whose ending position is the previous byte position of the first data frame check code as the corresponding first data frame parameter sequence;

[0038] Identify whether the first frame header matches the preset frame header identifier; if so, set the corresponding first result as qualified, otherwise, set the corresponding first result as unqualified;

[0039] Identify whether the first frame end matches the preset frame end identifier; if so, set the corresponding second result as qualified, otherwise, set the corresponding second result as unqualified;

[0040] Identify whether the data length of the first data frame parameter sequence matches the length of the first parameter sequence; if so, set the corresponding third result as qualified, otherwise, set the corresponding third result as unqualified;

[0041] Identify whether the first data frame type is a data type or an instruction type; if so, set the corresponding fourth result as qualified, otherwise set the corresponding fourth result as unqualified;

[0042] The first parameter sequence length, the first data frame type and the first data frame parameter sequence are sequentially spliced ​​to obtain a corresponding first data sequence; and a check code is calculated on the first data sequence based on the check code algorithm to obtain a corresponding first check code; and whether the first check code matches the first data frame check code is identified; if so, the corresponding fifth result is set to be qualified, and otherwise, the corresponding fifth result is set to be unqualified;

[0043] Identify whether the first, second, third, fourth and fifth results are all qualified; if so, set the corresponding first verification result as verification success; if not, set the corresponding first verification result as verification failure.

[0044] Preferably, the converting the current host bit signal into numerical data based on the 0 / 1 value high and low level duty ratio to obtain the corresponding second host bit data specifically includes:

[0045] Detecting the duration of the low-level signal in the current host bit signal to obtain a corresponding second low-level duration; and detecting the duration of the high-level signal in the current host bit signal to obtain a corresponding second high-level duration; and using the ratio of the second high-level duration to the second low-level duration as the corresponding second high-low level duty ratio;

[0046] If the absolute difference between the second high-low level duty cycle and the preset 1-value high-low level duty cycle is less than a preset small duty cycle difference threshold, the corresponding second host bit data is set to 1;

[0047] If the absolute difference between the second high-low level duty cycle and the preset high-low level duty cycle of 0 is smaller than the small duty cycle difference threshold, the corresponding second host bit data is set to 0.

[0048] Preferably, performing data frame format verification on the second host data frame to generate a corresponding second verification result specifically includes:

[0049] Using the first byte of the second host data frame as the corresponding second frame header;

[0050] Using the last byte of the second host data frame as the corresponding second frame tail;

[0051] Taking the sub-data segment in the second host data frame whose starting position is the next byte position of the second frame header and whose data length is the first byte length as the corresponding second parameter sequence length;

[0052] Using the next byte of the second parameter sequence length in the second host data frame as the corresponding second data frame type;

[0053] Using the sub-data segment in the second host data frame whose end position is the previous byte position of the second frame tail and whose data length is the second byte length as the corresponding second data frame check code;

[0054] Taking the sub-data segment in the second host data frame whose starting position is the next byte position of the second data frame type and whose ending position is the previous byte position of the second data frame check code as the corresponding second data frame parameter sequence;

[0055] Identify whether the second frame header matches the preset frame header identifier; if so, set the corresponding sixth result as qualified, otherwise, set the corresponding sixth result as unqualified;

[0056] Identify whether the second frame end matches the preset frame end identifier; if so, set the corresponding seventh result as qualified, otherwise, set the corresponding seventh result as unqualified;

[0057] Identify whether the data length of the second data frame parameter sequence matches the length of the second parameter sequence; if so, set the corresponding eighth result as qualified, otherwise, set the corresponding eighth result as unqualified;

[0058] Identify whether the second data frame type is a data type or an instruction type; if so, set the corresponding ninth result as qualified, otherwise set the corresponding ninth result as unqualified;

[0059] The second parameter sequence length, the second data frame type and the second data frame parameter sequence are sequentially spliced ​​to obtain a corresponding second data sequence; and a check code is calculated on the second data sequence based on the check code algorithm to obtain a corresponding second check code; and whether the second check code matches the second data frame check code is identified; if so, the corresponding tenth result is set to be qualified, and otherwise, the corresponding tenth result is set to be unqualified;

[0060] Identify whether the sixth, seventh, eighth, ninth and tenth results are all qualified; if so, set the corresponding second verification result to successful verification; if not, set the corresponding second verification result to failed verification.

[0061] Preferably, performing return frame data preparation processing according to the second host data frame to obtain a corresponding second slave data frame specifically includes:

[0062] The second data frame type and the second data frame parameter sequence of the second host data frame are input into a preset host data processing interface for processing; and the data frame returned by the host data processing interface is used as the corresponding second slave data frame.

[0063] Preferably, the sending of the current slave byte data in single byte specifically includes:

[0064] Sequentially divide the current slave byte data into a plurality of second slave bit data;

[0065] All the second slave bit data are traversed sequentially; and during the traversal, the second slave bit data currently traversed is used as the corresponding current slave bit data; and when the current slave bit data is 0, a first slave bit signal with a signal duration equal to the preset first bit signal duration and a high-low level duty ratio that satisfies the preset 0-value high-low level duty ratio is generated and sent to the first host; and when the current slave bit data is 1, a second slave bit signal with a signal duration equal to the first bit signal duration and a high-low level duty ratio that satisfies the preset 1-value high-low level duty ratio is generated and sent to the first host; the first and second slave bit signals are both composed of a low-level signal starting with a falling edge and a subsequent high-level signal; the ratio of the high-level signal duration to the low-level signal duration in the first slave bit signal satisfies the 0-value high-low level duty ratio; the ratio of the high-level signal duration to the low-level signal duration in the second slave bit signal satisfies the 1-value high-low level duty ratio;

[0066] And at the end of the traversal, confirm that the single byte sending is completed.

[0067] The embodiment of the present invention provides a communication data processing method between a master and a slave; in the bit signal communication process of the master and the slave, the method replaces the traditional processing method of identifying the 0 / 1 bit value with the absolute bit signal amplitude by the processing method of identifying the 0 / 1 bit value based on the duty cycle, thereby improving the bit signal fault tolerance of the master and the slave; and after each byte is sent by the slave, the byte sending interval of the slave is extended by sending a fixed-length low-level signal from the host side, and the byte sending and receiving errors of the master and the slave are reduced by the speed reduction method, and the byte sending and receiving success rate of the master and the slave are improved; and the corresponding start, end and check bits are no longer set in each byte, but the traditional bit-level repetitive byte check method is replaced by a byte-level one-time full-frame check method, which not only reduces the number of data sent and received, improves the sending and receiving efficiency, but also reduces the verification complexity without losing the data verification function. The improved serial port communication method provided by the method of the present invention not only reduces the communication processing difficulty of the master and the slave, improves the data sending and receiving accuracy of the master and the slave, but also has better device compatibility. BRIEF DESCRIPTION OF THE DRAWINGS

[0068] Figure 1 A schematic diagram of a process flow of communication data processing on the host side of a method for processing communication data between a master and a slave provided by an embodiment of the present invention;

[0069] Figure 2 A schematic diagram of a communication data processing flow chart of a slave side of a communication data processing method between a master and a slave provided by an embodiment of the present invention;

[0070] Figure 3 A schematic diagram of a data frame provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0071] In order to make the purpose, technical solution and advantages of the present invention clearer, the present invention will be further described in detail below in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0072] The embodiment of the present invention provides a method for processing communication data between a master and a slave. The method comprises the steps of processing communication data on both sides of the master and the slave. The steps of processing communication data on the host side are as follows: Figure 1 A method for processing communication data between a master and a slave provided by an embodiment of the present invention is shown in a schematic diagram of a process flow of communication data processing on the host side, which includes the following steps 1-4:

[0073] Step 1, when the first host obtains the first host data frame sent to the first slave, the first host identifies whether the host communication working stage is in the host communication initial stage; if so, the host communication working stage is switched to the host data sending stage;

[0074] The host communication working stage includes the host communication initial stage, the host data sending stage, the slave data receiving stage and the slave data parsing stage.

[0075] Here, the first host of the embodiment of the present invention can connect to more first slaves like the host in a conventional master-slave network, but the communication method with each first slave is consistent, so the embodiment of the present invention only describes the communication process between a group of master-slaves, namely the first host and the first slave; the first host data frame is the data that needs to be sent by the first host to the first slave at that time, and the source of the first host data frame is any built-in or external software / hardware processing interface, processing unit, processing module or processing system on the first host side.

[0076] In the embodiment of the present invention, the first host presets a host communication working stage for marking the current communication task processing stage of the host; the host communication working stage includes four stages, namely, the host communication initial stage, the host data sending stage, the slave data receiving stage and the slave data parsing stage; when the first host is in the host communication initial stage, if it receives a data frame that needs to be sent to the first slave, it will actively switch the host communication working stage to the host data sending stage, but if the first host receives a data frame that needs to be sent to the first slave in the other three stages other than the host communication initial stage, it will not actively switch but wait until the host communication working stage is changed to the host communication working stage before processing; the first host is in the host data When the first host is in the data sending stage, the first host data frame will be sent to the first slave, and at the end of the sending, the host communication working stage will be switched to the slave data receiving stage; when the first host is in the slave data receiving stage, the slave data frame sent back by the first slave will be received, and after confirming that the reception is complete, the host communication working stage will be switched to the slave data parsing stage; when the first host is in the slave data parsing stage, the first host will perform a format check on the received slave data frame, and when the check fails, the host communication working stage will be switched back to the host data sending stage to resend the first host data frame, and when the check succeeds, the slave data frame will be sent back to the source of the first host data frame and the host communication working stage will be switched back to the initial stage of host communication.

[0077] It should be noted that, in the embodiment of the present invention, the data frame format of both the host data frame and the slave data frame is consistent, and the complete data format of the data frame is a data sequence sequentially spliced ​​by a preset frame header identifier, a parameter sequence length, a data frame type, a data frame parameter sequence, a data frame check code and a preset frame tail identifier, such as Figure 3 As shown in the schematic diagram of the data frame provided by the embodiment of the present invention; wherein the data length of the frame header identifier is one byte, and the frame header identifier can be preset according to the actual application requirements; the data length of the parameter sequence length is a preset first byte length, and the first byte length can be preset according to the actual application requirements; the data length of the data frame type is one byte; the data length of the data frame parameter sequence matches the corresponding parameter sequence length; the data length of the data frame check code is a preset second byte length, and the second byte length can be preset according to the actual application requirements; the data length of the frame tail identifier is one byte, and the frame tail identifier can be preset according to the actual application requirements. The data frame type includes a data type and an instruction type, which are used to identify the type of the data frame parameter sequence in the current frame. If it is an instruction type, it means that the data frame parameter sequence is an instruction data sequence composed of multiple instruction parameters. If it is a data type, it means that the data frame parameter sequence is a feedback data sequence composed of multiple feedback data. The data frame check code is the check code data obtained by calculating the check code of the data sequence spliced ​​by the parameter sequence length, the data frame type and the data frame parameter sequence sequence based on a preset check code algorithm. The preset check code algorithm can be a CRC check code algorithm or any other common check code algorithm.

[0078] Step 2, when the host communication working stage is the host data sending stage, the first host sends a high-level signal with a signal duration not less than a preset leading time to the first slave; and when the sending of the high-level signal ends, the first host data frame is sequentially divided into multiple first host byte data; and all the first host byte data are traversed in sequence; and when traversing, the first host byte data currently traversed is used as the corresponding current host byte data, and the current host byte data is sent as a single byte; and when the single byte sending ends, whether the current host byte data is the last first host byte data is identified; if not, it goes to the next first host byte data to continue traversing; if so, the host communication working stage is switched to the slave data receiving stage.

[0079] Here, the preset lead time is a preset time length parameter.

[0080] Among them, the current host byte data is sent in single byte, specifically including:

[0081] Sequentially divide the current host byte data into multiple first host bit data; and traverse all the first host bit data in sequence; and when traversing, use the currently traversed first host bit data as the corresponding current host bit data; and when the current host bit data is 0, generate a first host bit signal with a signal duration equal to the preset first bit signal duration and a high-low level duty ratio that satisfies the preset 0-value high-low level duty ratio, and send it to the first slave; and when the current host bit data is 1, generate a second host bit signal with a signal duration equal to the first bit signal duration and a high-low level duty ratio that satisfies the preset 1-value high-low level duty ratio, and send it to the first slave; and at the end of the traversal, confirm that the single byte sending is completed.

[0082] Here, the preset 0 / 1 value high and low level duty cycle is two preset bit signal duty cycle parameters, and the bit signal duty cycle parameter is calculated as the ratio of the signal high level signal duration to the low level signal duration; the first and second host bit signals are both composed of a low level signal starting with a falling edge and a subsequent high level signal, and the signal lengths of the first and second host bit signals are both the first bit signal duration, and the first bit signal duration is the signal duration limit value of the master / slave bit signal in the embodiment of the present invention; the high level signal duration and the low level signal duration in the first host bit signal The ratio of the duration of the high level signal to the duration of the low level signal in the second host bit signal satisfies the high and low level duty cycle of 1; the ratio of the duration of the high level signal to the duration of the low level signal in the second host bit signal satisfies the high and low level duty cycle of 1; when the master / slave machine of the embodiment of the present invention receives the slave / host bit signal, it will only confirm that a qualified slave / host bit signal has been received if the signal received this time satisfies the two conditions that the signal duration = the duration of the first bit signal and the signal consists of a low level signal starting with a falling edge and a subsequent high level signal, and then the bit value will be identified based on the preset 0 / 1 value high and low level duty cycle.

[0083] Step 3, when the first host is in the slave data receiving stage during the host communication working stage, the first host uses the current time as the starting time and postpones a time period equal to the preset host waiting time as the corresponding current waiting time window, and receives the slave bit signal of the first slave within the current waiting time window; if a slave bit signal is received within the current waiting time window, the next slave bit signal is received with the current time as the new starting time and postponed by a time period equal to the preset host waiting time as the new current waiting time window; if a slave bit signal is not received within the current waiting time window, the host communication working stage is switched to the slave data parsing stage; and when each slave bit signal is received, the current slave bit signal is converted into numerical data based on the preset 0 / 1 value high and low level duty cycle to obtain the corresponding first slave bit data; and eight consecutive first slave bit data are used to form a corresponding first slave byte data and save it; and when each first slave byte data is obtained, a low-level signal with a signal duration not less than the preset byte interval duration is sent to the first slave.

[0084] Here, when the first host of the embodiment of the present invention is in the slave data receiving stage, it will receive the data sent by the first slave based on a sliding window mechanism, and send a low-level signal with a duration not less than a preset byte interval duration (a pre-set time length parameter) to the first slave after receiving each byte, so as to inform the first slave that the previous byte data has been successfully received; it can be seen that the first host of the embodiment of the present invention forces the byte serial transmission speed of the first slave to be reduced through a low-level signal interaction process from the host to the slave, thereby achieving the purpose of reducing the master-slave byte transmission and reception errors and improving the master-slave byte transmission and reception success rate.

[0085] The process of converting the current slave bit signal into numerical data based on the preset 0 / 1 value high and low level duty cycle to obtain the corresponding first slave bit data specifically includes:

[0086] The duration of the low-level signal in the current slave bit signal is detected to obtain the corresponding first low-level duration; and the duration of the high-level signal in the current slave bit signal is detected to obtain the corresponding first high-level duration; and the ratio of the first high-level duration to the first low-level duration is used as the corresponding first high-low level duty cycle; if the absolute difference between the first high-low level duty cycle and the preset 1-value high-low level duty cycle is less than the preset small duty cycle differential threshold, the corresponding first slave bit data is set to 1; if the absolute difference between the first high-low level duty cycle and the preset 0-value high-low level duty cycle is less than the small duty cycle differential threshold, the corresponding first slave bit data is set to 0.

[0087] Here, the small duty cycle differential threshold is a pre-set duty cycle threshold parameter, the value of which is a smaller duty cycle value, which can be set to 0 in extreme cases. The embodiment of the present invention improves the bit signal error tolerance of the host side receiving end by using high and low level duty cycles and configuring a small duty cycle differential threshold.

[0088] Step 4, when the host communication working stage is the slave data parsing stage, the first host composes a corresponding first slave data frame from all the first slave byte data obtained; and performs a data frame format check on the first slave data frame to generate a corresponding first check result; if the first check result is a check failure, then the cumulative number of retransmissions begins to be counted and the host communication working stage is switched to the host data sending stage to retransmit the first host data frame until the count value of the cumulative number of retransmissions exceeds the preset maximum number of retransmissions; if the first check result is a check success, then the first slave data frame is processed as a slave and the host communication working stage is switched to the host communication initial stage.

[0089] Here, when the first host of the embodiment of the present invention retransmits the first host data frame, if the retransmission is successful, the cumulative number of retransmissions is cleared; if the retransmission fails, the cumulative number of retransmissions is increased by 1 and retransmitted again; if the retransmission fails for multiple consecutive times, the cumulative number of retransmissions is continuously increased by 1. Once the count value of the cumulative number of retransmissions exceeds the preset maximum number of retransmissions, the retransmission is stopped, the cumulative number of retransmissions is cleared, and the host communication working phase is switched to the idle state, and a data sending failure warning is issued through the set warning processing interface. The warning processing interface can be any built-in or external software / hardware processing interface, processing unit, processing module or processing system on the first host side; when the first host of the embodiment of the present invention performs slave data processing on the first slave data frame, it actually sends the first slave data frame back to the source of the first host data frame.

[0090] Among them, performing data frame format check on the first slave data frame to generate a corresponding first check result specifically includes: taking the first byte of the first slave data frame as the corresponding first frame header; and taking the last byte of the first slave data frame as the corresponding first frame tail; and taking the sub-data segment of the first slave data frame whose starting position is the next byte position of the first frame header and whose data length is the first byte length as the corresponding first parameter sequence length; and taking the next byte of the first parameter sequence length in the first slave data frame as the corresponding first data frame type; and taking the sub-data segment of the first slave data frame whose ending position is the previous byte position of the first frame tail and whose data length is the second byte length as the corresponding first data frame check code; and taking the sub-data segment of the first slave data frame whose starting position is the next byte position of the first data frame type and whose ending position is the previous byte position of the first data frame check code as the corresponding first data frame parameter sequence; and identifying whether the first frame header matches a preset frame header identifier; if so, setting the corresponding first result as qualified, otherwise setting the corresponding first result as unqualified; and checking whether the first frame tail matches a preset frame tail identifier The method comprises the following steps: a) determining a first data frame parameter sequence and a second data frame parameter sequence according to the first parameter sequence length; b) determining a first data frame parameter sequence and a second data frame parameter sequence according to the first parameter sequence length; c) determining a first data frame parameter sequence and a second data frame parameter sequence according to the first parameter sequence length; e) determining a first data frame parameter sequence and a second data frame parameter sequence according to the first parameter sequence length; e) determining a second ...

[0091] As described above, a method for processing communication data between a master and a slave provided by an embodiment of the present invention comprises communication data processing steps on both sides of the master and slave, wherein the communication data processing steps on the slave side are as follows: Figure 2 A slave-side communication data processing flow diagram of a method for processing communication data between a master and a slave provided by an embodiment of the present invention includes the following steps 101-104:

[0092] Step 101, when the first slave is in any stage of the slave communication working stage, upon receiving a high-level signal with a signal duration of a preset leading time sent by the first host, the slave communication working stage is switched to the host data receiving stage;

[0093] The slave communication working phase includes the slave communication initial phase, the host data receiving phase, the master-slave data parsing and packaging phase, and the slave data sending phase.

[0094] Here, the first slave in the embodiment of the present invention presets a slave communication working stage for marking the current communication task processing stage of the slave; the slave communication working stage includes four stages, namely the slave communication initial stage, the host data receiving stage, the master-slave data parsing and encapsulation stage and the slave data sending stage; when the first slave is in the slave communication initial stage, it will monitor the sending signal of the first host; in addition, the embodiment of the present invention also stipulates that no matter which stage of the four stages the first slave is in, as long as a high-level signal with a signal duration of a preset leading duration is received, the slave communication working stage will be switched to the host data receiving stage; when the first slave is in the host data receiving stage, it continuously receives the host data frame sent by the first host, and switches the slave communication working stage to the host data receiving stage after the reception is completed. Master-slave data parsing and encapsulation stage; when the first slave is in the master-slave data parsing and encapsulation stage, it will verify the host data frame and prepare the slave return data frame, and after completing the return data frame preparation, it will switch the slave communication working stage to the slave data sending stage; when the first slave is in the slave data sending stage, it will not continuously send the return data frame to the first master, but adopt a byte-by-byte interaction method with the host to complete the sending of the return data frame. The byte-by-byte interaction method is that after sending a byte, the slave will wait for the host to return a low-level signal of a fixed duration and will send the next byte only after receiving the low-level signal until all bytes are sent. After the first slave sends all bytes of the return data frame, the slave communication working stage will be switched back to the initial stage of slave communication.

[0095] Step 102, when the first slave is in the host data receiving stage during the slave communication working phase, the first slave receives the host bit signal of the first host; and when each host bit signal is received, the current host bit signal is converted into numerical data based on the high and low level duty ratio of 0 / 1 value to obtain the corresponding second host bit data; and a corresponding second host byte data is formed from eight consecutively obtained second host bit data and saved; and whether the current second host byte data matches the preset frame header identifier is identified, and if so, the other second host byte data before the current second host byte data are deleted; and whether the current second host byte data matches the preset frame end identifier is identified, and if so, the slave communication working phase is switched to the master-slave data parsing and encapsulation phase.

[0096] Among them, the current host bit signal is converted into numerical data based on the 0 / 1 value high and low level duty cycle to obtain the corresponding second host bit data, specifically including: detecting the low level signal duration in the current host bit signal to obtain the corresponding second low level duration; and detecting the high level signal duration in the current host bit signal to obtain the corresponding second high level duration; and using the ratio of the second high level duration to the second low level duration as the corresponding second high and low level duty cycle; if the absolute difference between the second high and low level duty cycle and the preset 1 value high and low level duty cycle is less than the preset small duty cycle differential threshold, the corresponding second host bit data is set to 1; if the absolute difference between the second high and low level duty cycle and the preset 0 value high and low level duty cycle is less than the small duty cycle differential threshold, the corresponding second host bit data is set to 0.

[0097] Here, the small duty cycle differential threshold is a preset duty cycle threshold parameter, and the value of the duty cycle threshold parameter is a smaller duty cycle value; the embodiment of the present invention improves the bit signal error tolerance rate of the receiving end of the slave side by using high and low level duty cycles and configuring a small duty cycle differential threshold.

[0098] Step 103, when the slave communication working phase is the master-slave data parsing and encapsulating phase, the first slave forms a corresponding second host data frame with all the second host byte data obtained; and performs a data frame format check on the second host data frame to generate a corresponding second check result; if the second check result is a successful check, the return frame data preparation processing is performed according to the second host data frame to obtain the corresponding second slave data frame, and the slave communication working phase is switched to the slave data sending phase; if the second check result is a failed check, the slave communication working phase is switched to the slave communication initial phase.

[0099] in,

[0100] 1) Performing data frame format check on the second host data frame to generate a corresponding second check result, specifically including: taking the first byte of the second host data frame as the corresponding second frame header; taking the last byte of the second host data frame as the corresponding second frame tail; taking the sub-data segment whose starting position is the next byte position of the second frame header and whose data length is the first byte length in the second host data frame as the corresponding second parameter sequence length; taking the next byte of the second parameter sequence length in the second host data frame as the corresponding second data frame type; taking the sub-data segment whose ending position is the previous byte position of the second frame tail and whose data length is the second byte length in the second host data frame as the corresponding second data frame check code; taking the sub-data segment whose starting position is the next byte position of the second data frame type and whose ending position is the previous byte position of the second data frame check code in the second host data frame as the corresponding second data frame parameter sequence; and identifying whether the second frame header matches a preset frame header identifier; if so, setting the corresponding sixth result as qualified, otherwise setting the corresponding sixth result as unqualified; and checking whether the second frame tail matches a preset frame tail identifier and identify whether the data length of the second data frame parameter sequence matches the length of the second parameter sequence; if so, set the corresponding eighth result to be qualified, otherwise set the corresponding eighth result to be unqualified; and identify whether the second data frame type is a data type or an instruction type; if so, set the corresponding ninth result to be qualified, otherwise set the corresponding ninth result to be unqualified; and obtain the corresponding second data sequence by sequentially splicing the second parameter sequence length, the second data frame type, and the second data frame parameter sequence; and calculate the second data sequence based on the check code algorithm to obtain the corresponding second check code; and identify whether the second check code matches the second data frame check code; if so, set the corresponding tenth result to be qualified, otherwise set the corresponding tenth result to be unqualified; and identify whether the obtained sixth, seventh, eighth, ninth and tenth results are all qualified; if so, set the corresponding second check result to be a check success; if not, set the corresponding second check result to be a check failure;

[0101] 2) performing return frame data preparation processing according to the second host data frame to obtain a corresponding second slave data frame, specifically comprising: inputting a second data frame type and a second data frame parameter sequence of the second host data frame into a preset host data processing interface for processing; and using the data frame returned by the host data processing interface as the corresponding second slave data frame;

[0102] Here, the host data processing interface is a data processing interface pre-specified locally in the first slave for processing host data frames. The interface will execute the corresponding data processing flow based on the input host data frame and return a slave data frame that has been encapsulated in the data frame format of an embodiment of the present invention, namely, the second slave data frame.

[0103] Step 104, when the slave communication working stage is the slave data sending stage, the first slave sequentially divides the second slave data frame into multiple second slave byte data; and traverses all the second slave byte data in sequence; and when traversing, the second slave byte data currently traversed is used as the corresponding current slave byte data, and the current slave byte data is sent as a single byte; and when the single byte sending is completed, it is identified whether the current slave byte data is the last second slave byte data; if not, after confirming that a low-level signal with a signal length of a preset byte interval length sent by the first host is received, it switches to the next second slave byte data to continue traversing; if so, the slave communication working stage is switched to the slave communication initial stage.

[0104] Among them, the single-byte sending of the current slave byte data specifically includes: sequentially dividing the current slave byte data into multiple second slave bit data; and traversing all the second slave bit data in sequence; and when traversing, taking the currently traversed second slave bit data as the corresponding current slave bit data; and when the current slave bit data is 0, generating a first slave bit signal with a signal duration of a preset first bit signal duration and a high-low level duty ratio that satisfies a preset 0-value high-low level duty ratio, and sending it to the first host; and when the current slave bit data is 1, generating a second slave bit signal with a signal duration of a first bit signal duration and a high-low level duty ratio that satisfies a preset 1-value high-low level duty ratio, and sending it to the first host; and at the end of the traversal, confirming the end of the single-byte sending.

[0105] Here, the preset 0 / 1 value high and low level duty cycle are two pre-set bit signal duty cycle parameters, and the bit signal duty cycle parameters are calculated as the ratio of the signal high level signal duration to the signal low level signal duration; the first and second slave bit signals are both composed of a low level signal starting with a falling edge and a subsequent high level signal; the ratio of the high level signal duration to the low level signal duration in the first slave bit signal satisfies the 0 value high and low level duty cycle; the ratio of the high level signal duration to the low level signal duration in the second slave bit signal satisfies the 1 value high and low level duty cycle.

[0106] In summary, the embodiment of the present invention provides a communication data processing method between a master and a slave; in the bit signal communication process of the master and the slave, the method replaces the traditional processing method of identifying the 0 / 1 bit value with the absolute bit signal amplitude by the processing method of identifying the 0 / 1 bit value based on the duty cycle, thereby improving the bit signal fault tolerance of the master and the slave; and after each byte is sent by the slave, the byte sending interval of the slave is extended by sending a fixed-length low-level signal from the host side, and the byte sending and receiving errors of the master and the slave are reduced by the speed reduction method, and the byte sending and receiving success rate of the master and the slave are improved; and the corresponding start, end and check bits are no longer set in each byte, but the traditional bit-level repetitive byte check method is replaced by a byte-level one-time full-frame check method, which not only reduces the number of data sent and received, improves the sending and receiving efficiency, but also reduces the verification complexity without losing the data verification function. The improved serial port communication method provided by the method of the present invention not only reduces the communication processing difficulty of the master and the slave, improves the data sending and receiving accuracy of the master and the slave, but also has better device compatibility.

[0107] The professionals should further realize that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented by electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to the function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.

[0108] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.

[0109] The specific implementation methods described above further illustrate the objectives, technical solutions and beneficial effects of the present invention in detail. It should be understood that the above description is only a specific implementation method of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.

Claims

1. A method for processing communication data between a master and a slave, characterized in that: The method comprises: When the first host obtains the first host data frame sent to the first slave, the first host identifies whether the host communication working stage is in the host communication initial stage; if so, the host communication working stage is switched to the host data sending stage; the host communication working stage includes the host communication initial stage, the host data sending stage, the slave data receiving stage and the slave data parsing stage; When the host communication working stage is the host data sending stage, the first host sends a high-level signal with a signal duration not less than a preset leading duration to the first slave; and when the high-level signal is sent, the first host data frame is sequentially divided into a plurality of first host byte data; and all the first host byte data are traversed in sequence; and when traversing, the first host byte data currently traversed is used as the corresponding current host byte data, and the current host byte data is sent in a single byte; and when the single byte sending is finished, whether the current host byte data is the last one of the first host byte data is identified; if not, the next first host byte data is switched to continue traversal; if so, the host communication working stage is switched to the slave data receiving stage; When the host communication working stage is the slave data receiving stage, the first host uses the current time as the starting time and postpones a time period of the preset host waiting time as the corresponding current waiting time window, and receives the slave bit signal of the first slave within the current waiting time window. If a slave bit signal is received in the current waiting time window, the next slave bit signal is received with the current time as the new starting time and postponed by a time period of the preset host waiting time as the new current waiting time window. If a slave bit signal is not received within the current waiting time window, the host communication working stage is switched to the slave data parsing stage; and when each slave bit signal is received, the current slave bit signal is converted into a numerical data based on a preset 0 / 1 value high and low level duty cycle to obtain the corresponding first slave bit data; and eight consecutive first slave bit data are used to form a corresponding first slave byte data and save it; and when each first slave byte data is obtained, a low-level signal with a signal length not less than the preset byte interval length is sent to the first slave; When the host communication working stage is the slave data parsing stage, the first host forms a corresponding first slave data frame with all the first slave byte data obtained; and performs data frame format verification on the first slave data frame to generate a corresponding first verification result; if the first verification result is a verification failure, the cumulative number of retransmissions begins to be counted and the host communication working stage is switched to the host data sending stage to retransmit the first host data frame until the count value of the cumulative number of retransmissions exceeds the preset maximum number of retransmissions; if the first verification result is a verification success, the first slave data frame is subjected to slave data processing and the host communication working stage is switched to the host communication initial stage.

2. The method for processing communication data between a master and a slave according to claim 1, characterized in that: The method further comprises: When the first slave is in any stage of the slave communication working stage, once receiving a high-level signal with a signal duration of the preset leading time length sent by the first host, the slave communication working stage is switched to the host data receiving stage; the slave communication working stage includes a slave communication initial stage, a host data receiving stage, a master-slave data parsing and packaging stage, and a slave data sending stage; When the slave communication working stage is the host data receiving stage, the first slave receives the host bit signal of the first host; and when each host bit signal is received, the current host bit signal is converted into numerical data based on the 0 / 1 value high and low level duty ratio to obtain the corresponding second host bit data; and eight consecutively obtained second host bit data form a corresponding second host byte data and save it; and identify whether the current second host byte data matches the preset frame header identifier, and if so, delete the other second host byte data before the current second host byte data; and identify whether the current second host byte data matches the preset frame end identifier, and if so, switch the slave communication working stage to the master-slave data parsing and encapsulation stage; When the slave communication working stage is the master-slave data parsing and encapsulating stage, the first slave composes a corresponding second host data frame from all the obtained second host byte data; and performs a data frame format check on the second host data frame to generate a corresponding second check result; if the second check result is a check success, a return frame data preparation process is performed according to the second host data frame to obtain a corresponding second slave data frame, and the slave communication working stage is switched to the slave data sending stage; if the second check result is a check failure, the slave communication working stage is switched to the slave communication initial stage; When the slave communication working stage is the slave data sending stage, the first slave sequentially divides the second slave data frame into multiple second slave byte data; and traverses all the second slave byte data in sequence; and when traversing, the second slave byte data currently traversed is used as the corresponding current slave byte data, and the current slave byte data is sent as a single byte; and when the single byte sending ends, it is identified whether the current slave byte data is the last second slave byte data; if not, after confirming that a low-level signal with a signal length of the preset byte interval length sent by the first host is received, it switches to the next second slave byte data to continue traversing; if so, the slave communication working stage is switched to the slave communication initial stage.

3. The method for processing communication data between a master and a slave according to claim 2, characterized in that: The complete data format of any data frame should be a data sequence composed of the preset frame header identifier, parameter sequence length, data frame type, data frame parameter sequence, data frame check code and the preset frame tail identifier in sequence; The data length of the frame header identifier is one byte; The data length of the parameter sequence length is a preset first byte length; The data length of the data frame type is one byte; The data length of the data frame parameter sequence matches the corresponding parameter sequence length; The data length of the data frame check code is a preset second byte length; The data length of the frame tail identifier is one byte; The data frame type includes a data type and an instruction type; The data frame check code is check code data obtained by performing check code calculation on a data sequence formed by sequentially splicing the parameter sequence length, the data frame type and the data frame parameter sequence based on a preset check code algorithm.

4. The method for processing communication data between a master and a slave according to claim 1, characterized in that: The single-byte sending of the current host byte data specifically includes: Sequentially divide the current host byte data into a plurality of first host bit data; All the first host bit data are sequentially traversed; and during the traversal, the first host bit data currently traversed is used as the corresponding current host bit data; and when the current host bit data is 0, a first host bit signal with a signal duration equal to the preset first bit signal duration and a high-low level duty ratio that satisfies the preset 0-value high-low level duty ratio is generated and sent to the first slave; and when the current host bit data is 1, a second host bit signal with a signal duration equal to the first bit signal duration and a high-low level duty ratio that satisfies the preset 1-value high-low level duty ratio is generated and sent to the first slave; the first and second host bit signals are both composed of a low-level signal starting with a falling edge and a subsequent high-level signal; the ratio of the high-level signal duration to the low-level signal duration in the first host bit signal satisfies the 0-value high-low level duty ratio; the ratio of the high-level signal duration to the low-level signal duration in the second host bit signal satisfies the 1-value high-low level duty ratio; And at the end of the traversal, confirm that the single byte sending is completed.

5. The method for processing communication data between a master and a slave according to claim 1, characterized in that: The converting the current slave bit signal into numerical data based on the preset 0 / 1 value high and low level duty ratio to obtain the corresponding first slave bit data specifically includes: Detecting the duration of the low-level signal in the current slave bit signal to obtain a corresponding first low-level duration; and detecting the duration of the high-level signal in the current slave bit signal to obtain a corresponding first high-level duration; and using the ratio of the first high-level duration to the first low-level duration as the corresponding first high-low level duty ratio; If the absolute difference between the first high-low level duty cycle and the preset 1-value high-low level duty cycle is smaller than a preset small duty cycle difference threshold, the corresponding first slave bit data is set to 1; If the absolute difference between the first high-low level duty cycle and the preset high-low level duty cycle of 0 is smaller than the small duty cycle difference threshold, the corresponding first slave bit data is set to 0.

6. The method for processing communication data between a master and a slave according to claim 3, characterized in that: The performing data frame format verification on the first slave data frame to generate a corresponding first verification result specifically includes: Using the first byte of the first slave data frame as the corresponding first frame header; Using the last byte of the first slave data frame as the corresponding first frame tail; Taking the sub-data segment in the first slave data frame whose starting position is the next byte position of the first frame header and whose data length is the first byte length as the corresponding first parameter sequence length; Using the next byte of the first parameter sequence length in the first slave data frame as the corresponding first data frame type; Using the sub-data segment in the first slave data frame whose end position is the previous byte position of the first frame tail and whose data length is the second byte length as the corresponding first data frame check code; Taking the sub-data segment in the first slave data frame whose starting position is the next byte position of the first data frame type and whose ending position is the previous byte position of the first data frame check code as the corresponding first data frame parameter sequence; Identify whether the first frame header matches the preset frame header identifier; if so, set the corresponding first result as qualified, otherwise, set the corresponding first result as unqualified; Identify whether the first frame end matches the preset frame end identifier; if so, set the corresponding second result as qualified, otherwise, set the corresponding second result as unqualified; Identify whether the data length of the first data frame parameter sequence matches the length of the first parameter sequence; if so, set the corresponding third result as qualified, otherwise, set the corresponding third result as unqualified; Identify whether the first data frame type is a data type or an instruction type; if so, set the corresponding fourth result as qualified, otherwise set the corresponding fourth result as unqualified; The first parameter sequence length, the first data frame type and the first data frame parameter sequence are sequentially spliced ​​to obtain a corresponding first data sequence; and a check code is calculated on the first data sequence based on the check code algorithm to obtain a corresponding first check code; and whether the first check code matches the first data frame check code is identified; if so, the corresponding fifth result is set to be qualified, and otherwise, the corresponding fifth result is set to be unqualified; Identify whether the first, second, third, fourth and fifth results are all qualified; if so, set the corresponding first verification result as verification success; if not, set the corresponding first verification result as verification failure.

7. The method for processing communication data between a master and a slave according to claim 2, characterized in that: The converting the current host bit signal into numerical data based on the 0 / 1 value high and low level duty ratio to obtain the corresponding second host bit data specifically includes: Detecting the duration of the low-level signal in the current host bit signal to obtain a corresponding second low-level duration; and detecting the duration of the high-level signal in the current host bit signal to obtain a corresponding second high-level duration; and using the ratio of the second high-level duration to the second low-level duration as the corresponding second high-low level duty ratio; If the absolute difference between the second high-low level duty cycle and the preset 1-value high-low level duty cycle is less than a preset small duty cycle difference threshold, the corresponding second host bit data is set to 1; If the absolute difference between the second high-low level duty cycle and the preset high-low level duty cycle of 0 is smaller than the small duty cycle difference threshold, the corresponding second host bit data is set to 0.

8. The method for processing communication data between a master and a slave according to claim 3, characterized in that: The performing data frame format verification on the second host data frame to generate a corresponding second verification result specifically includes: Using the first byte of the second host data frame as the corresponding second frame header; Using the last byte of the second host data frame as the corresponding second frame tail; Taking the sub-data segment in the second host data frame whose starting position is the next byte position of the second frame header and whose data length is the first byte length as the corresponding second parameter sequence length; Using the next byte of the second parameter sequence length in the second host data frame as the corresponding second data frame type; Using the sub-data segment in the second host data frame whose end position is the previous byte position of the second frame tail and whose data length is the second byte length as the corresponding second data frame check code; Taking the sub-data segment in the second host data frame whose starting position is the next byte position of the second data frame type and whose ending position is the previous byte position of the second data frame check code as the corresponding second data frame parameter sequence; Identify whether the second frame header matches the preset frame header identifier; if so, set the corresponding sixth result as qualified, otherwise, set the corresponding sixth result as unqualified; Identify whether the second frame end matches the preset frame end identifier; if so, set the corresponding seventh result as qualified, otherwise, set the corresponding seventh result as unqualified; Identify whether the data length of the second data frame parameter sequence matches the length of the second parameter sequence; if so, set the corresponding eighth result as qualified, otherwise, set the corresponding eighth result as unqualified; Identify whether the second data frame type is a data type or an instruction type; if so, set the corresponding ninth result as qualified, otherwise set the corresponding ninth result as unqualified; The second parameter sequence length, the second data frame type and the second data frame parameter sequence are sequentially spliced ​​to obtain a corresponding second data sequence; and a check code is calculated on the second data sequence based on the check code algorithm to obtain a corresponding second check code; and whether the second check code matches the second data frame check code is identified; if so, the corresponding tenth result is set to be qualified, and otherwise, the corresponding tenth result is set to be unqualified; Identify whether the sixth, seventh, eighth, ninth and tenth results are all qualified; if so, set the corresponding second verification result to successful verification; if not, set the corresponding second verification result to failed verification.

9. The method for processing communication data between a master and a slave according to claim 8, characterized in that: The step of performing return frame data preparation processing according to the second host data frame to obtain a corresponding second slave data frame specifically includes: The second data frame type and the second data frame parameter sequence of the second host data frame are input into a preset host data processing interface for processing; and the data frame returned by the host data processing interface is used as the corresponding second slave data frame.

10. The method for processing communication data between a master and a slave according to claim 2, characterized in that: The single-byte sending of the current slave byte data specifically includes: Sequentially divide the current slave byte data into a plurality of second slave bit data; All the second slave bit data are traversed sequentially; and during the traversal, the second slave bit data currently traversed is used as the corresponding current slave bit data; and when the current slave bit data is 0, a first slave bit signal with a signal duration equal to the preset first bit signal duration and a high-low level duty ratio that satisfies the preset 0-value high-low level duty ratio is generated and sent to the first host; and when the current slave bit data is 1, a second slave bit signal with a signal duration equal to the first bit signal duration and a high-low level duty ratio that satisfies the preset 1-value high-low level duty ratio is generated and sent to the first host; the first and second slave bit signals are both composed of a low-level signal starting with a falling edge and a subsequent high-level signal; the ratio of the high-level signal duration to the low-level signal duration in the first slave bit signal satisfies the 0-value high-low level duty ratio; the ratio of the high-level signal duration to the low-level signal duration in the second slave bit signal satisfies the 1-value high-low level duty ratio; And at the end of the traversal, confirm that the single byte sending is completed.

Citation Information

Cited By

  • Data transmission system and method with verification and retransmission functions

    CN120856275A