One-to-many communication method and system based on serial port
Through the polling mechanism and command group sending method in the serial communication method, the problem of communication blocking and high cost between one control terminal and multiple controlled terminals in serial communication is solved, and efficient and flexible serial communication is realized to meet the needs of many applications in the smart home field. Joint panel customization needs.
Patent Information
- Application Number
- CN202011630574.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-12-31
- Publication Date
- 2024-09-24
- Estimated Expiration
- 2040-12-31
AI Technical Summary
When implementing serial port communication, it is difficult for the existing technology to efficiently support communication between a control terminal and multiple controlled terminals, resulting in high costs and communication blocking problems, and it cannot be flexibly combined to meet different customization needs.
Through the serial communication method between the master and the slave, the polling mechanism and the command group sending method are used to realize time-sharing multiplexing of serial communication resources, avoid communication conflicts and blocking, and achieve high efficiency without pre-allocating communication resources. Complete communication tasks quickly.
It achieves efficient and fast communication with multiple slaves on one serial port, reduces costs, reduces serial port resource requirements, supports flexible combination design, meets different customization needs, and solves the problems of communication blocking and high cost.
Smart Images

Figure CN112765075B
Abstract
Description
Technical Field
[0001] The invention relates to a one-to-many communication method and system based on a serial port, belonging to the technical field of serial port communication. Background Art
[0002] Common multi-device communication methods include: serial communication, such as RS-232 port, serial port, asynchronous port or a COM (communication) port; or 485 communication. Characteristics of RS232 interface: only point-to-point communication, not supporting multi-point communication; Characteristics of RS485 communication: with multi-station communication capability, a single RS485 interface can be used to easily establish a device network.
[0003] In specific application fields, how to realize the communication needs of one control end and multiple controlled ends through serial communication is a technical problem that needs to be solved. For example, the Chinese utility model patent with the authorization announcement number CN 206441155 U discloses a control circuit that can realize RS232 one-to-many communication, specifically including: the RXD receiving data end includes an interface driver circuit (SN75174 interface driver chip) and a data selection circuit (CD4051 switch circuit); the TXD sending data end includes an interface buffer (SN75175 integrated chip) and a data distributor (74HCT245 integrated chip) for receiving data information of the master control device; the baud rate is increased by time division multiplexing, and the RXD data of multiple controlled ends are integrated into one RXD and sent to the control end, and then the data information of each RXD is decoded through an inverse process to complete the RS232 interface transmission in the case of multiple control ends and multiple controlled ends.
[0004] For example, in the field of smart home, how to meet the communication needs of one control end and multiple controlled ends through serial ports is also a technical problem that needs to be solved urgently. For example, the integrated control multi-link panel (the panel integrates 86 controller units with different functions such as switches, scenes, curtains, thermostats, etc., and is a smart home panel product that is ultimately presented with multi-function control and combination), its main control circuit usually uses a single-chip microcomputer as the main control chip to control, then it is necessary to set up multiple serial ports to communicate with different types of controller modules (86 units such as switches, scenes, thermostats, etc.), so as to realize the communication method of one main control circuit controlling multiple devices through multiple serial ports or 485 chips.
[0005] In actual situations, if 485 communication is used to meet one-to-many control, it will result in high costs, because the microcontroller used in the integrated panel does not have 485 communication, and a new 485 chip needs to be added; if serial communication is used, due to the limited serial ports on the microcontroller, if one device communicates with multiple devices, a microcontroller with a large number of serial ports is required, which also increases the cost.
[0006] In addition, in the field of smart home, the above-mentioned integrated control multi-panel design still has the following problems:
[0007] The corresponding customization requirements of multi-gang panels used in different occasions vary greatly. The differences involve: the types of 86 units contained in each multi-gang panel are different (such as switches, scenes, sockets, curtains, thermostats, etc.), the order of the 86 units is different, and the number of load paths of each 86 unit is different (such as single-open / double-open / triple-open / quadruple-open).
[0008] Different devices (86 units) cannot be combined arbitrarily in hardware. Every time a new 86-unit combination is added, the software and hardware need to be redesigned, which consumes manpower, increases costs and takes a long time. Summary of the invention
[0009] The purpose of the present invention is to provide a one-to-many communication method and system based on a serial port, so as to solve the problem of high cost in realizing one-to-many communication between one control terminal and multiple controlled terminals.
[0010] To achieve the above object, the solution of the present invention includes:
[0011] A one-to-many communication system based on a serial port of the present invention comprises a host, a plurality of slaves and a transceiver circuit; the transceiver circuit comprises an output line connected to an output interface of a serial port of the host and an input line connected to an input interface of a serial port of the host; an input interface of a serial port of a slave is connected to the output line, and an output interface of a serial port of a slave is connected to the input line;
[0012] The host and the slaves realize the communication between the host and several slaves through the following serial communication method:
[0013] The host polls the status of each slave at intervals through the transceiver line, and the reply time of the slave in response to the host polling is less than the interval time of the host polling.
[0014] The present invention proposes a serial communication method for realizing a single serial port of a control end and multiple controlled ends, which effectively solves the cost problem of one-to-many communication and avoids the communication conflict and communication blocking problems existing in one-to-many serial port communication polling for status update.
[0015] Furthermore, the method for the host to poll the status of each slave is to send a polling instruction through an output line, and the polling instruction includes the address of the currently polled slave.
[0016] Furthermore, the method for the slave to respond to the host polling is that the slave parses the polling instruction, and when the address in the polling instruction does not match the local address, the slave does not respond; if the address matches, the slave reports the local status.
[0017] During the host polling process, the time-sharing multiplexing of serial communication resources is realized by sending commands in batches and the receiving end judging the command target. Whoever is the command target currently occupies the serial line to report the status, and the occupation time must not exceed the polling interval to prevent interference with the status query of the next slave. The communication process is efficient and fast, and the host does not need to pre-allocate communication resources or set up an additional communication priority mechanism.
[0018] Furthermore, the serial communication method also includes: the host sends a control instruction through a transceiver line, and the control instruction includes a control content and an address of a slave that needs to respond to the control.
[0019] Furthermore, the slave machine parses the control instruction, and does not respond when the address in the control instruction does not match the local address; if the address matches, it responds to the control content.
[0020] During the process of sending the host control command, the receiving end determines the command target by sending the command in batches, thus realizing the time-sharing multiplexing of serial communication resources. Whoever serves as the command target responds to the control command. The communication process is efficient and fast, and the host does not need to pre-allocate communication resources or set up an additional communication priority mechanism.
[0021] Furthermore, the serial port communication method also includes: when the slave does not send data externally, the output interface of the slave serial port is configured as a floating mode.
[0022] The output interface of the slave device that is not communicating is placed in a floating state to prevent the output interface level of the host device from being pulled down and interfering with the communication between the host and other slave devices.
[0023] Furthermore, the serial port communication method also includes: setting the serial port communication baud rate to 115200.
[0024] 115200 is the best baud rate setting in actual implementation, achieving higher transmission efficiency.
[0025] Furthermore, the serial port communication method also includes: the slaves do not communicate with each other, and the slaves do not actively communicate with the host.
[0026] The slave does not actively communicate, further preventing communication conflicts or communication blockages.
[0027] The one-to-many communication method based on a serial port of the present invention adopts the serial port communication method in the one-to-many communication system based on a serial port as described above to realize the communication between the host and several slaves. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] Figure 1 The invention discloses a circuit schematic diagram of a one-to-many communication system based on a serial port. DETAILED DESCRIPTION
[0029] The present invention will be further described in detail below in conjunction with the accompanying drawings.
[0030] System Example:
[0031] The serial port usually only includes two conventional input interfaces RX and output interfaces TX. Generally, serial port communication is one-to-one between the host and the slave, that is, one-to-one unidirectional transmission communication. If you want to realize one-to-many communication between the host and the slaves based on the serial port, the problem that comes with it is the communication blockage between a host and multiple slaves. Multiple RX signals interfere with each other, causing the control end (host) to be unable to receive the information of the controlled end (slave) normally.
[0032] The hardware circuit of this solution is as follows Figure 1 As shown, the core board is used as the main control host, and multiple 86 units as slaves are integrated through a serial port control. UART is used to connect each 86 functional module with the core board. Specifically, the transceiver line includes TX line, RX line and GND line, and TX line, RX line and GND line are connected to the TX port, RX port and GND port of the core board serial port respectively, and each 86 unit is hung on the transceiver line, and the TX port of the 86 unit serial port is connected to the RX line, the RX port is connected to the TX line, and the GND port is connected to the GND line. That is, all modules are connected with the GND line, TX line, RX line and VCC line, the core board is used as the host, and each 86 combination unit is used as a slave, and the host can communicate with each slave, and each slave cannot communicate with each other. In the field of smart home, the smart home system includes smart home devices and smart home central control gateways, and the smart home central control gateway is a central control device for centralized control of each smart home device; the multi-link control panel establishes a communication connection with the smart home central control gateway as a smart home device, and the core board of the multi-link control panel can receive the control instructions of the smart home central control gateway as the communication host in the present invention. The core board (communication host) of the multi-link control panel, based on the serial port one-to-many communication method of the present invention, sends the control instructions received from the smart home central control gateway and the like to the corresponding 86 units (communication slaves), that is, sends control instructions to the corresponding controlled 86 functional modules (switches, scenes, sockets, thermostats, curtains, etc.) through serial communication to achieve the corresponding functions. The slave itself can realize local functions. Taking switches and thermostats as examples, the human-computer interaction part and relay control are directly realized by the 86 combination units; at the same time, when the control instructions issued are received through the serial port, the instructions are parsed and implemented; and when the central control gateway queries, the local status that needs to be synchronized to the central control gateway is packaged and reported to the central control gateway through the serial port and the core board.
[0033] In order to realize one-to-many communication based on serial port and solve the communication blocking problem of one-to-many communication, the following serial port communication method is adopted.
[0034] First, each 86-unit combination unit (slave) must be configured with an address according to the combination requirements before leaving the factory, and the address must be unique. When networking, the core board (host) knows the address of the slave connected to the network. At the same time, the host includes a key network access function, and after accessing the network, it reports the type and order of the 86-unit combination it contains.
[0035] The serial communication method of the present invention includes the following two communication processes:
[0036] 1) Host polling process.
[0037] The host polling process is a process in which the host periodically queries the status of each slave, which is used for the host to master and periodically update the status of the slave. The host needs to poll and collect the status of each 86 combination unit. When a status change is detected, it reports to the host computer to achieve synchronization between the local 86 combination unit status and the host computer.
[0038] During the host polling process, the host sends out a status query instruction through the TX port according to a certain polling cycle. Each round of status query instructions is for a slave. The status query instruction contains the corresponding slave address queried in the current cycle and the status query identifier. After the status query instruction is issued, it is received by each networked slave through the RX port of its own serial port through the transceiver line TX line. After each slave receives the instruction issued by the host, it configures the address of each instruction received. When the instruction does not belong to itself, it directly discards it and does not respond to the instruction. When the address in the instruction is obtained by parsing the instruction and matches its own address, the instruction content continues to be parsed. After obtaining the status query identifier of the host, the timer starts timing to ensure that when replying to the host, the host reception completion time is not greater than the host polling cycle (the interval time of the host polling). For example, if the host polling interval is 100ms, if the current reception completion time is greater than 80ms, no reply will be made to the instruction to solve the bus conflict problem that may be caused by the slave program blocking the reply.
[0039] That is, set the host interval polling cycle T, and set the slave's reply completion cycle t to the host. The reply completion cycle t must be smaller than the host interval polling cycle T.
[0040] When the reply completion cycle is less than the host polling interval, the corresponding slave will package and report the local status that needs to be synchronized to the host. After the polling interval, the host continues to issue a status query instruction containing the next slave address.
[0041] 2) Forwarding and parsing of control instructions.
[0042] When the host receives a local operation of the multi-link control panel (such as voice, button, touch control, etc.) or a control command from the host computer (such as the smart home central control gateway) (for example, to adjust the thermostat, the instruction needs to increase the 86 combination unit number issued), the control instruction is issued through the TX port. The control instruction includes the address of the corresponding 86 combination unit (slave) found by the host according to the number, and the control content (such as the specific temperature set for the thermostat). After the control instruction is issued, it is received by each networked slave through the RX port of its own serial port through the transceiver line TX line. After each slave receives the instruction issued by the host, it configures the address of each instruction received. When the instruction does not belong to itself, it directly discards it and does not respond to the instruction. When the address in the instruction is obtained by parsing the instruction and matches its own address, it continues to parse the instruction content, responds to the control after obtaining the corresponding control content, and performs corresponding control according to the control content (for example, the thermostat completes the setting of the specific temperature).
[0043] In addition, each slave is not allowed to actively report data, and the output interface TX of each slave must be configured as a floating input mode when no data is sent; the output interface TX of the slave is set to a floating mode when no data is sent to avoid affecting the communication of other slaves. Normally, the input interface RX of the host needs to be in a floating input mode. If the output interface TX of the slave is not set to a floating input mode, the level of the input interface RX of the host will be raised.
[0044] Preferably, the serial communication baud rate needs to be 115200 to speed up bus transmission efficiency; this is the best baud rate setting during implementation, and in practice, a suitable baud rate range can be configured according to the solution to achieve higher transmission efficiency.
[0045] The one-to-many communication device based on the serial port of the present invention has the following characteristics: 1) each slave is not allowed to actively report data; 2) when no data is sent, the TX port of each slave must be configured as a floating input mode; 3) the reply completion cycle of the slave to the host is set to be less than the host interval polling cycle; 4) each 86 combination unit must be configured with an address according to the combination requirements before leaving the factory, and the address needs to be unique. The core board sends instructions containing the address, and the slave configures the address for each instruction received, and directly discards the instruction when it does not belong to itself.
[0046] The present invention overcomes the communication blocking problem during one-to-many serial port communication, breaks the simple one-to-one communication mode of the traditional serial port, supports one-to-many communication mode, and solves the problem of communicating with multiple slave devices without relying on hardware switching due to the small number of ports of the master device. In terms of resources, the communication ports are reduced, the port resources are saved, and a serial port-based communication method between a control machine and multiple controlled machines is logically realized.
[0047] Method Example:
[0048] The one-to-many communication method based on a serial port of the present invention has been introduced clearly enough in the serial port communication method of the device embodiment, and will not be repeated here.
[0049] The one-to-many communication method based on serial port proposed in the present invention does not need to add serial ports on the basis of the existing single-chip microcomputer, and can solve the problem that 485 communication or single-chip microcomputer with multiple serial ports is used in the control of multi-link integrated panel, which causes increased cost and cannot be flexibly combined to meet the needs of rich customized functions; it can be realized on a smart home multi-link control panel, through a core board (that is, the "host" in the present invention) and multiple 86 units ("slaves" in the communication system) such as switches, scenes, and thermostats. Effective communication and saving of serial port resources; and compared with the existing multi-link product solution of designing a core board for each 86 unit separately, the cost is further reduced, and a customized design of "one host to multiple slaves" can be performed according to demand, which meets the "building block" flexible and arbitrary combination, and solves the current technical problem that the design of multi-link products is labor-intensive and has a long cycle due to differences in the type and sequence of the 86 units.
Claims
1. A one-to-many communication system based on a serial port, characterized in that: It includes a host, several slaves and a transceiver circuit; the transceiver circuit includes an output line connected to the host serial port output interface and an input line connected to the host serial port input interface; the input interface of the slave serial port is connected to the output line, and the output interface of the slave serial port is connected to the input line; The host and the slaves realize the communication between the host and several slaves through the following serial communication method: The host polls the status of each slave at intervals through the transceiver line, and the reply time of the slave in response to the host polling is less than the interval time of the host polling; When the slave does not send data to the outside, the output interface of the slave serial port is configured as a floating mode; The host is a core board, and the slave is an 86 functional module; each 86 functional module is configured with an address according to the combination requirements, and the address is unique; the method for the host to poll the status of each slave is to send a polling instruction through an output line, and the polling instruction includes the address of the currently polled slave; the method for the slave to respond to the host polling is that the slave parses the polling instruction, and when the address in the polling instruction does not match the local address, it does not respond; if it matches, it reports the local status.
2. The one-to-many communication system based on serial port according to claim 1, characterized in that: The serial communication method further includes: the host sends a control instruction through a transceiver line, wherein the control instruction includes control content and an address of a slave that needs to respond to the control.
3. The one-to-many communication system based on serial port according to claim 2, characterized in that: The slave machine parses the control instruction, and does not respond when the address in the control instruction does not match the local address; if they match, it responds with the control content.
4. The one-to-many communication system based on serial port according to claim 1 or 3, characterized in that: The serial port communication method also includes: setting the serial port communication baud rate to 115200.
5. The one-to-many communication system based on serial port according to claim 1, characterized in that: The serial communication method also includes: the slaves do not communicate with each other, and the slaves do not actively communicate with the host.
6. A one-to-many communication method based on a serial port, characterized in that: The serial port communication method in the one-to-many communication system based on a serial port as claimed in any one of claims 1 to 5 is adopted to realize the communication between the host and several slaves.
