Serial Communication Control Method and System

By adding operation code comparison and failure retry mechanisms in serial communication, the problem of data loss and error in serial communication in complex environments is solved, and communication efficiency and reliability are improved.

CN118784168BActive Publication Date: 2025-07-22GUANGZHOU BAOLUN ELECTRONICS CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202410834725.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-06-26
Publication Date
2025-07-22
Estimated Expiration
2044-06-26

AI Technical Summary

Technical Problem

The existing serial communication methods are susceptible to interference in complex environments, resulting in data loss or error in codes, and the existing software error correction methods lead to low communication efficiency.

Method used

By adding the comparison mechanism of the initial operation code and feedback operation code to the instruction data, combined with the preset time limit and the failed retry mechanism, we ensure the successful transmission and execution of the instruction data.

Benefits of technology

It improves the efficiency and reliability of serial communication, reduces redundant transmission, improves the success rate of service execution, and promptly discovers the cause of failure.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118784168B_ABST
    Figure CN118784168B_ABST
Patent Text Reader

Abstract

The present application provides a serial communication control method and system, which are applied to a host computer and include: starting a first application program to enable the functions of the host computer, constructing first instruction data carrying an initial operation code according to the first application program, and sending the first instruction data to a lower computer, so that after the lower computer receives and executes the first instruction data, it feeds back first response data carrying a feedback operation code; if the first response data is received within a preset time limit, then parse the first response data to obtain the feedback operation code. If the feedback operation code is different from the initial operation code, the first response data is not the target first response data corresponding to the initial operation code, and it is necessary to retransmit the first instruction data to the lower computer within the preset time limit to obtain the target first response data; adopting the present application can improve the serial communication efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of serial port reliable communication, and in particular to a serial port communication control method and system. Background Art

[0002] Serial communication is a communication method that sends and receives bytes by bit. It is a commonly used communication method in the field of embedded Internet of Things. It has the characteristics of few transmission lines and low cost. It is mainly suitable for system communication work such as close-range human-machine exchange and real-time monitoring. Serial communication workplaces are mostly in complex environments such as strong electricity / outdoors, so they are susceptible to interference and are prone to occasional data loss or bit errors. Under different hardware optimization measures such as communication line shielding, line isolation, and baud rate calibration, some interference can be weakened or eliminated, but there is still the possibility of data errors.

[0003] For the above problems, in addition to the hardware anti-interference guarantee, the existing software-based error correction technology adopts the method that the upper computer software repeats sending each instruction 3 to 5 times, and the lower computer hardware repeats parsing the received instructions 3 to 5 times. If it is correct, the instruction is executed, and if it is wrong, it is discarded, so as to increase the probability of successful instruction sending. However, this error correction method repeats sending and receiving many times, making the serial communication efficiency low. Summary of the invention

[0004] The purpose of this application is to address the deficiencies of the above-mentioned existing related technologies and to propose a serial communication control method and system, which can improve the efficiency of serial communication from the software error correction level.

[0005] In a first aspect, the present application provides a serial port communication control method, which is applied to a host computer, and the serial port communication control method includes:

[0006] Starting a first application to enable the upper computer function, constructing first instruction data carrying an initial operation code according to the first application, and sending the first instruction data to the lower computer, so that after the lower computer receives and executes the first instruction data, it feeds back first response data carrying a feedback operation code;

[0007] If the first response data is received within the preset time limit, the first response data is parsed to obtain the feedback operation code. If the feedback operation code is different from the initial operation code, the first response data is not the target first response data corresponding to the initial operation code, and the first instruction data needs to be retransmitted to the lower computer within the preset time limit to obtain the target first response data.

[0008] This application enables the upper-level mechanism to construct the first instruction data through the first application program, adds an initial operation code to the first instruction, and constructs a comparison mechanism through the initial operation code and the feedback operation code fed back by the lower-level machine after receiving the first instruction data. If the initial operation code is different from the feedback operation code, retransmission is performed within a preset time limit, and a displayed response mechanism is used to avoid blindly increasing the redundant transmission and execution of instruction data, thereby improving the serial port communication efficiency at the software level. Moreover, based on the retransmission within the preset time limit, the successful execution of the instruction data can be ensured as much as possible, thereby improving the success rate of service execution and further improving the serial port communication efficiency.

