Serial port communication method and system
By changing the software's initial handshake detection algorithm in serial communication and confirming the handshake connection using preset pulse signals, the problem of inefficient handshake in existing serial communication methods is solved, and fast and effective handshake establishment is achieved.
Patent Information
- Application Number
- CN202411387743.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-07
- Publication Date
- 2025-02-18
AI Technical Summary
The existing serial communication methods are inefficient in the handshake process, especially during long-distance communication, which requires adding IO signal lines and controlling IO points, which wastes resources, and the software inquiry handshake efficiency is low.
By changing the software's initial handshake detection algorithm, the main communicator configures the serial port sending pin to the IO output mode and sends a preset pulse signal to the communicator. When the communicator detects that the preset pulse signal meets the preset pulse signal, confirm the handshake connection.
It realizes the rapid and efficient establishment of handshake connections without the need for additional IO signal points or protocol polling, which improves handshake efficiency.
Smart Images

Figure CN119473973A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of communication technology, and in particular to a serial port communication method and system. Background Art
[0002] As one of the computer single-chip microcomputer communication methods, serial port communication mainly plays the role of data transmission between the host and peripherals and between the host. Serial port communication has the characteristics of fewer transmission lines and low cost. It is mainly suitable for short-distance human-computer exchange, real-time monitoring and other system communication work. With the help of the existing telephone network, long-distance transmission can also be achieved. Therefore, the serial port communication interface is a commonly used interface in computer single-chip microcomputer systems.
[0003] However, in the current communication method, if hardware handshake is used, it is necessary to add IO signal lines to identify the handshake, which requires additional control IO points and connecting lines, especially for long-distance communication, which wastes resources. If the handshake is inquired by software, various baud rates, various data bit stops, various check bits, etc. are tried to query whether there is a correct response, so the handshake efficiency is low. Summary of the invention
[0004] The present application provides a serial communication method and system. The method does not require additional IO signal points, nor does it require various protocol polling. It only requires changing the software initial handshake detection algorithm to quickly and effectively establish a handshake connection.
[0005] In view of this, the present application provides a serial port communication method, which includes: the main communication party configures the serial port sending pin to the IO output mode; the main communication party sends a preset pulse signal to the communicated party through the serial port sending pin; when the communicated party configures the serial port receiving pin to the IO input mode, the communicated party detects the pulse signal; if the pulse signal detected by the communicated party meets the preset pulse signal requirement, the communicated party confirms that the handshake meets the customized requirements.
[0006] In combination with the first aspect, in a possible implementation, after the communicated party confirms that the handshake meets the customized requirements, the method also includes: the communicated party configures the transmit and receive pins to a serial communication mode; the communicated party determines a matching communication protocol based on a preset pulse signal received from the main communication party.
[0007] In combination with the first aspect, in a possible implementation method, after the main communication party sends a preset pulse signal to the communicated party through the serial port sending pin, the method also includes: the main communication party configures the sending and receiving pins to the serial port communication mode and determines the matching communication protocol; if the main communication party receives a reply message from the communicated party after sending the first frame of data to the communicated party, the main communication party confirms that the handshake communication between the two parties is successfully established and conducts real-time communication.
[0008] In combination with the first aspect, in a possible implementation manner, the method further includes: the communicated party monitoring the time interval for receiving communication signals from the main communication party; and the main communication party monitoring the time interval for receiving communication signals from the communicated party.
[0009] In combination with the first aspect, in a possible implementation, the method further includes: when the time interval for the main communication party and / or the communicated party to monitor the communication signal exceeds a set threshold, it is determined that the connection is disconnected, and communication can only be carried out after re-handshaking.
[0010] The second aspect of the present application provides a serial port communication system, which includes: a main communication party and a communicated party, the main communication party is used to configure the serial port sending pin to the IO output mode; the main communication party is also used to send a preset pulse signal to the communicated party through the serial port sending pin; the communicated party is used to detect the pulse signal when the communicated party configures the serial port receiving pin to the IO input mode; the communicated party is also used to confirm that the handshake meets the customized requirements when the detected pulse signal meets the preset pulse signal requirement.
[0011] In combination with the second aspect, in a possible implementation, the communicated party is further used to configure the transmit and receive pins to a serial communication mode; the communicated party is further used to determine a matching communication protocol based on a preset pulse signal received from the main communication party.
[0012] In combination with the second aspect, in a possible implementation method, the main communication party is also used to configure the sending and receiving pins to the serial communication mode and determine the matching communication protocol; the main communication party is also used to confirm that the handshake communication between the two parties is successfully established and conduct real-time communication if the main communication party receives a reply message from the communicated party after sending the first frame of data to the communicated party.
[0013] In combination with the second aspect, in a possible implementation, the communicated party is further used to monitor the time interval for receiving communication signals from the main communication party; the main communication party is further used to monitor the time interval for receiving communication signals from the communicated party.
[0014] In combination with the second aspect, in a possible implementation, the main communication party and / or the communicated party is further configured to monitor the communication signal and, when the time interval exceeds a set threshold, determine that the connection is disconnected and that communication can only be performed after a re-handshake.
[0015] The present application provides a serial communication method and system, the method comprising: the main communication party configures the serial port sending pin to the IO output mode; the main communication party sends a preset pulse signal to the communicated party through the serial port sending pin; when the communicated party configures the serial port receiving pin to the IO input mode, the communicated party detects the pulse signal; if the pulse signal detected by the communicated party meets the preset pulse signal requirement, the communicated party confirms that the handshake meets the customized requirements. This method does not require additional IO signal points, nor does it require various protocol polling. It only needs to change the software initial handshake detection algorithm to quickly and effectively establish a handshake connection. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] Figure 1 A flowchart of a serial communication method provided in an embodiment of the present application; Figure 2 A pulse signal schematic diagram provided in an embodiment of the present application; Figure 3 A schematic diagram of a serial communication system provided in an embodiment of the present application. DETAILED DESCRIPTION
[0017] 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 those skilled in the art without creative work are within the scope of protection of this application.
[0018] The term "and / or" in this application can be a description of the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this application generally indicates that the associated objects before and after are in an "or" relationship.
[0019] The terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or modules is not necessarily limited to those steps or modules that are clearly listed, but may include other steps or modules that are not clearly listed or inherent to these processes, methods, products or devices.
[0020] As one of the computer single-chip microcomputer communication methods, serial port communication mainly plays the role of data transmission between the host and peripherals and between the host. Serial port communication has the characteristics of fewer transmission lines and low cost. It is mainly suitable for short-distance human-computer exchange, real-time monitoring and other system communication work. With the help of the existing telephone network, long-distance transmission can also be achieved. Therefore, the serial port communication interface is a commonly used interface in computer single-chip microcomputer systems.
[0021] However, in the current communication method, if hardware handshake is used, it is necessary to add IO signal lines to identify the handshake, which requires additional control IO points and connecting lines, especially for long-distance communication, which wastes resources. If the handshake is inquired by software, various baud rates, various data bit stops, various check bits, etc. are tried to query whether there is a correct response, so the handshake efficiency is low.
[0022] Therefore, this application provides a serial communication method, see Figure 1 , the serial communication method provided by this application includes: S11, the master communication party configures the serial port sending pin to IO output mode.
[0023] The master communication party configures the serial port sending pin to IO output mode. It should be noted that the master communication party can be a dedicated peripheral, such as an external display panel and other peripherals. The IO output mode is input / output, input / output mode. The master communication party can configure the serial port sending pin to IO output mode through a command pre-stored in a register.
[0024] S12, the main communication party sends a preset pulse signal to the communicated party through the serial port sending pin.
[0025] The master party sends a preset pulse signal to the communicated party through the serial port sending pin. Figure 2 The preset pulse signal may be pre-set. For example, three pulse frames may be sent, the first frame being low frequency, the second frame being high frequency, and the third frame being low frequency, and each pulse frame lasting 300 milliseconds. Figure 2 The fourth frame pulse is the end frame.
[0026] It should be noted that the three-frame pulse is only an example. In actual operation, it can also be a pulse signal of more than 3 frames. The duration of each frame can be preset and is not limited here. The main communication party can pre-configure the correspondence between the preset pulse signal and the preset communication protocol. For example, according to the above, 3 frames of pulses are sent, the first frame is low frequency, the second frame is high frequency, and the third frame is low frequency. Each frame of pulse lasts for 100 milliseconds, corresponding to the first communication protocol; 4 frames of pulses are sent, the first frame is low frequency, the second frame is high frequency, the third frame is low frequency, and the fourth frame is high frequency. Each frame of pulse lasts for 150 milliseconds, corresponding to the second communication protocol... Each set pulse signal corresponds to a uniquely determined communication protocol. The communicated party also sets the same correspondence.
[0027] S13. When the communicated party configures the serial port receiving pin to be in IO input mode, the communicated party detects a pulse signal.
[0028] When the communicated party configures the serial port receiving pin to IO input mode, the communicated party detects the pulse signal, which is the pulse signal detected from the master communication party.
[0029] The communicated party is a universal port, such as a motherboard, which can adapt to multiple communication protocols. Like the master communication party, the communicated party can also configure the serial port receiving pin to IO input mode through the command pre-stored in the register.
[0030] S14. If the pulse signal detected by the communicating party meets the preset pulse signal requirement, the communicating party confirms that the handshake meets the customized requirement.
[0031] If the pulse signal detected by the communicating party meets the preset pulse signal requirement, the communicating party confirms that the handshake meets the customized requirement.
[0032] The communicated party can compare the detected pulse signal with the preset pulse signal, and if a match is determined, the communicated party can determine that the handshake meets the customized requirements. The matching communication protocol can be determined based on the preset pulse signal.
[0033] It should be noted that after the communicated party confirms that the handshake meets the customized requirements, the method further includes: the communicated party configures the transceiver pins to a serial communication mode; the communicated party determines a matching communication protocol according to a preset pulse signal received from the master communication party. The serial communication mode is a pre-configured mode and can be configured according to the command stored in the register.
[0034] It should be noted that after the main communication party sends a preset pulse signal to the communicated party through the serial port sending pin, the method also includes: the main communication party configures the sending and receiving pins to the serial port communication mode and determines the matching communication protocol; if the main communication party receives a reply message from the communicated party after sending the first frame of data to the communicated party, the main communication party confirms that the handshake communication between the two parties is successfully established and conducts real-time communication.
[0035] It is understandable that after establishing communication, the method further includes: the communicated party monitoring the time interval for receiving communication signals from the main communication party; and the main communication party monitoring the time interval for receiving communication signals from the communicated party.
[0036] The method further includes: when the time interval of the communication signal monitored by the main communication party and / or the communicated party exceeds a set threshold, it is determined that the connection is disconnected, and communication can only be performed after re-handshaking. The set threshold can be set according to actual needs, such as 1000 milliseconds. Re-handshaking requires the main communication party to reconfigure the serial port sending pin to IO output mode, and the communicated party to reconfigure the serial port receiving pin to IO input mode.
[0037] The present application provides a serial communication method, which includes: the main communication party configures the serial port sending pin to the IO output mode; the main communication party sends a preset pulse signal to the communicated party through the serial port sending pin; when the communicated party configures the serial port receiving pin to the IO input mode, the communicated party detects the pulse signal; if the pulse signal detected by the communicated party meets the preset pulse signal requirement, the communicated party confirms that the handshake meets the customized requirements. This method does not require additional IO signal points, nor does it require various protocol polling. It only needs to change the software initial handshake detection algorithm to quickly and effectively establish a handshake connection.
[0038] In view of the above serial communication method, please refer to Figure 3 The present application also provides a serial port communication system, which includes: a main communication party and a communicated party, the main communication party is used to configure the serial port sending pin to the IO output mode; the main communication party is also used to send a preset pulse signal to the communicated party through the serial port sending pin; the communicated party is used to detect the pulse signal when the communicated party configures the serial port receiving pin to the IO input mode; the communicated party is also used to confirm that the handshake meets the customized requirements when the detected pulse signal meets the preset pulse signal requirement.
[0039] The communicated party is further used to configure the transceiver pins to a serial communication mode; the communicated party is further used to determine a matching communication protocol according to a preset pulse signal received from the main communication party.
[0040] The main communication party is also used to configure the sending and receiving pins to the serial communication mode and determine the matching communication protocol; the main communication party is also used to confirm that the handshake communication between the two parties is successfully established and conduct real-time communication if the main communication party receives a reply message from the communicated party after sending the first frame of data to the communicated party.
[0041] The communicated party is further used to monitor the time interval for receiving communication signals from the main communication party; the main communication party is further used to monitor the time interval for receiving communication signals from the communicated party.
[0042] The main communication party and / or the communicated party are further configured to monitor the communication signal and, when the time interval exceeds a set threshold, determine that the connection is disconnected, and perform communication only after re-handshaking.
[0043] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0044] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions to enable a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk, etc., various media that can store program codes.
[0045] In the embodiments provided in this application, it should be understood that the disclosed methods can be implemented in other ways without exceeding the spirit and scope of this application. The current embodiment is only an illustrative example and should not be used as a limitation. The specific content given should not limit the purpose of this application. For example, some features can be ignored or not executed.
[0046] The technical means disclosed in the present application are not limited to the technical means disclosed in the above-mentioned implementation methods, but also include technical solutions composed of any combination of the above technical features. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of this application, and these improvements and modifications are also regarded as the protection scope of this application.
[0047] The above is a detailed introduction to a serial communication method and system provided by the embodiments of the present application. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method and its core idea of the present application; at the same time, for those of ordinary skill in the art, according to the idea of the present application, there will be changes in the specific implementation methods and application scopes. In summary, the content of this specification should not be understood as a limitation on the present application. Although the present application is described in detail with reference to the aforementioned embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions recorded in the aforementioned embodiments, or replace some of the technical features therein by equivalents; and these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application.
Claims
1. A serial communication method, characterized in that: The method comprises: The master communication party configures the serial port sending pin to IO output mode; The master communication party sends a preset pulse signal to the communicated party through the serial port sending pin; When the communicated party configures the serial port receiving pin to be in IO input mode, the communicated party detects a pulse signal; If the pulse signal detected by the communicated party meets the preset pulse signal requirement, the communicated party confirms that the handshake meets the customized requirement.
2. The serial communication method according to claim 1, characterized in that: After the communicated party confirms that the handshake meets the customized requirements, the method further includes: The communicating party configures the transceiver pins to a serial communication mode; The communicated party determines a matching communication protocol according to a preset pulse signal received from the communicating party.
3. The serial communication method according to claim 1, characterized in that: After the main communication party sends a preset pulse signal to the communicated party through the serial port sending pin, the method further includes: The master communication party configures the transceiver pins to a serial communication mode and determines a matching communication protocol; If the main communication party receives a reply message from the communicated party after sending the first frame of data to the communicated party, the main communication party confirms that the handshake communication between the two parties is successfully established and performs real-time communication.
4. The serial communication method according to any one of claims 1 to 3, characterized in that: The method further comprises: The communicated party monitors the time interval for receiving the communication signal from the communicating party; The communicating party monitors a time interval for receiving a communication signal from the communicating party.
5. The serial communication method according to claim 4, characterized in that: The method further comprises: When the time interval for the main communication party and / or the communicated party to monitor the communication signal exceeds a set threshold, it is determined that the connection is disconnected and communication can only be performed after re-handshaking.
6. A serial communication system, characterized in that: The system comprises: a main communication party and a communicated party, The master communication party is used to configure the serial port sending pin to IO output mode; The master communication party is also used to send a preset pulse signal to the communicated party through a serial port sending pin; The communicated party is configured to detect a pulse signal when the communicated party configures a serial port receiving pin to an IO input mode; The communicated party is further configured to confirm that the handshake meets the customized requirement when the detected pulse signal meets the preset pulse signal requirement.
7. The serial communication system according to claim 6, characterized in that: The communicated party is also used to configure the transceiver pins to a serial communication mode; The communicated party is further configured to determine a matching communication protocol according to a preset pulse signal received from the main communicating party.
8. The serial communication system according to claim 6, characterized in that: The main communication party is also used to configure the transceiver pins to the serial communication mode and determine the matching communication protocol; The main communication party is also used to confirm that the handshake communication between the two parties is successfully established and perform real-time communication if the main communication party receives a reply message from the communicated party after sending the first frame of data to the communicated party.
9. The serial communication system according to any one of claims 6 to 8, characterized in that: The communicated party is further configured to monitor a time interval for receiving a communication signal from the communicating party; The main communication party is further used to monitor the time interval for receiving the communication signal from the communicated party.
10. The serial communication system according to claim 9, characterized in that: The main communication party and / or the communicated party are further configured to monitor the communication signal and, when the time interval exceeds a set threshold, determine that the connection is disconnected, and perform communication only after re-handshaking.