Serial port asynchronous full duplex message automatic processing method and system and storage medium

By creating multiple queues and threads in the serial communication system, the automatic processing of asynchronous full-duplex packets is solved, and the problems of low communication delay and processing efficiency in the existing technology are improved, and the system's response speed and processing capabilities are improved.

CN119483872APending Publication Date: 2025-02-18XIAMEN INTRETECH
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202411515085.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-29
Publication Date
2025-02-18

AI Technical Summary

Technical Problem

The existing serial port full-duplex communication technology has problems of communication delay and low processing efficiency, especially in high-frequency communication scenarios.

Method used

By creating a queue to be sent, a queue to be answered and a queue to be processed, and starting multiple threads or processes are responsible for message sending, receiving, processing and timeout detection respectively, asynchronous full-duplex message automatic processing is realized.

Benefits of technology

It improves the efficiency of message processing and the system response speed, reduces communication delay and processing delay, and can better cope with high load conditions.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119483872A_ABST
    Figure CN119483872A_ABST
Patent Text Reader

Abstract

The invention discloses a serial port asynchronous full duplex message automatic processing method and system and a storage medium. The method comprises the following steps: creating a to-be-sent queue, a to-be-responded queue and a to-be-processed queue; creating a message processing method, a message sending failure processing method and a message timeout processing method according to the message protocol type, and respectively filling the message processing method, the message sending failure processing method and the message timeout processing method into corresponding chain tables; receiving a request message and adding the request message to the tail of the queue to be sent; extracting the message from the queue to be sent and sending the message to a serial port; if the request message is successfully sent, adding the request message to a queue to be responded, and if the request message is failed to be sent, retrieving a corresponding method from a message sending failure processing method chain table and processing the corresponding method; reading the received message from the serial port, adding the received message to the tail of the queue to be processed, and then continuing to receive the next message; reading the message from the column head of the queue to be processed, and processing the message according to the message type; and starting an overtime processing thread or process, wherein the thread or process is responsible for monitoring whether the message in the queue to be responded is overtime or not.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to the field of communication technology, and in particular to a method, system and storage medium for automatically processing serial port asynchronous full-duplex messages. Background Art

[0002] In the field of modern communications, serial communication is a common data transmission method, which is widely used in various electronic devices and systems. Traditional serial communication is usually half-duplex or simplex, that is, only sending or receiving operations can be performed at any time, which limits the efficiency of data transmission. With the development of technology, full-duplex serial communication technology has gradually become possible, which allows data to be transmitted in both directions at the same time, greatly improving communication efficiency.

[0003] However, the existing full-duplex serial communication technology still has some shortcomings in practical applications. First, after sending a message, the system usually needs to block and wait for the arrival of the reply message or timeout, which causes communication delays. Second, after receiving a message, the system needs to process the current message before receiving a new message, which may cause the reception of the new message to be delayed, especially in high-frequency communication scenarios. This delay may affect the overall performance of the system.

[0004] Therefore, the existing message processing method has the problems of communication delay and low processing efficiency. Summary of the invention

[0005] The main purpose of the present invention is to provide a method, system and storage medium for automatically processing serial port asynchronous full-duplex messages, aiming to solve the technical problems of communication delay and low processing efficiency in existing message processing methods.

[0006] To achieve the above object, the present invention provides a method for automatically processing serial port asynchronous full-duplex messages, which comprises the following steps:

[0007] Create queues to be sent, queues to be replied, and queues to be processed;

[0008] Create a message processing method, a message sending failure processing method, and a message timeout processing method according to the message protocol type, and fill them into the corresponding message processing method linked list, message sending failure processing linked list, and message timeout processing linked list respectively;

[0009] When receiving a request message sent by a user, the request message is added to the tail of the queue to be sent;

[0010] Start a message sending thread or process, which is responsible for taking out the message from the waiting queue and sending it to the serial port; if the sending is successful, the request message is added to the waiting reply queue; if the sending fails, the corresponding method is retrieved from the message sending failure processing method list and processed;

[0011] Start a message receiving thread or process, which is responsible for reading the received message from the serial port, adding it to the end of the queue to be processed, and then continuing to receive the next message;

[0012] Start a message processing thread or process, which is responsible for reading messages from the queue header to be processed and processing the messages according to the message type;

[0013] Start a timeout processing thread or process, which is responsible for monitoring whether the message in the waiting reply queue has timed out.

[0014] Optionally, when monitoring whether the messages in the waiting-for-response queue have timed out, only the first message at the head of the waiting-for-response queue is checked each time to see if it has timed out. If so, the corresponding method is retrieved from the message timeout processing method linked list and processed; if not, it returns immediately.