[0009] Furthermore, the preset time limit includes: the maximum instruction execution timeout and the maximum number of failed retries; wherein, obtaining the target first response data includes:

[0010] If the first response data is received within the maximum instruction execution timeout, then parse the first response data to obtain the feedback operation code and the first response result;

[0011] If the feedback operation code is different from the initial operation code, or it is detected that the first response result is incorrect, then the first response data is not the target first response data corresponding to the initial operation code, and the first instruction data needs to be retransmitted to the lower-level machine within the limit of the maximum number of failed retries to obtain the target first response data.

[0012] Furthermore, if the first response data is not received within the maximum instruction execution timeout, then the first response data is lost or the first instruction data is lost, and the first instruction data needs to be retransmitted to the lower-level machine within the limit of the maximum number of failed retries to obtain the target first response data.

[0013] Furthermore, if the first response data is still not received within the limit of the maximum number of failed retries, then the execution of the first instruction data fails, and the failure result is reported to the service layer so that the service layer can record the fault or notify the fault.

[0014] Furthermore, if the first response data is still not received within the maximum number of failed retries, it further includes: the lower-level machine enables the upper-level machine function to detect whether a fault occurs in the upper-level machine and the lower-level machine, specifically including:

[0015] The lower-level machine installs and starts the second application program to enable the upper-level machine function, constructs second instruction data carrying the initial operation code according to the second application program, and sends the second instruction data to the upper-level machine, so that after the upper-level machine enables the lower-level machine function, it receives and executes the second instruction data and feeds back the second response data carrying the initial operation code;

[0016] If the second response data is received correctly, there is no fault in the host computer and the slave computer.

[0017] In this application, the function of the slave computer is converted through software programming to enable it to have the function of the host computer, and the second instruction data is actively sent. Therefore, after the host computer fails to receive the target first response data all the time after sending the first instruction data, fault troubleshooting is carried out, the cause of the fault can be found in time, and the situation of ineffective operations where the target response data still cannot be obtained after other types of instructions are executed can be avoided, thereby improving the reliability of serial communication.

[0018] Further, if the second response data is received correctly, stopping sending the second instruction data includes:

[0019] If the second response data is received within the preset time limit, the second response data is parsed to obtain the feedback operation code and the second response result, and the feedback operation code is the same as the initial operation code, and if it is detected that the second response result is correct, the second response data is stopped from being sent, and there is no fault in the host computer and the slave computer.

[0020] Further, after the slave computer receives and executes the first instruction data, feeding back the first response data carrying the feedback operation code includes:

[0021] After the slave computer receives and parses the first instruction data, service data and an initial operation code are obtained. If the service data is detected to be correct, the first instruction data is executed to obtain a first response result, and according to the first response result and the initial operation code, the first response data is constructed and the first response data is transmitted to the host computer.

[0022] Further, after it is detected that the service data is incorrect, it includes:

[0023] Discard the first instruction data and wait again within the preset time limit to receive the first instruction data retransmitted by the host computer; or,

[0024] Discard the first instruction data and send a retransmission response to the host computer so that after the host computer receives the retransmission response, it retransmits the first instruction data to the slave computer; the retransmission response includes: a retransmission identifier and the feedback operation code.

[0025] Further, starting the first application program to enable the function of the host computer includes:

[0026] Start the first application program and initialize the preset time limit so that the host computer is in a pre-state of constructing the first instruction data.

[0027] In a second aspect, the present application provides a serial communication control system, which is applied to a host computer. The serial communication control system includes: a construction instruction module and a reception response module; where

