Serial port multiplexing communication method and device, air conditioner and computer readable storage medium
By cross-sending data packets and utilizing sending time and duration to achieve serial port multiplexing of the air conditioner controller, the problem of the limited number of serial ports of the air conditioner controller is solved, the communication efficiency with multiple intelligent functional modules is improved, and faults can be detected in a timely manner.
Patent Information
- Application Number
- CN202410390775.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-04-01
- Publication Date
- 2025-11-21
- Estimated Expiration
- 2044-04-01
AI Technical Summary
The number of serial ports on the air conditioner controller is limited, making it impossible to communicate with multiple intelligent functional modules simultaneously.
The serial port of the host is multiplexed by interleaving multiple first data packets and second data packets, utilizing the sending time and duration of the data packets. The specific steps include acquiring data packets and sending duration, monitoring response packets and updating error count values to detect communication failures.
The serial port multiplexing of the air conditioner controller and multiple intelligent functional modules has been realized, which improves communication efficiency and enables timely detection and handling of communication faults.
Smart Images

Figure CN118208805B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of communication, in particular to a serial port multiplexing communication method and device, an air conditioner and a computer readable storage medium. BACKGROUND
[0002] With the wide use of air conditioners, the functions of air conditioners are becoming more and more, and the communication between the air conditioner controller and various intelligent function modules will be involved in the use of air conditioners, for example, the communication between the air conditioner controller and the wifi module, host computer and the like of the air conditioner. However, the number of serial ports of the air conditioner controller is limited, which causes the air conditioner controller to be unable to communicate with multiple intelligent function modules at the same time. SUMMARY
[0003] The serial port multiplexing communication method and device, the air conditioner and the computer readable storage medium provided by the embodiments of the present application can cross send multiple first data packets and multiple second data packets to the first slave and the second slave, and realize the serial port multiplexing of the host.
[0004] The technical solutions adopted by the present application to solve the problems are as follows:
[0005] In one aspect, the present application provides a serial port multiplexing communication method applied to a host, the host being in communication connection with a first slave and a second slave, and the serial port multiplexing communication method comprising:
[0006] obtaining multiple first data packets, multiple second data packets, a first sending duration and a second sending duration;
[0007] sending an Mth first data packet in the multiple first data packets to the first slave, and sending an Mth second data packet in the multiple second data packets to the second slave based on the sending time of the Mth first data packet and the first sending duration; wherein M is an integer and 0
[0008] based on the sending time of the Mth second data packet and the second sending duration, sending an M+1th first data packet in the multiple first data packets to the first slave, to realize the serial port multiplexing of the host.
[0009] In some embodiments of the present application, sending the Mth second data packet in the multiple second data packets to the second slave based on the sending time of the Mth first data packet and the first sending duration comprises:
[0010] determining a third sending duration of the Mth first data packet based on the sending time of the Mth first data packet and the current time;
[0011] comparing the third sending duration with the first sending duration;
[0012] If the third sending duration reaches the first sending duration, the Mth second data packet in the plurality of second data packets is sent to the second slave.
[0013] In some embodiments of the present application, after the Mth first data packet in the plurality of first data packets is sent to the first slave, the method further comprises:
[0014] monitoring whether a first response packet returned by the first slave based on the Mth first data packet is received before the third sending duration reaches the first sending duration;
[0015] if the first response packet is not received, updating the first error count value based on a preset first value;
[0016] if the first response packet is received, updating the first error count value to a preset second value.
[0017] In some embodiments of the present application, after the first error count value is updated based on the preset first value, the method comprises:
[0018] comparing the updated first error count value with a preset first count threshold value;
[0019] if the updated first error count value reaches the first count threshold value, outputting first failure information; the first failure information indicates that a communication failure occurs between the host and the first slave.
[0020] In some embodiments of the present application, the M+1th first data packet in the plurality of first data packets is sent to the first slave based on the sending time of the Mth second data packet and the second sending duration, comprising:
[0021] determining a fourth sending duration of the Mth second data packet based on the sending time of the Mth second data packet and a current time;
[0022] comparing the fourth sending duration with the second sending duration;
[0023] if the fourth sending duration reaches the second sending duration, the M+1th first data packet in the plurality of first data packets is sent to the first slave.
[0024] In some embodiments of the present application, after the Mth second data packet in the plurality of second data packets is sent to the second slave based on the sending time of the Mth first data packet and the first sending duration, the method further comprises:
[0025] monitoring whether a second response packet returned by the second slave based on the Mth second data packet is received before the fourth sending duration reaches the second sending duration;
[0026] if the second response packet is not received, updating a second error count value based on a preset third value;
[0027] If the second response packet is received, the second error count value is updated to a preset fourth value.
[0028] In some embodiments of the present application, after the second error count value is updated based on the preset third value, the following is included:
[0029] The updated second error count value is compared with a preset second count threshold value.
[0030] If the updated second error count value reaches the second count threshold value, second failure information is outputted; the second failure information represents that the host and the second slave machine have a communication failure.
[0031] In some embodiments of the present application, the first sending duration is obtained based on the following steps, including:
[0032] First communication protocol information of the host and the first slave machine is obtained.
[0033] The first data packet length is determined based on the first communication protocol information.
[0034] A preset fifth sending duration and a preset sixth sending duration are obtained, and the first sending duration is determined based on the first data packet length, the fifth sending duration and the sixth sending duration.
[0035] In a second aspect, the embodiments of the present application further provide a serial port multiplexing communication device applied to a host, the host being in communication connection with a first slave machine and a second slave machine, and the serial port multiplexing communication device including:
[0036] An information obtaining module, configured to obtain a plurality of first data packets, a plurality of second data packets, a first sending duration and a second sending duration.
[0037] A first sending module, configured to send an Mth first data packet in the plurality of first data packets to the first slave machine, and send an Mth second data packet in the plurality of second data packets to the second slave machine based on a sending time of the Mth first data packet and the first sending duration; wherein M is an integer and 0 < M ≤ N-1, and N is a quantity of the plurality of first data packets.
[0038] A second sending module, configured to send an M+1th first data packet in the plurality of first data packets to the first slave machine based on a sending time of the Mth second data packet and the second sending duration, so as to realize serial port multiplexing of the host.
[0039] In a third aspect, the present application further provides an air conditioner, including:
[0040] One or more processors;
[0041] A memory; and
[0042] One or more application programs, wherein the one or more application programs are stored in the memory and configured to be executed by the processor to implement the serial port multiplexing communication method of any one of the first aspect.
[0043] In a fourth aspect, the embodiments of the present application provide a computer readable storage medium, which stores a computer program, and the computer program is loaded by a processor to execute the steps in the serial port multiplexing communication method of any one of the first aspect.
[0044] The application has the beneficial effect that: by sending the Mth first data packet in the plurality of first data packets to the first slave, and sending the Mth second data packet in the plurality of second data packets to the second slave based on the sending time of the Mth first data packet and the first sending duration, and sending the M+1th first data packet in the plurality of first data packets to the first slave based on the sending time of the Mth second data packet and the second sending duration, the plurality of first data packets and the plurality of second data packets can be sent to the first slave and the second slave alternately, and the serial port multiplexing of the host is realized. BRIEF DESCRIPTION OF DRAWINGS
[0045] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the drawings needed to be used in the embodiments or prior art description will be briefly introduced below. Obviously, the drawings in the following description are only some embodiments described in the present application, and other drawings can also be obtained by those skilled in the art without creative effort on the basis of these drawings.
[0046] Figure 1 is a scene schematic diagram of the serial port multiplexing communication system provided by the embodiments of the present application;
[0047] Figure 2 is a flow schematic diagram of the serial port multiplexing communication method provided by the embodiments of the present application;
[0048] Figure 3 is a specific flow schematic diagram of the serial port multiplexing communication method provided by the embodiments of the present application;
[0049] Figure 4 is a specific flow schematic diagram of sending the Mth second data packet provided by the embodiments of the present application;
[0050] Figure 5 is a specific flow schematic diagram of sending the M+1th first data packet provided by the embodiments of the present application;
[0051] Figure 6 is a principle block diagram of the serial port multiplexing communication device provided by the embodiments of the present application;
[0052] Figure 7 is a structure schematic diagram of one embodiment of the air conditioner provided by the embodiments of the present application. Detailed Implementation
[0053] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0054] In the description of this application, it should be understood that the terms "center," "longitudinal," "lateral," "length," "width," "thickness," "upper," "lower," "front," "rear," "left," "right," "vertical," "horizontal," "top," "bottom," "inner," and "outer," etc., indicating orientation or positional relationships based on the orientation or positional relationships shown in the accompanying drawings, are used only for the convenience of describing this application and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation, and therefore should not be construed as a limitation of this application. Furthermore, the terms "first," "second," and "third," etc., are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of indicated technical features. Thus, features defined with "first," "second," "third," etc., may explicitly or implicitly include one or more of the stated features. In the description of this application, "a plurality of" means two or more, unless otherwise explicitly specified.
[0055] In this application, the term "exemplary" is used to mean "used as an example, illustration, or description." Any embodiment described as "exemplary" in this application is not necessarily to be construed as being more preferred or advantageous than other embodiments. The following description is provided to enable any person skilled in the art to make and use this application. Details are set forth in the following description for purposes of explanation. It should be understood that those skilled in the art will recognize that this application can be made without using these specific details. In other instances, well-known structures and processes are not described in detail to avoid obscuring the description of this application with unnecessary detail. Therefore, this application is not intended to be limited to the embodiments shown, but is consistent with the broadest scope of the principles and features disclosed in this application.
[0056] This application provides a serial port multiplexing communication method, apparatus, air conditioner, and computer-readable storage medium, which will be described in detail below.
[0057] Please see Figure 1 , Figure 1A scene schematic diagram of a serial port multiplexing communication system provided by the embodiment of the application, the serial port multiplexing communication system can include a host computer, and a first slave computer and a second slave computer in communication connection with the host computer, and the host computer is integrated with a serial port multiplexing communication device.
[0058] The host computer in the embodiment of the application is mainly used for obtaining a plurality of first data packets, a plurality of second data packets, a first sending duration and a second sending duration; sending an Mth first data packet in the plurality of first data packets to the first slave computer, and sending an Mth second data packet in the plurality of second data packets to the second slave computer based on a sending time of the Mth first data packet and the first sending duration; wherein M is an integer and 0
[0059] The host computer used in the embodiment of the application can be a device including receiving and transmitting hardware, i.e., a device having receiving and transmitting hardware capable of performing bidirectional communication on a bidirectional communication link. Such a device can include a cellular or other communication device having a single-line display or a multi-line display or a cellular or other communication device without a multi-line display.
[0060] In a specific embodiment, the serial port multiplexing communication method provided by the embodiment of the application is applied to an air conditioner, the host computer is an air conditioner controller MCU, and the first slave computer and the second slave computer are intelligent function modules related to communication on the air conditioner, for example, the first slave computer can be a wifi module of the air conditioner, and the second slave computer can be a host computer of the air conditioner.
[0061] Those skilled in the art can understand that Figure 1 The application environment shown in the embodiment of the application is only one application scenario of the application scheme, and does not constitute a limitation on the application scenario of the application scheme. For example Figure 1 Only one host computer and two slave computers are shown in the embodiment of the application, and it can be understood that the serial port multiplexing communication system can also include one host computer and more slave computers, and the specific number of slave computers is not limited herein.
[0062] In addition, the serial port multiplexing communication system can also include a memory for storing data, such as duration data, for example, a first sending duration, a second sending duration, etc., and data packets, for example, a first data packet, a second data packet, etc.
[0063] It should be noted that Figure 1The scenario schematic diagram of the serial port multiplexing communication system shown is merely an example, and the serial port multiplexing communication system and scenario described in the embodiments of the present application are used to more clearly illustrate the technical solutions of the embodiments of the present application, and do not constitute a limitation on the technical solutions provided by the embodiments of the present application. It can be known by those skilled in the art that, as the serial port multiplexing communication system evolves and new service scenarios appear, the technical solutions provided by the embodiments of the present application are also applicable to similar technical problems.
[0064] First, a serial port multiplexing communication method is provided in the embodiments of the present application. The execution subject of the serial port multiplexing communication method is a serial port multiplexing communication device. The serial port multiplexing communication device is applied to an air conditioner. The serial port multiplexing communication method comprises the following steps: obtaining a plurality of first data packets, a plurality of second data packets, a first sending time length, and a second sending time length; sending an Mth first data packet in the plurality of first data packets to a first slave machine, and sending an Mth second data packet in the plurality of second data packets to a second slave machine based on a sending time of the Mth first data packet and the first sending time length; wherein M is an integer and 0 < M ≤ N-1, and N is the number of the plurality of first data packets; and sending an M+1th first data packet in the plurality of first data packets to the first slave machine based on a sending time of the Mth second data packet and the second sending time length, to realize serial port multiplexing of a host.
[0065] As shown in the embodiments of the serial port multiplexing communication method of the present application, the serial port multiplexing communication method can comprise the following steps S201-S203, which are specifically as follows: Figure 2
[0066] Step S201: obtaining a plurality of first data packets, a plurality of second data packets, a first sending time length, and a second sending time length.
[0067] The plurality of first data packets are data packets that the host needs to send to the first slave machine. For example, if the plurality of first data packets comprise N data packets, the plurality of first data packets comprise a first first data packet, a second first data packet, …, and an Nth first data packet. The plurality of second data packets are data packets that the host needs to send to the second slave machine. The number of the plurality of second data packets can be the same as or different from the number of the plurality of first data packets. For example, if the plurality of second data packets also comprise N data packets, the plurality of second data packets comprise a first second data packet, a second second data packet, …, and an Nth second data packet.
[0068] Considering that the number of serial ports of the host (such as an air conditioner controller) is limited, in order to realize communication between the host and a plurality of slave machines at the same time, the first sending time length and the second sending time length are pre-set in the embodiments. The first sending time length refers to the time length from the start of sending a first data packet to the start of sending a next data packet. The second sending time length refers to the time length from the start of sending a second data packet to the start of sending a next data packet. For example, refer to FIG. 2.Figure 3 As shown, the first sending duration refers to a duration from starting to send the first data packet AT1 to starting to send the second data packet BT1 (i.e. Figure 3 the middle timing T), and the second sending duration refers to a duration from starting to send the second data packet BT1 to starting to send the first data packet AT2.
[0069] In an embodiment, the first sending duration is obtained based on the following steps, including:
[0070] (1) obtaining first communication protocol information of the host and the first slave.
[0071] The first communication protocol information refers to regulations and agreements that must be followed by the host and the first slave to complete communication or service. For example, the host is an air conditioner controller, the first slave is a wifi module of the air conditioner, and the first communication protocol information is regulations and agreements that must be followed by the air conditioner controller and the wifi module of the air conditioner to complete communication or service.
[0072] (2) determining a first data packet length based on the first communication protocol information.
[0073] The first data packet length is the length of the data packet transmitted between the host and the first slave. The communication protocols of the host and the first slave are different, and the first data packet length is also different. For example, the host and the first slave communicate through the UDP protocol, and the first data packet length is 65535 Bytes. The host and the first slave communicate through the TCP protocol, and the first data packet length is 1460 Bytes.
[0074] (3) obtaining a preset fifth sending duration and a preset sixth sending duration, and determining the first sending duration based on the first data packet length, the fifth sending duration and the sixth sending duration.
[0075] The fifth sending duration and the sixth sending duration are preset duration values. The fifth sending duration and the sixth sending duration can be set according to actual needs. For example, the fifth sending duration is set to t1 = 50 ms, and the sixth sending duration t2 ≥ 50 ms.
[0076] Specifically, the step of determining the first sending duration based on the first data packet length, the fifth sending duration and the sixth sending duration can specifically include: determining a seventh sending duration based on the first data packet length; and summing the fifth sending duration, the sixth sending duration and the seventh sending duration to obtain the first sending duration. The calculation process of the first sending duration can be represented as: T1 = t1 + t2 + t3, where T1 represents the first sending duration, t1 represents the fifth sending duration, t2 represents the sixth sending duration, and t3 represents the seventh sending duration.
[0077] In an embodiment, the second sending duration is obtained based on the following steps, including:
[0078] (1) Obtain second communication protocol information of the host and the second slave.
[0079] The second communication protocol information refers to the regulations and agreements that must be followed by the host and the second slave to complete communication or service. For example, the host is an air conditioner controller, the second slave is the host of the air conditioner, and the second communication protocol information is the regulations and agreements that must be followed by the air conditioner controller and the host of the air conditioner to complete communication or service.
[0080] (2) Determine the second data packet length based on the second communication protocol information.
[0081] The second data packet length is the length of the data packet transmitted between the host and the second slave. The communication protocols of the host and the second slave are different, and the second data packet length is also different. For example, the host and the second slave communicate through the UDP protocol, and the second data packet length is 65535 Bytes. The host and the second slave communicate through the TCP protocol, and the second data packet length is 1460 Bytes.
[0082] (3) Obtain a preset eighth transmission duration and a ninth transmission duration, and determine a second transmission duration based on the second data packet length, the eighth transmission duration, and the ninth transmission duration.
[0083] The eighth transmission duration and the ninth transmission duration are pre-set duration values. The eighth transmission duration and the ninth transmission duration can be set according to actual needs. For example, the eighth transmission duration is set to t4 = 50 ms, and the ninth transmission duration t5 ≥ 50 ms.
[0084] Specifically, the step of determining the second transmission duration based on the second data packet length, the eighth transmission duration, and the ninth transmission duration can include: determining a tenth transmission duration based on the second data packet length; and summing the eighth transmission duration, the ninth transmission duration, and the tenth transmission duration to obtain the second transmission duration. The calculation process of the second transmission duration can be represented as: T2 = t4 + t5 + t6, where T2 represents the second transmission duration, t4 represents the eighth transmission duration, t5 represents the ninth transmission duration, and t6 represents the tenth transmission duration.
[0085] In step S202, the Mth first data packet in the plurality of first data packets is sent to the first slave, and the Mth second data packet in the plurality of second data packets is sent to the second slave based on the transmission time of the Mth first data packet and the first transmission duration. M is an integer and 0 < M ≤ N-1, and N is the number of the plurality of first data packets.
[0086] In a specific embodiment, the number of the first data packets is N, and the Mth first data packet can be any one of the 1st first data packet, the 2nd first data packet,..., and the (N-1)th first data packet. The number of the second data packets is N, and the Mth second data packet can be any one of the 1st second data packet, the 2nd second data packet,..., and the (N-1)th second data packet.
[0087] The sending time of the Mth first data packet refers to the starting sending time of the Mth first data packet. For example, continuing to refer to FIG. 1, the Mth first data packet is the first data packet AT1, and the Mth second data packet is the second data packet BT1. The first data packet AT1 is sent to the first slave machine, and the second data packet BT1 is sent to the second slave machine based on the sending time of the first data packet AT1 and the first sending duration. For another example, the Mth first data packet is the first data packet AT2, and the Mth second data packet is the second data packet BT2. The first data packet AT2 is sent to the first slave machine, and the second data packet BT2 is sent to the second slave machine based on the sending time of the first data packet AT2 and the first sending duration. In this way, the cross sending of the first data packet ATi and the second data packet BTi can be implemented, and the serial port multiplexing of the host machine can be further implemented. Figure 3 In a specific implementation, referring to FIG. 2, the step of sending the Mth second data packet of the second data packets to the second slave machine based on the sending time of the Mth first data packet and the first sending duration in the step S202 can include the following steps S301-S303, which are specifically as follows.
[0088] Figure 4 The step S301 includes determining the third sending duration of the Mth first data packet based on the sending time of the Mth first data packet and the current time.
[0089] The step S301 includes determining the third sending duration of the Mth first data packet based on the sending time of the Mth first data packet and the current time.
[0090] The third sending duration refers to the duration between the starting sending time of the Mth first data packet and the current time. It is mentioned above that the sending time of the Mth first data packet refers to the starting sending time of the Mth first data packet. Therefore, the third sending duration of the Mth first data packet can be determined based on the sending time of the Mth first data packet and the current time.
[0091] The step S302 includes comparing the third sending duration with the first sending duration.
[0092] The step S303 includes sending the Mth second data packet of the second data packets to the second slave machine if the third sending duration reaches the first sending duration.
[0093] The third sending duration is compared with the first sending duration. If the third sending duration reaches the first sending duration, it is determined that the Mth second data packet can be sent, and the Mth second data packet in the plurality of second data packets is sent to the second slave machine. Otherwise, if the third sending duration has not reached the first sending duration, the step of determining the third sending duration of the Mth first data packet based on the sending time of the Mth first data packet and the current time is continuously executed until the third sending duration reaches the first sending duration.
[0094] In a specific implementation, after the step of sending the Mth first data packet in the plurality of first data packets to the first slave machine in the step S202, the following steps can be included:
[0095] (1) Monitoring whether the first response packet returned by the first slave machine based on the Mth first data packet is received before the third sending duration reaches the first sending duration.
[0096] If there is no communication failure between the host and the first slave machine, after the first slave machine receives the Mth first data packet sent by the host, the first slave machine returns a first response packet to the host based on the Mth first data packet. In order to determine whether a communication failure occurs between the host and the first slave machine, after the host sends the Mth first data packet in the plurality of first data packets to the first slave machine, whether the first response packet returned by the first slave machine based on the Mth first data packet is received before the third sending duration reaches the first sending duration is monitored.
[0097] (2) If the first response packet is not received, updating the first error count value based on a preset first value.
[0098] The first error count value is used to represent the number of times that the host continuously fails to receive the response packet of the first slave machine. Based on the first error count value, whether a communication failure occurs between the host and the first slave machine can be determined. The first value is a value preset for updating the first error count value. The first value can be set according to actual needs. For example, the first value can be set to 1.
[0099] In a specific embodiment, the step of updating the first error count value based on the preset first value specifically includes: increasing the first error count value by the first value. For example, the first value is set to 1. If the first response packet is not received, the first error count value is increased by 1.
[0100] In a specific embodiment, after the step of updating the first error count value based on the preset first value, the following steps are included: comparing the updated first error count value with a preset first count threshold value; and outputting first failure information if the updated first error count value reaches the first count threshold value.
[0101] The first counting threshold is a pre-set counting threshold used to measure whether a communication failure has occurred between the host and the first slave. The first counting threshold can be set according to actual needs. For example, if the first counting threshold is set to 50, and the first error count value reaches 50, that is, the host has not received a response packet from the first slave 50 times in a row, then it is determined that a communication failure has occurred between the host and the first slave.
[0102] The first fault information indicates that a communication failure has occurred between the host and the first slave device. The first fault information includes, but is not limited to, being output in one or more ways such as graphics, text, voice, and color. For example, outputting a voice prompt that "a communication failure has occurred between the host and the first slave device".
[0103] (3) If the first response packet is received, the first error count value is updated to the preset second value.
[0104] The second value is a pre-set value used to update the first error count value. The second value can be set as needed. For example, the first value can be set to 0. If the first response packet returned by the first slave based on the Mth first data packet is received before the third transmission duration reaches the first transmission duration, the first error count value will be updated to 0 so as to continue to monitor the number of times the master has not received a response packet from the first slave.
[0105] Step S203: Based on the sending time and the second sending duration of the Mth second data packet, send the (M+1)th first data packet from the multiple first data packets to the first slave device to realize serial port multiplexing of the master device.
[0106] In one specific embodiment, the number of multiple first data packets is N, and the (M+1)th first data packet can be any one of the second, third, ..., Nth first data packets. The transmission time of the Mth second data packet refers to the start transmission time of the Mth second data packet. For example, continuing to refer to... Figure 3 As shown, the Mth second data packet is the second data packet BT1, and the (M+1)th first data packet is the first data packet AT2. The second data packet BT1 is sent to the second slave device, and the first data packet AT2 is sent to the first slave device based on the sending time and the second sending duration of the second data packet BT1. Similarly, the Mth second data packet is the second data packet BT2, and the (M+1)th first data packet is the first data packet AT3. The second data packet BT2 is sent to the second slave device, and the first data packet AT3 is sent to the first slave device based on the sending time and the second sending duration of the second data packet BT2. In this way, the cross-transmission of the first data packet ATi and the second data packet BTi can be realized, thereby realizing the serial port multiplexing of the host.
[0107] In a specific implementation method, refer to Figure 5As shown, the step of sending the M+1th first data packet in the plurality of first data packets to the first slave based on the sending time of the Mth second data packet and the second sending duration in the step S203 can include the following steps S401-S403, which are as follows:
[0108] In the step S401, the fourth sending duration of the Mth second data packet is determined based on the sending time of the Mth second data packet and the current time.
[0109] The fourth sending duration refers to the duration between the starting sending time of the Mth second data packet and the current time. As mentioned above, the sending time of the Mth second data packet refers to the starting sending time of the Mth second data packet. Therefore, the fourth sending duration of the Mth second data packet can be determined based on the sending time of the Mth second data packet and the current time.
[0110] In the step S402, the fourth sending duration is compared with the second sending duration.
[0111] In the step S403, if the fourth sending duration reaches the second sending duration, the M+1th first data packet in the plurality of first data packets is sent to the first slave.
[0112] The fourth sending duration is compared with the second sending duration. If the fourth sending duration reaches the second sending duration, it is determined that the M+1th first data packet can be sent, and then the M+1th first data packet is sent to the first slave. Otherwise, if the fourth sending duration has not reached the second sending duration, the step of determining the fourth sending duration of the Mth second data packet based on the sending time of the Mth second data packet and the current time is continuously performed until the fourth sending duration reaches the second sending duration.
[0113] In a specific implementation, after the step of sending the Mth second data packet in the plurality of second data packets to the second slave based on the sending time of the Mth first data packet and the first sending duration in the step S202, the following steps can be included:
[0114] (1) Monitoring whether the second response packet returned by the second slave based on the Mth second data packet is received before the fourth sending duration reaches the second sending duration.
[0115] If there is no communication failure between the host and the second slave, the second slave will return a second response packet to the host based on the Mth second data packet after receiving the Mth second data packet sent by the host. In order to determine whether a communication failure occurs between the host and the second slave, the host will monitor whether the second response packet returned by the second slave based on the Mth second data packet is received before the fourth sending duration reaches the second sending duration after sending the Mth second data packet in the plurality of second data packets to the second slave.
[0116] (2) If the second response packet is not received, updating the second error count value based on a preset third value.
[0117] The second error count value is used to represent the number of times that the host continuously fails to receive the response packet from the second slave. Based on the second error count value, it can be determined whether there is a communication failure between the host and the second slave. The third value is a preset value used to update the second error count value. The third value can be set as needed, for example, the third value can be set to 1.
[0118] In an embodiment, the step of updating the second error count value based on the preset third value specifically includes: increasing the second error count value by the third value, for example, the third value is set to 1, and if the second response packet is not received, the third error count value is increased by 1.
[0119] In an embodiment, after the step of updating the second error count value based on the preset third value, the method further includes: comparing the updated second error count value with a preset second count threshold; and outputting second failure information if the updated second error count value reaches the second count threshold.
[0120] The second count threshold is a preset count threshold used to measure whether there is a communication failure between the host and the second slave. The second count threshold can be set according to actual needs, for example, the second count threshold is set to 50, and if the second error count value reaches 50, i.e., the host fails to receive the response packet from the second slave for 50 consecutive times, it is determined that there is a communication failure between the host and the second slave.
[0121] The second failure information represents that there is a communication failure between the host and the second slave. The second failure information includes but is not limited to being output in one or more of the following ways: graphics, text, voice, and color, for example, a voice prompt of "there is a communication failure between the host and the second slave" is output.
[0122] (3) If the second response packet is received, updating the second error count value to a preset fourth value.
[0123] The fourth value is a preset value used to update the second error count value. The fourth value can be set as needed, for example, the fourth value can be set to 0, and if the second response packet returned by the second slave based on the Mth second data packet is received before the fourth sending duration reaches the second sending duration, the first error count value is updated to 0, so as to continue to monitor the number of times that the host continuously fails to receive the response packet from the second slave.
[0124] In order to better implement the serial port multiplexing communication method in the embodiments of the present application, on the basis of the serial port multiplexing communication method, the embodiments of the present application further provide a serial port multiplexing communication device. The serial port multiplexing communication device is applied to a host computer, and the host computer is in communication connection with a first slave computer and a second slave computer, as shown in FIG. 7. The serial port multiplexing communication device 700 includes: Figure 6
[0125] An information acquisition module 710 is configured to acquire a plurality of first data packets, a plurality of second data packets, a first sending duration and a second sending duration.
[0126] A first sending module 720 is configured to send an Mth first data packet in the plurality of first data packets to the first slave computer, and send an Mth second data packet in the plurality of second data packets to the second slave computer based on a sending time of the Mth first data packet and the first sending duration, where M is an integer and 0 < M ≤ N-1, and N is the number of the plurality of first data packets.
[0127] A second sending module 730 is configured to send an M+1th first data packet in the plurality of first data packets to the first slave computer based on a sending time of the Mth second data packet and the second sending duration, so as to implement serial port multiplexing of the host computer.
[0128] In the embodiments of the present application, the Mth first data packet in the plurality of first data packets is sent to the first slave computer, the Mth second data packet in the plurality of second data packets is sent to the second slave computer based on the sending time of the Mth first data packet and the first sending duration, and the M+1th first data packet in the plurality of first data packets is sent to the first slave computer based on the sending time of the Mth second data packet and the second sending duration. In this way, the plurality of first data packets and the plurality of second data packets can be sent to the first slave computer and the second slave computer alternately, and serial port multiplexing of the host computer is implemented.
[0129] In some embodiments of the present application, the information acquisition module 710 is specifically configured to:
[0130] acquire first communication protocol information of the host computer and the first slave computer;
[0131] determine a first data packet length based on the first communication protocol information;
[0132] acquire a preset fifth sending duration and a preset sixth sending duration, and determine the first sending duration based on the first data packet length, the fifth sending duration and the sixth sending duration.
[0133] In some embodiments of the present application, the first sending module 720 is specifically configured to:
[0134] determine a third sending duration of the Mth first data packet based on the sending time of the Mth first data packet and a current time;
[0135] compare the third sending duration with the first sending duration;
[0136] if the third sending duration reaches the first sending duration, send an Mth second data packet in the plurality of second data packets to the second slave.
[0137] In some embodiments of the present application, the first sending module 720 is specifically further configured to:
[0138] monitor whether a first response packet returned by the first slave based on the Mth first data packet is received before the third sending duration reaches the first sending duration;
[0139] if the first response packet is not received, update the first error count value based on a preset first value;
[0140] if the first response packet is received, update the first error count value to a preset second value.
[0141] In some embodiments of the present application, the first sending module 720 is specifically further configured to:
[0142] compare the updated first error count value with a preset first count threshold;
[0143] if the updated first error count value reaches the first count threshold, output first fault information; the first fault information indicates that a communication fault occurs between the host and the first slave.
[0144] In some embodiments of the present application, the second sending module 730 is specifically configured to:
[0145] determine a fourth sending duration of the Mth second data packet based on a sending time of the Mth second data packet and a current time;
[0146] compare the fourth sending duration with a second sending duration;
[0147] if the fourth sending duration reaches the second sending duration, send an M+1th first data packet in the plurality of first data packets to the first slave.
[0148] In some embodiments of the present application, the second sending module 730 is specifically further configured to:
[0149] monitor whether a second response packet returned by the second slave based on the Mth second data packet is received before the fourth sending duration reaches the second sending duration;
[0150] if the second response packet is not received, update a second error count value based on a preset third value;
[0151] if the second response packet is received, update the second error count value to a preset fourth value.
[0152] In some embodiments of the present application, the second sending module 730 is further configured to:
[0153] compare the updated second error count value with a preset second count threshold value;
[0154] output second fault information if the updated second error count value reaches the second count threshold value, the second fault information indicating that the host and the second slave machine have a communication failure.
[0155] The embodiments of the present application also provide an air conditioner which integrates any of the serial port multiplexing communication devices provided by the embodiments of the present application. The air conditioner comprises:
[0156] one or more processors;
[0157] a memory; and
[0158] one or more application programs, wherein the one or more application programs are stored in the memory and configured to execute the steps in the serial port multiplexing communication method in any of the serial port multiplexing communication method embodiments by the processor.
[0159] The embodiments of the present application also provide an air conditioner which integrates any of the serial port multiplexing communication devices provided by the embodiments of the present application. As shown in Figure 7 , a structural schematic diagram of an air conditioner related to the embodiments of the present application is shown, in particular:
[0160] The air conditioner can include a processor 801 with one or more processing cores, a memory 802 with one or more computer readable storage media, a power supply 803, an input unit 804, and the like. Those skilled in the art can understand that the air conditioner structure shown in Figure 7 does not constitute a limitation on the air conditioner, and can include more or fewer components than those shown, or combine certain components, or different component arrangements.
[0161] Among them:
[0162] The processor 801 is the control center of the air conditioner, and connects various parts of the air conditioner through various interfaces and lines. By running or executing software programs and / or modules stored in the memory 802, and calling data stored in the memory 802, the processor 801 performs various functions of the air conditioner and processes data, thereby overall monitoring the air conditioner. Optionally, the processor 801 can include one or more processing cores; preferably, the processor 801 can integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface, and application programs, etc., and the modem processor mainly processes wireless communication. It can be understood that the above-mentioned modem processor can also not be integrated into the processor 801.
[0163] The memory 802 can be used to store software programs and modules, and the processor 801 executes various functions and data processing by running the software programs and modules stored in the memory 802. The memory 802 can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, application programs required by at least one function (such as a sound playing function, an image playing function, etc.), and the like; and the data storage area can store data created according to the use of the air conditioner, etc. In addition, the memory 802 can include a high-speed random access memory, and can also include a non-volatile memory, such as at least one magnetic disk storage device, a flash memory device, or other volatile solid-state memory device. Accordingly, the memory 802 can also include a memory controller to provide the processor 801 with access to the memory 802.
[0164] The air conditioner also includes a power supply 803 for supplying power to various components. Preferably, the power supply 803 can be logically connected to the processor 801 through a power management system, so as to realize functions such as charge management, discharge management, and power consumption management through the power management system. The power supply 803 can also include one or more than one direct current or alternating current power supply, a recharging system, a power failure detection circuit, a power converter or inverter, a power status indicator, and any other components.
[0165] The air conditioner can also include an input unit 804, which can be used to receive input digital or character information, and generate keyboard, mouse, joystick, optical or trackball signal inputs related to user settings and function controls.
[0166] Although not shown, the air conditioner can also include a display unit, etc., which will not be described here. In particular, in the present embodiment, the processor 801 in the air conditioner will load executable files corresponding to the processes of one or more than one application program into the memory 802 according to the following instructions, and run the application programs stored in the memory 802 by the processor 801, so as to realize various functions, as follows:
[0167] Obtaining a plurality of first data packets, a plurality of second data packets, a first sending duration and a second sending duration;
[0168] Sending an Mth first data packet in the plurality of first data packets to a first slave, and sending an Mth second data packet in the plurality of second data packets to a second slave based on a sending time of the Mth first data packet and the first sending duration; wherein M is an integer and 0
[0169] Based on a sending time of the Mth second data packet and the second sending duration, sending an M+1th first data packet in the plurality of first data packets to the first slave, so as to realize serial port multiplexing of the host.
[0170] Those skilled in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by instructions or by controlling relevant hardware by the instructions, which can be stored in a computer readable storage medium and loaded and executed by a processor.
[0171] To this end, the embodiments of the present application provide a computer readable storage medium, which can include a read only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc. A computer program is stored on the storage medium, and the computer program is loaded by a processor to execute the steps in any of the serial port multiplexing communication methods provided by the embodiments of the present application. For example, the computer program loaded by the processor can execute the following steps:
[0172] obtaining a plurality of first data packets, a plurality of second data packets, a first sending duration and a second sending duration;
[0173] sending an Mth first data packet in the plurality of first data packets to a first slave, and sending an Mth second data packet in the plurality of second data packets to a second slave based on a sending time of the Mth first data packet and the first sending duration, wherein M is an integer and 0 < M ≤ N-1, and N is the number of the plurality of first data packets;
[0174] sending an M+1th first data packet in the plurality of first data packets to the first slave based on a sending time of the Mth second data packet and the second sending duration, to realize serial port multiplexing of the host.
[0175] In the above embodiments, the description of each embodiment has its own focus, and the parts not described in detail in a certain embodiment can be referred to the detailed description of other embodiments above, which will not be repeated here.
[0176] In specific implementation, the above various units or structures can be implemented as independent entities, or can be combined as the same or several entities, and the specific implementation of the above various units or structures can be referred to the method embodiments above, which will not be repeated here.
[0177] The specific implementation of the above various operations can be referred to the embodiments above, which will not be repeated here.
[0178] The serial port multiplexing communication method, the serial port multiplexing communication device, the air conditioner and the computer readable storage medium provided by the embodiments of the present application are described in detail above, and the principles and implementation manners of the present application are described by applying specific examples. The above embodiment description is only used to help understand the method of the present application and its core idea; meanwhile, for those skilled in the art, according to the idea of the present application, the specific implementation manner and application range will be changed, and the above description should not be understood as a limitation on the present application.
Claims
1. A method of multiplexing communications over a serial port, the method comprising: The application is applied to a host computer, which is in communication connection with a first slave computer and a second slave computer, and the serial port multiplexing communication method comprises the following steps: Obtaining a plurality of first data packets, a plurality of second data packets, a first sending duration and a second sending duration; Sending an Mth first data packet in the plurality of first data packets to the first slave computer, and sending an Mth second data packet in the plurality of second data packets to the second slave computer based on the sending time of the Mth first data packet and the first sending duration, wherein M is an integer and 0 < M ≤ N-1, and N is the number of the plurality of first data packets; Based on the sending time of the Mth second data packet and the second sending duration, sending an M+1th first data packet in the plurality of first data packets to the first slave computer to realize the serial port multiplexing of the host computer.
2. The method of claim 1, wherein, The sending of the Mth second data packet in the plurality of second data packets to the second slave computer based on the sending time of the Mth first data packet and the first sending duration comprises the following steps: Determining a third sending duration of the Mth first data packet based on the sending time of the Mth first data packet and the current time; Comparing the third sending duration with the first sending duration; If the third sending duration reaches the first sending duration, sending the Mth second data packet in the plurality of second data packets to the second slave computer.
3. The method of claim 2, wherein, After the sending of the Mth first data packet in the plurality of first data packets to the first slave computer, the following steps are further included: Monitoring whether a first response packet returned by the first slave computer based on the Mth first data packet is received before the third sending duration reaches the first sending duration; If the first response packet is not received, updating a first error count value based on a preset first value; If the first response packet is received, updating the first error count value to a preset second value.
4. The method of claim 3, wherein, After the updating of the first error count value based on the preset first value, the following steps are included: Comparing the updated first error count value with a preset first count threshold value; If the updated first error count value reaches the first count threshold value, outputting first fault information; the first fault information represents that a communication fault occurs between the host computer and the first slave computer.
5. The method of claim 1, wherein, The sending of the M+1th first data packet in the plurality of first data packets to the first slave computer based on the sending time of the Mth second data packet and the second sending duration comprises the following steps: Determining a fourth sending duration of the Mth second data packet based on the sending time of the Mth second data packet and the current time; Comparing the fourth sending duration with the second sending duration; If the fourth sending duration reaches the second sending duration, sending the M+1th first data packet in the plurality of first data packets to the first slave computer.
6. The method of claim 5, wherein, After the sending of the Mth second data packet in the plurality of second data packets to the second slave computer based on the sending time of the Mth first data packet and the first sending duration, the following steps are further included: monitoring whether the second response packet returned by the second slave based on the Mth second data packet is received before the fourth sending duration reaches the second sending duration; updating a second error count value based on a preset third value if the second response packet is not received; updating the second error count value to a preset fourth value if the second response packet is received.
7. The method of claim 6, wherein, after the second error count value is updated based on the preset third value, comprising: comparing the updated second error count value with a preset second count threshold value; outputting second failure information if the updated second error count value reaches the second count threshold value; the second failure information representing that the host and the second slave have communication failure.
8. The method of claim 1, wherein, the first sending duration is obtained based on the following steps, comprising: obtaining first communication protocol information of the host and the first slave; determining a first data packet length based on the first communication protocol information; obtaining a preset fifth sending duration and a preset sixth sending duration, and determining the first sending duration based on the first data packet length, the fifth sending duration and the sixth sending duration.
9. A serial multiplexing communication device, comprising: applied to a host, the host being in communication connection with a first slave and a second slave, the serial port multiplexing communication device comprising: an information obtaining module, configured to obtain a plurality of first data packets, a plurality of second data packets, a first sending duration and a second sending duration; a first sending module, configured to send an Mth first data packet in the plurality of first data packets to the first slave, and send an Mth second data packet in the plurality of second data packets to the second slave based on a sending time of the Mth first data packet and the first sending duration; wherein M is an integer and 0 < M ≤ N-1, N being a quantity of the plurality of first data packets; a second sending module, configured to send an M+1th first data packet in the plurality of first data packets to the first slave based on a sending time of the Mth second data packet and the second sending duration, so as to realize serial port multiplexing of the host.
10. An air conditioner characterized by comprising: the air conditioner comprises: one or more processors; a memory; and one or more application programs, wherein the one or more application programs are stored in the memory and configured to be executed by the processor to implement the serial port multiplexing communication method of any one of claims 1 to 8.
11. A computer readable storage medium, characterized in that, a computer program is stored thereon, the computer program being loaded by a processor to execute the steps in the serial port multiplexing communication method of any one of claims 1 to 8.
Citation Information
Patent Citations
Communication method based on ID packet
CN106358276A
Data transmission method, device, storage medium and system
CN108009107A