[0015] Optionally, the queue to be sent is used to store messages that need to be sent to the serial port, the queue to be replied is used to store request messages that have been sent successfully, and the queue to be processed is used to store request messages and reply messages received from the serial port.

[0016] Optionally, the message processing is performed according to the message type:

[0017] For the request message, after processing it according to the message protocol processing method, a response message is generated and added to the queue to be sent;

[0018] For the reply message, the corresponding request message is retrieved from the waiting reply queue using the message protocol and message sequence number. If the corresponding request message is found, it is processed according to the message protocol processing method. If the corresponding request message is not found, the reply message is discarded.

[0019] Optionally, when adding the request message to the waiting-for-response queue, the time at which the request message was sent is also added to the waiting-for-response queue.

[0020] Optionally, a corresponding method is retrieved from a linked list of methods for handling message sending failures, specifically, the retrieval is performed based on the message protocol type.

[0021] Optionally, the message sending thread or process, the message receiving thread or process, the message processing thread or process, and the timeout processing thread or process are all executed concurrently.

[0022] Optionally, the processing methods in the message processing method linked list, the message sending failure processing method linked list and the message timeout processing method linked list all support dynamic addition and deletion.

[0023] Corresponding to the method for automatically processing serial port asynchronous full-duplex messages, the present invention provides a system for automatically processing serial port asynchronous full-duplex messages, which comprises:

[0024] The queue management module is used to create queues to be sent, queues to be answered and queues to be processed;

[0025] A linked list management module, used to create a message processing method, a message sending failure processing method and a message timeout processing method according to the message protocol type, and fill them into the corresponding message processing method linked list, message sending failure processing linked list and message timeout processing linked list respectively;

[0026] A message sending module is used to add the request message to the tail of the queue to be sent when receiving the request message sent by the user; and to start a message sending thread or process to take out the message from the queue to be sent and send it to the serial port; if the sending is successful, the request message is added to the queue to be replied; if the sending fails, the corresponding method is retrieved from the message sending failure processing method chain list and processed;

[0027] The message receiving module is used to start a message receiving thread or process, which is responsible for reading the received message from the serial port, adding it to the end of the queue to be processed, and then continuing to receive the next message;

[0028] The message processing module is used to start a message processing thread or process, which is responsible for reading messages from the head of the queue to be processed and processing the messages according to the message type;

[0029] The timeout processing module is used to start a timeout processing thread or process, which is responsible for monitoring whether the message in the waiting reply queue has timed out.

[0030] In addition, to achieve the above-mentioned purpose, the present invention also provides a computer-readable storage medium, on which a serial port asynchronous full-duplex message automatic processing program is stored. When the serial port asynchronous full-duplex message automatic processing program is executed by a processor, the steps of the serial port asynchronous full-duplex message automatic processing method as described above are implemented.

[0031] The beneficial effects of the present invention are:

[0032] (1) Compared with the prior art, the present invention uses a queue to be sent and a dedicated sending thread or process. When a message is to be sent, it only needs to be added to the queue to be sent, and the sending thread or process is responsible for sending it. There is no need to add the message to send it, thus realizing automatic sending. Through the queue to be replied, the timeout processing thread or process, and the message receiving thread or process, after the request message is sent, it is not necessary to block until the reply message arrives or times out, and the next message can be sent immediately, thus realizing instant sending. After receiving a message, it only needs to add the message to the queue to be processed, and it does not need to process the message, and it can return to receive the next message. There is no delay in receiving a new message due to the need to process the received message, thus realizing instant reception. Multiple processing linked lists are created to realize efficient management and processing of messages. The system will not block each other when sending, receiving and processing messages, thus improving the efficiency of message processing and the response speed of the system.

[0033] (2) Compared with the prior art, the present invention improves the efficiency of timeout processing by only checking whether the first message at the head of the waiting-for-response queue has timed out, while ensuring that the timed-out message can be processed in time, thereby reducing the resource consumption of timeout checking;

[0034] (3) Compared with the prior art, the present invention clarifies the functions and uses of each queue, and stores different types of messages in dedicated queues, making message management clearer and more efficient, facilitating rapid location and processing of messages, and improving system stability and reliability;

[0035] (4) Compared with the prior art, the present invention ensures that the message can be correctly processed and responded to by processing the request message and the response message separately, thereby improving the accuracy of message processing and the interactivity of the system;

[0036] (5) Compared with the prior art, the present invention makes timeout detection more accurate by recording the sending time of the request message in the waiting queue, which helps the system to manage the life cycle of the message more effectively and avoid data loss or error caused by timeout;