[0028] The construction instruction module is used to start a first application program to enable the functions of the host computer, construct first instruction data carrying an initial operation code according to the first application program, and send the first instruction data to the lower computer, so that after the lower computer receives and executes the first instruction data, it feeds back first response data carrying a feedback operation code;

[0029] The reception response module is used to, if the first response data is received within a preset time limit, parse the first response data to obtain the feedback operation code. If the feedback operation code is different from the initial operation code, then the first response data is not the target first response data corresponding to the initial operation code, and the first instruction data needs to be retransmitted to the lower computer within the preset time limit to obtain the target first response data. Description of the Drawings

[0030] Figure 1 is a flowchart of a serial communication control method provided by an embodiment of the present application;

[0031] Figure 2 is a structural schematic diagram of a serial communication control system provided by an embodiment of the present application. Detailed Embodiments

[0032] Next, the technical solutions in the embodiments of the present application will be clearly and completely described in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present application.

[0033] It is worth noting that in the existing related technologies for error correction based on software, the instructions are redundantly executed; if the instruction data sent each time is correct, then the lower computer hardware will execute the same instruction multiple times, resulting in a great waste of computing resources in high-frequency instruction processing scenarios; moreover, it lacks a response mechanism. If the instruction data sent each time is incorrect, then the instruction will execute fails, but the host computer software does not know that the lower computer hardware execution fails, resulting in a situation where the data after operation between the service layer and the hardware is inconsistent.

[0034] Based on this, the present application adds an opcode response mechanism to the instruction data to solve the problem of redundant instruction execution; and gives the operation of adding an opcode, and then adds a failure retry mechanism to retry a certain number of times in the case of instruction sending failure, to ensure the successful execution of the instruction as much as possible, and notify the service layer to make a log record or manual intervention after complete failure, so as to improve the serial port communication efficiency.

[0035] To more clearly illustrate the solution of the present application, it will be described in detail from the following embodiments.

[0036] Embodiment 1

[0037] See Figure 1 , which is a schematic flow diagram of a serial port communication control method provided by an embodiment of the present application, including: steps S11 to S12, specifically:

[0038] Step S11, start the first application program to enable the host computer function, construct the first instruction data carrying the initial opcode according to the first application program, and send the first instruction data to the lower computer, so that after the lower computer receives and executes the first instruction data, it feeds back the first response data carrying the feedback opcode.

[0039] It should be noted that the first application program is a programming software executed by the host computer for constructing the first instruction data. The second application program mentioned later is a programming software executed by the lower computer after enabling the host computer function (that is, making the lower computer have the host computer function) for constructing the second instruction data; the first instruction data is the instruction data constructed by the host computer according to the initial opcode and the service data of the host computer (including: operation instructions), and the second instruction data is the instruction data constructed by the lower computer according to the initial opcode and the service data of the lower computer (including: operation instructions); the first response data is the response data generated after the lower computer receives and executes the first instruction data, and the second response data is the response data generated after the host computer receives and executes the second instruction data.

[0040] In some embodiments, starting the first application program to enable the host computer function includes: starting the first application program and initializing a preset time limit, so that the host computer is in a pre-state of constructing the first instruction data.

[0041] It should be noted that the upper and lower computers can also perform read and write operations on the specified serial port through software programming.

[0042] In some embodiments, the preset time limit includes: the maximum instruction execution timeout and the maximum number of failure retries.

[0043] In some embodiments, the host computer software starts and initializes relevant parameters, which may be preset parameters; among them, max_request_timeout represents the maximum timeout for instruction execution, and max_retry_count identifies the maximum number of failed retries.

[0044] In some embodiments, constructing first instruction data carrying an initial operation code according to a first application program includes: according to the first application program, adding a unique initial operation code action_code to the instruction data, where the initial operation code action_code is used to identify the instruction operation, obtaining the first instruction data, and then sending the first instruction data to the lower computer and waiting for a response from the lower computer.

