Serial port communication control method and system
By introducing an opcode response mechanism and a failure retry mechanism into serial communication, the problems of low serial communication efficiency and data loss are solved, communication efficiency and reliability are improved, and instruction data is successfully executed.
Patent Information
- Application Number
- CN202410834725.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-26
- Publication Date
- 2024-10-15
- Estimated Expiration
- 2044-06-26
AI Technical Summary
The existing serial port communication efficiency is low and data loss or bit errors are prone to occur. The existing software error correction method repeatedly sends and receives many times, resulting in low efficiency.
By introducing an opcode response mechanism and a failure retry mechanism into serial communication, the comparison of the initial opcode and the feedback opcode is used to retransmit only when necessary, avoiding redundant transmission and execution, and ensuring the successful execution of instruction data.
It improves the efficiency and reliability of serial communication, reduces the waste of computing resources, enhances the success rate of business execution, detects fault causes in time, and avoids invalid operations.
Smart Images

Figure CN118784168A_ABST
Abstract
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] The present application enables the host computer to construct the function of the first instruction data through the first application program, and adds an initial operation code in the first instruction, and constructs a comparison mechanism through the initial operation code and the feedback operation code fed back by the lower computer after receiving the first instruction data. If the initial operation code and the feedback operation code are different, they are retransmitted within a preset time limit, and a displayed response mechanism is used to avoid blindly increasing the redundant transmission and execution of the instruction data, thereby improving the serial port communication efficiency based on the software level, and the retransmission based on the preset time limit can ensure the successful execution of the instruction data as much as possible, thereby improving the success rate of business execution and further improving the serial port communication efficiency.
[0009] Further, the preset time limit includes: a maximum timeout time for command execution and a maximum number of failed retries; wherein obtaining the target first response data includes:
[0010] If the first response data is received within the maximum timeout period for executing the instruction, parsing the first response data to obtain a feedback operation code and a first response result;
[0011] If the feedback operation code is different from the initial operation code, or 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 must be retransmitted to the lower computer within 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 timeout period for executing the instruction, 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 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, the execution of the first instruction data fails, and the failure result is reported to the business layer so that the business layer performs fault recording or fault notification.
[0014] Further, if the first response data is still not received within the maximum number of failed retries, the method further includes: the lower computer enables the upper computer function to detect whether the upper computer and the lower computer fail, specifically including:
[0015] The lower computer installs and starts a second application to enable the upper computer function, and constructs second instruction data carrying the initial operation code according to the second application, 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 second response data carrying the initial operation code;
[0016] If the second response data is received correctly, then the upper computer and the lower computer are not faulty.
[0017] The present application converts the function of the lower computer through software programming so that it has the function of the upper computer to actively send the second instruction data, so that after the upper computer sends the first instruction data and still cannot receive the target first response data, troubleshooting can be performed, and the cause of the fault can be discovered in time to avoid invalid operations in which the target response data cannot be obtained after other types of instructions are executed, thereby improving the reliability of serial port communication.
[0018] Further, if the received second response data is correct, 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 the second response result is detected to be correct, then the sending of the second response data is stopped, and no failure occurs to the upper computer and the lower computer.
[0020] Further, after receiving and executing the first instruction data, the lower computer feeds back first response data carrying a feedback operation code, including:
[0021] After receiving and parsing the first instruction data, the lower computer obtains the business data and the initial operation code. If the business data is detected to be correct, the first instruction data is executed to obtain a first response result. According to the first response result and the initial operation code, the first response data is constructed and transmitted to the upper computer.
[0022] Further, if the business data error is detected, the following steps are included:
[0023] discard the first instruction data, and wait again within the preset time limit for receiving the first instruction data retransmitted by the host computer; or,
[0024] The first instruction data is discarded, and a retransmission response is sent to the upper computer, so that after the upper computer receives the retransmission response, it retransmits the first instruction data to the lower set; the retransmission response includes: a retransmission identifier and the feedback operation code.
[0025] Further, starting the first application to enable the host computer function includes:
[0026] The first application is started and the preset time limit is initialized so that the host computer is in a preliminary 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 receiving response module; wherein,
[0028] The construction instruction module is used to start the first application to enable the upper computer function, construct the first instruction data carrying the initial operation code according to the first application, and send the first instruction data to the lower computer, so that the lower computer receives and executes the first instruction data and then feeds back the first response data carrying the feedback operation code;
[0029] The receiving response module is used to parse the first response data and obtain the feedback operation code if the first response data is received within a preset time limit. 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. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] Figure 1 It is a flowchart of a serial communication control method provided in an embodiment of the present application;
[0031] Figure 2 It is a structural diagram of a serial communication control system provided in an embodiment of the present application. DETAILED DESCRIPTION
[0032] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0033] It is worth noting that the existing software-based error correction technology has redundant execution of instructions. If the instruction data sent each time is correct, the lower-level hardware will execute the same instruction multiple times, causing a huge waste of computing resources in high-frequency instruction processing scenarios. In addition, it lacks a response mechanism. If the instruction data sent each time is wrong, the instruction will fail to execute, but the upper-level software does not know that the lower-level hardware has failed to execute, resulting in inconsistent data after the operation between the business layer and the hardware.
[0034] Based on this, the present application adds an opcode response mechanism in the instruction data to solve the problem of redundant instruction execution; and gives the operation of adding opcodes, and then adds a failure retry mechanism, to retry a certain number of times when the instruction sending fails, to ensure the successful execution of the instruction as much as possible, and to notify the business layer to make log records or manual intervention after complete failure, so as to improve the efficiency of serial port communication.
[0035] In order to more clearly illustrate the scheme of the present application, it will be described in detail from the following examples.
[0036] Example 1
[0037] See also Figure 1 , is a flow chart of a serial communication control method provided in an embodiment of the present application, comprising: steps S11 to S12, specifically:
[0038] Step S11, start the first application to enable the upper computer function, construct the first instruction data carrying the initial operation code according to the first application, 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 operation code.
[0039] It is worth noting that the first application is a programming software executed by the host computer, which is used to construct the first instruction data, and the second application mentioned later is a programming software executed by the lower computer after the lower computer enables the host computer function (that is, the lower computer has the host computer function), which is used to construct the second instruction data; the first instruction data is instruction data constructed by the upper computer according to the initial operation code and the business data of the upper computer (including: operation instructions), and the second instruction data is instruction data constructed by the lower computer according to the initial operation code and the business data of the lower computer (including: operation instructions); the first response data is the response data generated by the lower computer after receiving and executing the first instruction data, and the second response data is the response data generated by the upper computer after receiving and executing the second instruction data.
[0040] In some embodiments, starting the first application to enable the host computer function includes: starting the first application and initializing a preset time limit to put the host computer in a pre-state for constructing the first instruction data.
[0041] It is worth noting 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: a maximum timeout period for instruction execution and a maximum number of failed retries.
[0043] In some embodiments, the host computer software starts and initializes relevant parameters, which may be preset parameters; wherein max_request_timeout indicates the maximum timeout for instruction execution, and max_retry_count indicates the maximum number of failed retries.
[0044] In some embodiments, first instruction data carrying an initial operation code is constructed according to a first application, including: according to the first application, adding a unique initial operation code action_code to the instruction data, 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 the lower computer to respond.
[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, it obtains business data and an initial operation code. If the business data is detected to be correct, it executes the first instruction data to obtain a first response result. According to the first response result and the initial operation code, it constructs first response data, and transmits the first response data to the upper computer.
[0046] It is worth noting that the first response result is that after the lower computer receives the first instruction data of the upper computer, it parses the first instruction data, obtains the initial operation code and business data corresponding to the first instruction data, and then executes the business data to generate a response result; the second response result is that after the upper computer receives the second instruction data of the lower computer, it parses the second instruction data, obtains the initial operation code and business data corresponding to the second instruction data, and then executes the business data to generate a response result.
[0047] In some embodiments, if a business data error is detected, it includes: discarding the first instruction data and waiting for the host computer to retransmit the first instruction data within a preset time limit; 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 downstream set; the retransmission response includes: a retransmission flag 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 business data. If the business data is wrong, the first instruction data is discarded; if the business data is correct, the first instruction data is executed to obtain the first response data, and the first response data is constructed according to the first response data and the initial operation code action_code, and then the first response data is sent to the upper computer software.
[0049] It is worth noting that the operation code (including: initial operation code and feedback operation code) is only used to associate the request and response of the current operation. The operation code carried in the request data of the upper computer must be returned by the lower computer in the response data as it is, so that the upper computer can identify which request the 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, the first response data is parsed 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 must be retransmitted to the lower computer within the preset time limit to obtain the target first response data.
[0051] It is worth noting 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 upper computer to the lower computer.
[0052] In some embodiments, after receiving the first response data, the host computer parses it to obtain a feedback operation code and a first response result. If the first response result is detected to be correct, it is determined that there is no data error caused by a bit error. If the feedback operation code is detected to be the same as the initial operation code, it is determined that the request and response are consistent.
[0053] In some embodiments, if there is no data error caused by a bit error, and the request is consistent with the response, it means that the instruction is executed successfully, and the first response result is transmitted to the business 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 period of instruction execution, parsing the first response data to obtain a feedback opcode and a first response result; if the feedback opcode is different from the initial opcode, or an error is detected in the first response result, the first response data is not the target first response data corresponding to the initial opcode, and the first instruction data must be retransmitted to the downstream 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 period of the 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 downstream computer within 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 maximum number of failed retries, the first instruction data execution fails, and the failure result is reported to the business layer so that the business layer performs fault recording or fault notification.
[0057] In some embodiments, if no response is received from the lower computer within the maximum timeout period max_request_timeout for instruction execution, it is determined that the data has been lost (including: the first instruction data and the first response data) and a failed retry is performed quickly. If no response is received from the lower computer within the maximum number of failed retries max_retry_count, the instruction execution is determined to have failed and the result is reported to the business layer, which records the fault or notifies human intervention.
[0058] In some embodiments, a response from the lower computer is received within the maximum timeout period max_request_timeout for instruction execution. If the data is incorrect due to a bit error (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 failed retry is performed quickly. If no response from the lower computer is received within the maximum number of failed retries max_retry_count, the instruction execution is deemed to have failed and the result is reported to the business layer, which records the fault or notifies human intervention.
[0059] In some embodiments, by connecting the lower computer to different serial ports on the upper computer serial controller, the upper computer can simultaneously communicate with multiple lower computers via serial ports; wherein, the lower computers corresponding to different serial ports use different communication protocols or instruction data, and each lower computer processes its own data in a process isolation manner based on the application software. Specifically, the communication protocols or instructions of different lower computers are generally different, and all software generally adopts a process isolation method for communication with different serial ports, each processing its own communication data without interfering with each other, and each verifies whether its own protocol data is correct. Verification rules belong to the business layer and can be flexibly formulated according to actual conditions.
[0060] In some embodiments, the initial operation code in the first instruction data sent by the upper computer to the lower computer each time may be the same operation code, or different operation codes; if different operation codes are used as the initial operation codes, 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 failed retries, it also includes: the lower computer enables the upper computer function to detect whether the upper computer and the lower computer have faults, specifically including: the lower computer installs and starts the second application to enable the upper computer function, and constructs second instruction data carrying an initial operation code according to the second application, 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, then there is no fault in the upper computer and the lower computer.
[0062] It is worth noting that, based on software programming, the upper computer has the upper computer function and the lower computer has the lower computer function. When the lower computer has not been able to feedback the correct first response data that complies with the operation code, the second application is installed and started on the lower computer to enable the lower computer to have the upper computer function, so that the lower computer actively sends the second instruction data, and the upper computer receives and executes the second response data and then feeds back the second response data. Within the limits of the maximum timeout time max_request_timeout and the maximum number of failed retries max_retry_count for instruction execution, the lower computer receives the second response data fed back by the upper computer, so as to determine the reason why the lower computer cannot always feed back the corresponding target first response data after the upper computer sends the first instruction data, so as to timely discover the cause of the fault, avoid the invalid operation that still cannot obtain the target response data after other types of instructions are executed, and thus improve the reliability of serial communication.
[0063] In some embodiments, if the second response data is received correctly, then the upper computer and the lower computer have not failed, including: the lower computer receives and parses the second response data, obtains the second response result and feedback operation code corresponding to the second response data, if the second response result is detected to be correct, there is no error code, if the feedback operation code is the same as the initial operation code, then the request and response are consistent, if there is no error code and the request and response are consistent at the same time, then the upper computer and the lower computer have not failed; otherwise, the upper computer or the lower computer fails, and it needs to be reported to the business layer so that the business layer can record the fault or notify the fault.
[0064] The present application converts the function of the lower computer through software programming so that it has the function of the upper computer to actively send the second instruction data, so that after the upper computer sends the first instruction data and still cannot receive the target first response data, troubleshooting can be performed, and the cause of the fault can be discovered in time to avoid invalid operations in which the target response data cannot be obtained after other types of instructions are executed, thereby improving the reliability of serial port communication.
[0065] In some embodiments, if the second response data is received correctly, the second instruction data is stopped from being sent, including: if the second response data is received within a preset time limit, the second response data is parsed 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 the second response result is detected to be correct, then the second response data is stopped from being sent, and no failure occurs in the upper computer and the lower computer.
[0066] The present application adds an opcode response mechanism to the instruction data to explicitly feedback the instruction execution results, thereby solving the problem of redundant instruction execution, saving unnecessary computing resource loss, improving the efficiency of serial communication, and greatly improving the reliability of serial communication; and, based on the opcode response mechanism, adding a failure retry mechanism can ensure the successful execution of instructions to the greatest extent possible and improve the success rate of business execution.
[0067] Example 2
[0068] See also Figure 2 , is a structural diagram of a serial communication control system provided in an embodiment of the present application, which is applied to a host computer. The serial communication control system includes: a construction instruction module 21 and a receiving response module 22.
[0069] In some embodiments, after constructing the instruction module 21 to enable the upper computer, it outputs the first instruction data to the lower computer, and the lower computer feeds back the first response data to the receiving response module 22. After receiving the first response data, the receiving response module 22 performs data judgment to output the target first response data.
[0070] The instruction module 21 is constructed to start the first application to enable the upper computer function, construct the first instruction data carrying the initial operation code according to the first application, 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 operation code.
[0071] In some embodiments, starting the first application to enable the host computer function includes: starting the first application and initializing a preset time limit to put the host computer in a pre-state for constructing the first instruction data.
[0072] 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, it obtains business data and an initial operation code. If the business data is detected to be correct, it executes the first instruction data to obtain a first response result. According to the first response result and the initial operation code, it constructs first response data, and transmits the first response data to the upper computer.
[0073] In some embodiments, if a business data error is detected, it includes: discarding the first instruction data and waiting for the host computer to retransmit the first instruction data within a preset time limit; 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 downstream set; the retransmission response includes: a retransmission flag and a feedback operation code.
[0074] The receiving response module 22 is used to parse the first response data and obtain a feedback operation code if the first response data is received within a preset time limit. 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: a maximum timeout period for instruction execution and a maximum number of failed retries.
[0076] In some embodiments, obtaining the target first response data includes: if the first response data is received within the maximum timeout period of instruction execution, parsing the first response data to obtain a feedback opcode and a first response result; if the feedback opcode is different from the initial opcode, or an error is detected in the first response result, the first response data is not the target first response data corresponding to the initial opcode, and the first instruction data must be retransmitted to the downstream 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 period of the 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 downstream computer within 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 maximum number of failed retries, the first instruction data execution fails, and the failure result is reported to the business layer so that the business layer performs fault recording or fault notification.
[0079] In some embodiments, if the first response data is still not received within the maximum number of failed retries, it also includes: the lower computer enables the upper computer function to detect whether the upper computer and the lower computer have faults, specifically including: the lower computer installs and starts the second application to enable the upper computer function, and constructs second instruction data carrying an initial operation code according to the second application, 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, then there is no fault in the upper computer and the lower computer.
[0080] In some embodiments, if the second response data is received correctly, the second instruction data is stopped from being sent, including: if the second response data is received within a preset time limit, the second response data is parsed 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 the second response result is detected to be correct, then the second response data is stopped from being sent, and no failure occurs in the upper computer and the lower computer.
[0081] The present application enables the host computer to construct the function of the first instruction data through the first application program, and adds an initial operation code in the first instruction. Through the comparison mechanism between the initial operation code and the feedback operation code fed back by the lower computer after receiving the first instruction data, if the initial operation code and the feedback operation code are different, they are retransmitted within a preset time limit, so as to avoid blindly increasing the redundant transmission and execution of the instruction data through a displayed response mechanism, thereby improving the serial port communication efficiency based on the software level, and the retransmission based on the preset time limit can ensure the successful execution of the instruction data as much as possible, thereby improving the success rate of business execution and further improving the serial port communication efficiency.
[0082] Those skilled in the art will appreciate that the embodiments of the present application may also provide computer program products. Therefore, the present application may adopt the form of complete hardware embodiments, complete software embodiments, or embodiments in combination with software and hardware. Moreover, the present application may adopt the form of computer program products implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program codes.
[0083] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0084] These computer program instructions may also be stored in a computer readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0085] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1The steps for the functions specified in one or more boxes.
[0086] The above is only a preferred implementation of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the technical principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.
Claims
1. A serial communication control method, applied to a host computer, characterized in that: The serial port communication control method comprises: 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; 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.
2. The serial communication control method according to claim 1, characterized in that: The preset time limit includes: the maximum timeout time for command execution 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 timeout period for executing the instruction, 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 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 must be retransmitted to the lower computer within the maximum number of failed retries to obtain the target first response data.
3. The serial communication control method according to claim 2, characterized in that: If the first response data is not received within the maximum timeout period of the 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 maximum number of failed retries to obtain the target first response data.
4. The serial communication control method according to any one of claims 2 or 3, characterized in that: 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 business layer so that the business layer performs fault recording or fault notification.
5. The serial communication control method according to claim 4, characterized in that: If the first response data is still not received within the maximum number of failed retries, the method further includes: the lower computer enables the upper computer function to detect whether the upper computer and the lower computer fail, specifically including: The lower computer installs and starts a second application to enable the upper computer function, and constructs second instruction data carrying the initial operation code according to the second application, 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 second response data carrying the initial operation code; If the second response data is received correctly, then the upper computer and the lower computer are not faulty.
6. The serial communication control method according to claim 5, characterized in that: 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, 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 the second response result is detected to be correct, then the sending of the second response data is stopped, and no failure occurs to the upper computer and the lower computer.
7. The serial communication control method according to claim 1, wherein: After receiving and executing the first instruction data, the lower computer feeds back first response data carrying a feedback operation code, including: After receiving and parsing the first instruction data, the lower computer obtains the business data and the initial operation code. If the business data is detected to be correct, the first instruction data is executed to obtain a first response result. According to the first response result and the initial operation code, the first response data is constructed and transmitted to the upper computer.
8. The serial communication control method according to claim 7, characterized in that: If the business data error is detected, it includes: discard the first instruction data, and wait again within the preset time limit for receiving the first instruction data retransmitted by the host computer; or, The first instruction data is discarded, and a retransmission response is sent to the upper computer, so that after the upper computer receives the retransmission response, it retransmits the first instruction data to the lower set; the retransmission response includes: a retransmission identifier and the feedback operation code.
9. The serial communication control method according to claim 1, wherein: The starting of the first application to enable the host computer function includes: The first application is started and the preset time limit is initialized so that the host computer is in a preliminary state of constructing the first instruction data.
10. A serial communication control system, applied to a host computer, characterized in that: The serial communication control system includes: a construction instruction module and a receiving response module; wherein, The construction instruction module is used to start the first application to enable the upper computer function, construct the first instruction data carrying the initial operation code according to the first application, and send the first instruction data to the lower computer, so that the lower computer receives and executes the first instruction data and then feeds back the first response data carrying the feedback operation code; The receiving response module is used to parse the first response data and obtain the feedback operation code if the first response data is received within a preset time limit. 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.
Citation Information
Patent Citations
Robot communication method and system, readable storage medium and robot
CN107861506A
Data packet processing method and device
CN112673586A
Serial port communication method, lower computer and serial port communication system
CN115794691A
Remote fault monitoring system and method based on PLC cabinet
CN115826563A
PLC online monitoring and debugging system and implementation method thereof
CN116149253A