[0037] (6) Compared with the prior art, the present invention realizes the parallel operation of message sending, receiving, processing and timeout detection by concurrently executing multiple threads or processes, which greatly improves the processing capacity and efficiency of the system and enables the system to better cope with high load conditions;

[0038] (7) Compared with the prior art, the present invention allows dynamic addition and deletion of processing methods, provides a high degree of flexibility and scalability, can adapt to changing needs and protocol types, and facilitates system maintenance and upgrades. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of the present invention. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:

[0040] Figure 1 A simplified flow chart of an embodiment of a method for automatically processing a serial port asynchronous full-duplex message according to the present invention;

[0041] Figure 2 It is a framework diagram of an embodiment of a system for automatically processing serial port asynchronous full-duplex messages according to the present invention. DETAILED DESCRIPTION

[0042] In order to make the purpose, technical scheme and advantages of the embodiments of the present invention clearer, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, rather than all the embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.

[0043] like Figure 1 As shown, a method for automatically processing a serial port asynchronous full-duplex message of the present invention comprises the following steps:

[0044] Create queues to be sent, queues to be replied, and queues to be processed;

[0045] Create a message processing method, a message sending failure processing method, and a message timeout processing method according to the message protocol type, and fill them into the corresponding message processing method linked list, message sending failure processing linked list, and message timeout processing linked list respectively;

[0046] When receiving a request message sent by a user, add the request message to the tail of the queue to be sent;

[0047] Start a message sending thread or process, which is responsible for taking out the message from the waiting queue and sending it to the serial port; if the sending is successful, the request message is added to the waiting reply queue; if the sending fails, the corresponding method is retrieved from the message sending failure processing method list and processed;

[0048] Start a message receiving thread or process, which is responsible for reading the received message from the serial port, adding it to the end of the queue to be processed, and then continuing to receive the next message;

[0049] Start a message processing thread or process, which is responsible for reading messages from the queue header to be processed and processing the messages according to the message type;

[0050] Start a timeout processing thread or process, which is responsible for monitoring whether the message in the waiting reply queue has timed out.

[0051] The present invention uses a queue to be sent and a special sending thread or process. When a message is to be sent, the message only needs to be added to the queue to be sent, and the sending thread or process is responsible for sending it without adding a sender, thereby realizing automatic sending; through a queue to be replied, a timeout processing thread or process, and a message receiving thread or process, after the request message is sent, it is not necessary to block until the reply message arrives or times out, and the next message can be sent immediately, thereby realizing instant sending; after receiving a message, it is only necessary to add the message to the queue of messages to be processed, and it is not necessary to process the message, and it can return to receive the next message, and the reception of the new message will not be delayed due to the need to process the received message, thereby realizing instant reception; multiple processing linked lists are created, and efficient management and processing of messages are realized. The system will not block each other when sending, receiving and processing messages, thereby improving the efficiency of message processing and the response speed of the system.

[0052] It should be noted that the creation of a message processing method according to the message protocol type, a message sending failure processing method and a message timeout processing method can all be implemented through existing technologies and will not be described in detail in the present invention.

[0053] In this embodiment, in the process of monitoring whether the messages in the waiting-for-response queue have timed out, only the first message at the head of the waiting-for-response queue is checked each time to see whether it has timed out. If it has timed out, the corresponding method is retrieved from the message timeout processing method linked list and processed; if it has not timed out, it returns immediately.

[0054] The present invention improves the efficiency of timeout processing by only checking whether the first message at the head of the waiting-for-response queue has timed out, while ensuring that the timed-out message can be processed in time and reducing the resource consumption of timeout checking.

[0055] In this embodiment, the queue to be sent is used to store messages that need to be sent to the serial port, the queue to be replied is used to store request messages that have been successfully sent, and the queue to be processed is used to store request messages and reply messages received from the serial port.

[0056] Preferably, the queue to be sent is a first-in-first-out queue, the queue to be replied to is added from the tail, and can be retrieved and read at any position, and the queue to be processed is a first-in-first-out queue.

[0057] The present invention clarifies the functions and uses of each queue, and stores different types of messages through dedicated queues, making message management clearer and more efficient, facilitating rapid positioning and processing of messages, and improving the stability and reliability of the system.

[0058] In this embodiment, the message processing is performed according to the message type as follows:

[0059] For the request message, after processing according to the message protocol processing method, a response message is generated and added to the queue to be sent; preferably, the request message can be sent to the serial port to inquire about the information of the other end and configure the message to operate the other end; or received from the serial port to inquire about the information of the local end and configure the message to operate the local end.