[0045] In some embodiments, after the lower computer receives and executes the first instruction data, it feeds back first response data carrying a feedback operation code, including: after the lower computer receives and parses the first instruction data, obtaining service data and an initial operation code, if it detects that the service data is correct, then executing the first instruction data to obtain a first response result, constructing the first response data according to the first response result and the initial operation code, and transmitting the first response data to the host computer.

[0046] It should be noted that the first response result is the response result generated after the lower computer receives the first instruction data from the host computer, parses the first instruction data, obtains the initial operation code and service data corresponding to the first instruction data, and then executes the service data; the second response result is the response result generated after the host computer receives the second instruction data from the lower computer, parses the second instruction data, obtains the initial operation code and service data corresponding to the second instruction data, and then executes the service data.

[0047] In some embodiments, after detecting that the service data is incorrect, it includes: discarding the first instruction data and waiting again within a preset time limit to receive the first instruction data retransmitted by the host computer; or, discarding the first instruction data and sending a retransmission response to the host computer, so that after the host computer receives the retransmission response, it retransmits the first instruction data to the lower computer set; the retransmission response includes: a retransmission identifier and a feedback operation code.

[0048] In some embodiments, the lower computer receives and parses the first instruction data, and obtains the initial operation code action_code and service data. If the service data is incorrect, it discards the first instruction data; if the service data is correct, it executes the first instruction data to obtain the first response data, constructs the first response data according to the first response data and the initial operation code action_code, and then sends the first response data to the host computer software.

[0049] It should be noted that the operation codes (including: the initial operation code and the feedback operation code) are only used to associate the requests and responses of the current operation. The operation code carried in the host computer's request data must be returned exactly as it is by the slave computer in the response data, so that the host computer can identify which request this response belongs to. That is: only when the initial operation code and the feedback operation code are the same can it be identified which response belongs to which request.

[0050] Step S12: If the first response data is received within the preset time limit, then parse the first response data to obtain the feedback operation code. If the feedback operation code is different from the initial operation code, then the first response data is not the target first response data corresponding to the initial operation code, and the first instruction data needs to be retransmitted to the slave computer within the preset time limit to obtain the target first response data.

[0051] It should be noted that the target first response data is the target response data corresponding to the initial operation code in the first instruction data sent by the host computer to the slave computer.

[0052] In some embodiments, after the host computer receives the first response data, it is parsed to obtain the feedback operation code and the first response result. Only when it is detected that the first response result is correct is it determined that there is no data error caused by an error code. Only when it is detected that the feedback operation code is the same as the initial operation code is it determined that the request and the response are consistent.

[0053] In some embodiments, if there is no data error caused by an error code and the request and the response are consistent, it means that the instruction execution is successful, and the first response result is transmitted to the service layer for processing.

[0054] In some embodiments, obtaining the target first response data includes: if the first response data is received within the maximum timeout time for instruction execution, then parse the first response data to obtain the feedback operation code and the first response result; if the feedback operation code is different from the initial operation code, or it is detected that the first response result is incorrect, then the first response data is not the target first response data corresponding to the initial operation code, and the first instruction data needs to be retransmitted to the slave computer within the limit of the maximum number of failed retries to obtain the target first response data.

[0055] In some embodiments, if the first response data is not received within the maximum timeout time for instruction execution, then the first response data is lost or the first instruction data is lost, and the first instruction data needs to be retransmitted to the slave computer within the limit of the maximum number of failed retries to obtain the target first response data.

[0056] In some embodiments, if the first response data is still not received within the limit of the maximum number of failed retries, then the execution of the first instruction data fails, and the failure result is reported to the service layer so that the service layer can record the fault or notify of the fault.

[0057] In some embodiments, if no response from the lower computer is received within the maximum instruction execution timeout max_request_timeout, it is determined that the data has been lost (including: the first instruction data and the first response data), and a failure retry is quickly performed. If no response from the lower computer is still received within the specified maximum number of failure retries max_retry_count, it is determined that the instruction execution has failed, and the result is reported to the service layer, where the service layer records the fault or notifies the human operator to intervene and handle it.

[0058] In some embodiments, if a response from the lower computer is received within the maximum instruction execution timeout max_request_timeout, and if the data is incorrect due to an error code (including: the first response result is incorrect) or the feedback operation code does not match the initial operation code action_code, the response is discarded, and a failure retry is quickly performed. If no response from the lower computer is still received within the specified maximum number of failure retries max_retry_count, it is determined that the instruction execution has failed, and the result is reported to the service layer, where the service layer records the fault or notifies the human operator to intervene and handle it.

[0059] In some embodiments, by accessing different serial ports of the upper computer serial controller through the lower computer, the upper computer can simultaneously perform serial communication with multiple lower computers; among them, for the lower computers corresponding to different serial ports, different communication protocols or instruction data are used, and each lower computer processes its own data in a process isolation manner based on the application software. Specifically, generally, the communication protocols or instructions of different lower computers are different, and all software generally adopts a process isolation method for communication with different serial ports to process their own communication data independently without interference, and each verifies whether its own protocol data is correct. The verification rules belong to the service layer and can be flexibly formulated according to the actual situation.

[0060] In some embodiments, the initial operation code in the first instruction data sent by the upper computer to the lower computer each time can use the same operation code or different operation codes; among them, if different operation codes are used as the initial operation code, new instruction data needs to be constructed each time.

[0061] In some embodiments, if the first response data is still not received within the maximum number of failure retries, it further includes: the lower computer enables the upper computer function to detect whether the upper computer and the lower computer have failed, specifically including: the lower computer installs and starts the second application program to enable the upper computer function, constructs the second instruction data carrying the initial operation code according to the second application program, and sends the second instruction data to the upper computer, so that after the upper computer enables the lower computer function, it receives and executes the second instruction data and feeds back the second response data carrying the initial operation code; if the second response data is received correctly, it means that the upper computer and the lower computer have not failed.

[0062] It should be noted that, based on software programming, the host computer is enabled with host computer functions and the slave computer is enabled with slave computer functions. When the slave computer fails to feedback the correct first response data that conforms to the operation code, the second application program is installed and started on the slave computer to enable the slave computer to have host computer functions, allowing the slave computer to actively send the second instruction data, and the host computer receives and executes it and then feedbacks the second response data. Within the limits of the maximum instruction execution timeout max_request_timeout and the maximum number of failed retries max_retry_count, the slave computer receives the second response data feedback by the host computer, so as to determine the reason why the slave computer always fails to feedback the corresponding target first response data after the host computer sends the first instruction data, thus timely discovering the cause of the failure and avoiding the situation of ineffective operations where the target response data still cannot be obtained after the execution of other types of instructions, thereby improving the reliability of serial port communication.

[0063] In some embodiments, if the second response data is received correctly, it means that no fault has occurred in the host computer and the slave computer, including: the slave computer receives and parses the second response data to obtain the second response result corresponding to the second response data and the feedback operation code. If it is detected that the second response result is correct, there is no error code. If the feedback operation code is the same as the initial operation code, the request and the response are consistent. If there is no error code and the request and the response are consistent at the same time, then no fault has occurred in the host computer and the slave computer; otherwise, a fault has occurred in the host computer or the slave computer and needs to be reported to the service layer so that the service layer can record the fault or give a fault notification.

[0064] This application converts the functions of the slave computer through software programming to enable it to have host computer functions and actively send the second instruction data, so as to conduct fault troubleshooting after the host computer fails to receive the target first response data all the time after sending the first instruction data, being able to timely discover the cause of the failure and avoid the situation of ineffective operations where the target response data still cannot be obtained after the execution of other types of instructions, thereby improving the reliability of serial port communication.

[0065] In some embodiments, if the second response data is received correctly, stop sending the second instruction data, including: if the second response data is received within the preset time limit, parse the second response data to obtain the feedback operation code and the second response result, and the feedback operation code is the same as the initial operation code, and it is detected that the second response result is correct, then stop sending the second response data, and no fault has occurred in the host computer and the slave computer.