[0060] For the reply message (the message that replies to the request message), the message protocol and message sequence number (indicating which message this message is sent out) are used to retrieve the corresponding request message from the queue to be replied. If the corresponding request message is found, it is processed according to the message protocol processing method. If the corresponding request message is not found, the reply message is discarded.

[0061] For example: the message type is a request message, and the message protocol type is query status A. The message protocol processing method is: obtain the status of status A, generate a reply message, and then add it to the queue to be sent; for example: the message type is a reply message, and the message protocol type is synchronize the peer time, then the reply message time will be set to the local time.

[0062] The present invention ensures that the messages can be correctly processed and responded to by processing the request message and the response message respectively, thereby improving the accuracy of message processing and the interactivity of the system.

[0063] In this embodiment, when the request message is added to the waiting-for-response queue, the time when the request message is sent is also added to the waiting-for-response queue.

[0064] The present invention makes timeout detection more accurate by recording the sending time of the request message in the waiting-for-response queue, which helps the system to more effectively manage the life cycle of the message and avoid data loss or error caused by timeout.

[0065] In this embodiment, the corresponding method is retrieved from the message sending failure processing method chain list, specifically, the retrieval is performed according to the message protocol type. Preferably, the message protocol type is classified according to the message function.

[0066] In this embodiment, the message sending thread or process, the message receiving thread or process, the message processing thread or process, and the timeout processing thread or process are all executed concurrently.

[0067] The present invention realizes the parallel operation of message sending, receiving, processing and timeout detection by concurrently executing multiple threads or processes, greatly improving the processing capacity and efficiency of the system and enabling the system to better cope with high load conditions.

[0068] In this embodiment, the processing methods in the message processing method linked list, the message sending failure processing method linked list, and the message timeout processing method linked list all support dynamic addition and deletion.

[0069] The present invention allows dynamic addition and deletion of processing methods, provides high flexibility and scalability, can adapt to changing needs and protocol types, and facilitates system maintenance and upgrading.

[0070] like Figure 2 As shown, the present invention also provides a serial port asynchronous full-duplex message automatic processing system, which includes: a queue management module 10, which is used to create a queue to be sent, a queue to be answered and a queue to be processed;

[0071] A linked list management module 20, used to create a message processing method, a message sending failure processing method and a message timeout processing method according to the message protocol type, and fill them into the corresponding message processing method linked list, message sending failure processing linked list and message timeout processing linked list respectively;

[0072] The message sending module 30 is used to add the request message to the tail of the queue to be sent when receiving the request message sent by the user; and to start a message sending thread or process to take out the message from the queue to be sent and send it to the serial port; if the sending is successful, the request message is added to the queue to be answered; if the sending fails, the corresponding method is retrieved from the message sending failure processing method chain list and processed;

[0073] The message receiving module 40 is used to start a message receiving thread or process, which is responsible for reading the received message from the serial port and adding it to the end of the queue to be processed, and then continues to receive the next message;

[0074] The message processing module 50 is used to start a message processing thread or process, which is responsible for reading messages from the head of the queue to be processed and processing the messages according to the message type;

[0075] The timeout processing module 60 is used to start a timeout processing thread or process, which is responsible for monitoring whether the message in the waiting reply queue has timed out.

[0076] The embodiment of the present invention further provides a computer-readable storage medium, which may be a computer-readable storage medium included in the memory in the above embodiment; or a computer-readable storage medium that exists independently and is not installed in a device. The computer-readable storage medium stores at least one instruction, which is loaded and executed by a processor to implement Figure 1 The computer readable storage medium may be a read-only memory, a disk or an optical disk, etc.

[0077] It should be noted that the various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments, and the same or similar parts between the various embodiments can be referred to each other. For the system embodiment and the storage medium embodiment, since they are basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0078] Furthermore, in this document, the terms "comprises," "comprising," or any other variation thereof are intended to encompass non-exclusive inclusion, such that a process, method, article, or device that includes a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or device. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of additional identical elements in the process, method, article, or device that includes the element.

[0079] The above description shows and describes the preferred embodiments of the present invention. It should be understood that the present invention is not limited to the form disclosed herein, and should not be regarded as excluding other embodiments, but can be used in various other combinations, modifications and environments, and can be modified within the scope of the invention, through the above teachings or the technology or knowledge of the relevant field. The changes and modifications made by those skilled in the art shall not depart from the spirit and scope of the present invention, and shall be within the scope of protection of the claims attached to the present invention.

Claims