[0066] The present application adds an opcode response mechanism to the instruction data to explicitly feedback the instruction execution result, thereby being able to solve the problem of redundant instruction execution, save unnecessary computational resource loss, improve the efficiency of serial communication, and greatly enhance the reliability of serial communication; and, based on the opcode response mechanism, a failure retry mechanism is added to ensure the success of instruction execution as much as possible and improve the success rate of service execution.

[0067] Embodiment 2

[0068] See Figure 2 , which is a schematic structural diagram of a serial communication control system provided by an embodiment of the present application, applied to a host computer. The serial communication control system includes: a construction instruction module 21 and a reception response module 22.

[0069] In some embodiments, after the construction instruction module 21 enables the host computer, it outputs first instruction data to the lower computer, and the lower computer feeds back first response data to the reception response module 22. After receiving the first response data, the reception response module 22 performs data judgment to output target first response data.

[0070] The construction instruction module 21 is used to start a first application program to enable the host computer function, construct first instruction data carrying an initial opcode according to the first application program, and send the first instruction data to the lower computer, so that after the lower computer receives and executes the first instruction data, it feeds back first response data carrying a feedback opcode.

[0071] In some embodiments, starting the first application program to enable the host computer function includes: starting the first application program and initializing a preset time limit, so that the host computer is in a pre-state of constructing the first instruction data.

[0072] In some embodiments, after the lower computer receives and executes the first instruction data and feeds back first response data carrying a feedback opcode, it includes: after the lower computer receives and parses the first instruction data, it obtains service data and an initial opcode. If the service data is detected to be correct, it executes the first instruction data to obtain a first response result, constructs first response data according to the first response result and the initial opcode, and transmits the first response data to the host computer.

[0073] In some embodiments, after detecting that the service data is incorrect, it includes: discarding the first instruction data and waiting again within a preset time limit to receive the first instruction data retransmitted by the host computer; or, discarding the first instruction data and sending a retransmission response to the host computer, so that after the host computer receives the retransmission response, it retransmits the first instruction data to the lower computer set; the retransmission response includes: a retransmission identifier and a feedback opcode.

[0074] A receiving response module 22, which is configured to, if first response data is received within a preset time limit, parse the first response data to obtain a feedback operation code. If the feedback operation code is different from the initial operation code, the first response data is not the target first response data corresponding to the initial operation code, and the first instruction data needs to be retransmitted to the lower computer within the preset time limit to obtain the target first response data.

[0075] In some embodiments, the preset time limit includes: the maximum timeout time for instruction execution and the maximum number of failed retries.

[0076] In some embodiments, obtaining the target first response data includes: if first response data is received within the maximum timeout time for instruction execution, parsing the first response data to obtain a feedback operation code and a first response result; if the feedback operation code is different from the initial operation code, or if the first response result is detected to be incorrect, the first response data is not the target first response data corresponding to the initial operation code, and the first instruction data needs to be retransmitted to the lower computer within the limit of the maximum number of failed retries to obtain the target first response data.

[0077] In some embodiments, if the first response data is not received within the maximum timeout time for instruction execution, the first response data is lost or the first instruction data is lost, and the first instruction data needs to be retransmitted to the lower computer within the limit of the maximum number of failed retries to obtain the target first response data.

[0078] In some embodiments, if the first response data is still not received within the limit of the maximum number of failed retries, the execution of the first instruction data fails, and the failure result is reported to the service layer so that the service layer can record the fault or notify of the fault.

[0079] In some embodiments, if the first response data is still not received within the maximum number of failed retries, it further includes: the lower computer enables the upper computer function to detect whether a fault occurs in the upper computer and the lower computer. Specifically, it includes: the lower computer installs and starts a second application program to enable the upper computer function, constructs second instruction data carrying the initial operation code according to the second application program, and sends the second instruction data to the upper computer, so that after the upper computer enables the lower computer function, it receives and executes the second instruction data and feeds back the second response data carrying the initial operation code; if the second response data is received correctly, no fault occurs in the upper computer and the lower computer.

[0080] In some embodiments, if the second response data is received correctly, stopping sending the second instruction data includes: if the second response data is received within the preset time limit, parsing the second response data to obtain a feedback operation code and a second response result, and the feedback operation code is the same as the initial operation code, and detecting that the second response result is correct, then stopping sending the second response data, and no fault occurs in the upper computer and the lower computer.

[0081] This application enables the upper-level mechanism to construct the first instruction data through the first application program, and adds an initial operation code to the first instruction. Through the comparison mechanism between the initial operation code and the feedback operation code fed back by the lower-level machine after receiving the first instruction data, if the initial operation code is different from the feedback operation code, retransmission is performed within a preset time limit, and the response mechanism is used to avoid blindly increasing the redundant transmission and execution of instruction data, thereby improving the serial port communication efficiency at the software level. Moreover, based on the retransmission within the preset time limit, it is possible to ensure the successful execution of the instruction data as much as possible, thereby improving the success rate of service execution and further improving the serial port communication efficiency.

[0082] Those skilled in the art should understand that the embodiments of this application may also provide a computer program product. Therefore, this application may be implemented in the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware aspects. Moreover, this application may be implemented in the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0083] This application is described with reference to the flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to the embodiments of this application. It should be understood that each process and / or block in the flowchart and / or block diagram, and the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to the processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing devices to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing devices generate for implementing in the process Figure 1 one process or multiple processes and / or blocks Figure 1 a device for the functions specified in one block or multiple blocks.

[0084] These computer program instructions can also be stored in a computer-readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer-readable memory generate a manufactured product including an instruction device, and the instruction device implements in the process Figure 1 one process or multiple processes and / or blocks Figure 1 a device for the functions specified in one block or multiple blocks.

[0085] These computer program instructions can also be loaded onto a computer or other programmable data processing device, so that a series of operation steps are performed on the computer or other programmable device to generate a computer-implemented process, and thus the instructions executed on the computer or other programmable device provide for implementing in the process Figure 1 one process or multiple processes and / or blocks Figure 1Steps of the functions specified in one or more boxes.

[0086] The above are only the preferred embodiments of the present application. It should be noted that for those of ordinary skill in the art, without departing from the technical principle of the present application, several improvements and modifications can be made, and these improvements and modifications should also be regarded as the protection scope of the present application.

Claims

1. A serial communication control method, applied to a host computer, characterized in that, The serial communication control method includes: Starting a first application to enable the host computer function, constructing first instruction data carrying an initial operation code according to the first application, and sending the first instruction data to the lower computer, so that after the lower computer receives and executes the first instruction data, it feeds back first response data carrying a feedback operation code, wherein the first instruction data is instruction data constructed by the host computer according to the initial operation code and the service data of the host computer; If the first response data is received within a preset time limit, parse the first response data to obtain the feedback operation code. If the feedback operation code is different from the initial operation code, the first response data is not the target first response data corresponding to the initial operation code, and the first instruction data needs to be retransmitted to the lower computer within the preset time limit to obtain the target first response data; Wherein, the preset time limit includes: the maximum instruction execution timeout time and the maximum number of failed retries; wherein, obtaining the target first response data includes: If the first response data is received within the maximum instruction execution timeout time, parse the first response data to obtain a feedback operation code and a first response result; If the feedback operation code is different from the initial operation code, or it is detected that the first response result is incorrect, the first response data is not the target first response data corresponding to the initial operation code, and the first instruction data needs to be retransmitted to the lower computer within the limit of the maximum number of failed retries to obtain the target first response data; Wherein, if the first response data is not received within the maximum instruction execution timeout time, the first response data is lost or the first instruction data is lost, and the first instruction data needs to be retransmitted to the lower computer within the limit of the maximum number of failed retries to obtain the target first response data.

2. The serial port communication control method according to claim 1, wherein If the first response data is still not received within the limit of the maximum number of failed retries, the execution of the first instruction data fails, and the failure result is reported to the service layer so that the service layer can record the fault or notify of the fault.