1. A method for automatically processing serial port asynchronous full-duplex messages, characterized in that: The following steps are involved: Create queues to be sent, queues to be replied, and queues to be processed; Create a message processing method, a message sending failure processing method, and a message timeout processing method according to the message protocol type, and fill them into the corresponding message processing method linked list, message sending failure processing linked list, and message timeout processing linked list respectively; When receiving a request message sent by a user, the request message is added to the tail of the queue to be sent; Start a message sending thread or process, which is responsible for taking out the message from the waiting queue and sending it to the serial port; if the sending is successful, the request message is added to the waiting reply queue; if the sending fails, the corresponding method is retrieved from the message sending failure processing method list and processed; Start a message receiving thread or process, which is responsible for reading the received message from the serial port, adding it to the end of the queue to be processed, and then continuing to receive the next message; Start a message processing thread or process, which is responsible for reading messages from the queue header to be processed and processing the messages according to the message type; Start a timeout processing thread or process, which is responsible for monitoring whether the message in the waiting reply queue has timed out.

2. The method for automatically processing serial port asynchronous full-duplex messages according to claim 1, characterized in that: When monitoring whether the messages in the waiting-for-answer queue have timed out, only the first message at the head of the waiting-for-answer queue is checked each time to see if it has timed out. If so, the corresponding method is retrieved from the message timeout processing method list and processed; If it has not timed out, return immediately.

3. The method for automatically processing serial port asynchronous full-duplex messages according to claim 1, characterized in that: The queue to be sent is used to store messages that need to be sent to the serial port, the queue to be replied is used to store request messages that have been sent successfully, and the queue to be processed is used to store request messages and reply messages received from the serial port.

4. The method for automatically processing serial port asynchronous full-duplex messages according to claim 1, characterized in that: The specific message processing according to the message type is as follows: For the request message, after processing it according to the message protocol processing method, a response message is generated and added to the queue to be sent; For the reply message, the corresponding request message is retrieved from the waiting reply queue using the message protocol and message sequence number. If the corresponding request message is found, it is processed according to the message protocol processing method. If the corresponding request message is not found, the reply message is discarded.

5. The method for automatically processing serial port asynchronous full-duplex messages according to claim 1, characterized in that: When a request message is added to the waiting-for-answer queue, the time when the request message is sent is also added to the waiting-for-answer queue.

6. The method for automatically processing serial port asynchronous full-duplex messages according to claim 1, characterized in that: The corresponding method is retrieved from the message sending failure processing method chain list, specifically, the search is performed according to the message protocol type.

7. The method for automatically processing serial port asynchronous full-duplex messages according to claim 1, characterized in that: The message sending thread or process, the message receiving thread or process, the message processing thread or process and the timeout processing thread or process are all executed concurrently.

8. The method for automatically processing serial port asynchronous full-duplex messages according to claim 1, characterized in that: The processing methods in the message processing method chain list, the message sending failure processing method chain list and the message timeout processing method chain list all support dynamic addition and deletion.

9. A serial port asynchronous full-duplex message automatic processing system, characterized in that: include: The queue management module is used to create queues to be sent, queues to be answered and queues to be processed; A linked list management module, used to create a message processing method, a message sending failure processing method and a message timeout processing method according to the message protocol type, and fill them into the corresponding message processing method linked list, message sending failure processing linked list and message timeout processing linked list respectively; A message sending module is used to add the request message to the tail of the queue to be sent when receiving the request message sent by the user; and to start a message sending thread or process to take out the message from the queue to be sent and send it to the serial port; if the sending is successful, the request message is added to the queue to be replied; if the sending fails, the corresponding method is retrieved from the message sending failure processing method chain list and processed; The message receiving module is used to start a message receiving thread or process, which is responsible for reading the received message from the serial port, adding it to the end of the queue to be processed, and then continuing to receive the next message; The message processing module is used to start a message processing thread or process, which is responsible for reading messages from the head of the queue to be processed and processing the messages according to the message type; The timeout processing module is used to start a timeout processing thread or process, which is responsible for monitoring whether the message in the waiting reply queue has timed out.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a serial port asynchronous full-duplex message automatic processing program, and when the serial port asynchronous full-duplex message automatic processing program is executed by the processor, the steps of the serial port asynchronous full-duplex message automatic processing method as described in any one of claims 1 to 8 are implemented.

Citation Information

Patent Citations

  • Implementation method for sharing serial port resources by multiple processes based on messages

    CN111782417A

  • Serial communication method, computer readable storage medium and chip

    CN116594946A

  • Communication data processing method and device, electronic equipment and storage medium

    CN118193183A