3. The serial port communication control method according to claim 2, characterized in that, If the first response data is still not received within the maximum number of failed retries, it further includes: the lower computer enables the host computer function to detect whether a fault occurs in the host computer and the lower computer, specifically including: The lower computer installs and starts a second application to enable the host computer function, constructs second instruction data carrying the initial operation code according to the second application, and sends the second instruction data to the host computer, so that after the host computer enables the lower computer function, it receives and executes the second instruction data and feeds back second response data carrying the initial operation code; If the second response data is received correctly, no fault occurs in the host computer and the lower computer.

4. The serial port communication control method according to claim 3, characterized in that The step of stopping sending the second instruction data if the second response data is received correctly includes: If the second response data is received within the preset time limit, parse the second response data to obtain the feedback operation code and the second response result, and the feedback operation code is the same as the initial operation code, and if it is detected that the second response result is correct, stop sending the second response data, and there is no fault in the host computer and the slave computer.

5. The serial port communication control method according to claim 1, characterized in that, After the slave computer receives and executes the first instruction data, it feeds back the first response data carrying the feedback operation code, including: After the slave computer receives and parses the first instruction data, it obtains the service data and the initial operation code. If it is detected that the service data is correct, it executes the first instruction data to obtain the first response result, constructs the first response data according to the first response result and the initial operation code, and transmits the first response data to the host computer.

6. The serial port communication control method according to claim 5, characterized in that, After detecting that the service data is incorrect, it includes: Discard the first instruction data and wait again within the preset time limit to receive the first instruction data retransmitted by the host computer; or, Discard the first instruction data and send a retransmission response to the host computer, so that after the host computer receives the retransmission response, it retransmits the first instruction data to the slave computer; the retransmission response includes: a retransmission identifier and the feedback operation code.

7. The serial port communication control method according to claim 1, wherein The enabling of the host computer function by starting the first application program includes: Start the first application program and initialize the preset time limit, so that the host computer is in a pre-state of constructing the first instruction data.

8. A serial communication control system is applied to a host computer, characterized in that, The serial communication control system includes: a command construction module and a response receiving module; where, The command construction module is used to enable the host computer function by starting the first application program, construct the first instruction data carrying the initial operation code according to the first application program, and send the first instruction data to the slave computer, so that after the slave computer receives and executes the first instruction data, it feeds back the first response data carrying the feedback operation code, where the first instruction data is the instruction data constructed by the host computer according to the initial operation code and the service data of the host computer; The response receiving module is used to, if the first response data is received within the preset time limit, parse the first response data to obtain the feedback operation code. If the feedback operation code is different from the initial operation code, the first response data is not the target first response data corresponding to the initial operation code, and the first instruction data needs to be retransmitted to the slave computer within the preset time limit to obtain the target first response data; Wherein, the preset time limit includes: the maximum instruction execution timeout and the maximum number of failed retries; wherein, obtaining the target first response data includes: If the first response data is received within the maximum instruction execution timeout, parse the first response data to obtain the feedback operation code and the first response result; If the feedback operation code is different from the initial operation code, or the first response result is detected as incorrect, then the first response data is not the target first response data corresponding to the initial operation code, and it is necessary to retransmit the first instruction data to the lower computer within the limit of the maximum number of failed retries to obtain the target first response data; Among them, if the first response data is not received within the maximum instruction execution timeout period, then the first response data is lost or the first instruction data is lost, and it is necessary to retransmit the first instruction data to the lower computer within the limit of the maximum number of failed retries to obtain the target first response data.

Citation Information

Patent Citations

  • Robot communication method and system, readable storage medium and robot

    CN107861506A

  • Serial port communication method, lower computer and serial port communication system

    CN115794691A

  • PLC online monitoring and debugging system and implementation method thereof

    CN116149253A

  • Communication instruction sending method, electronic equipment, medical system and related products

    CN116781229A