CN117118951A - Method for dynamically distributing addresses of universal slaves of one master and multiple slaves bus - Google Patents
Method for dynamically distributing addresses of universal slaves of one master and multiple slaves bus Download PDFInfo
- Publication number
- CN117118951A CN117118951A CN202311096957.6A CN202311096957A CN117118951A CN 117118951 A CN117118951 A CN 117118951A CN 202311096957 A CN202311096957 A CN 202311096957A CN 117118951 A CN117118951 A CN 117118951A
- Authority
- CN
- China
- Prior art keywords
- address
- slave
- communication
- addresses
- bus
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
- 238000000034 method Methods 0.000 title claims abstract description 36
- 238000004891 communication Methods 0.000 claims abstract description 79
- 238000012544 monitoring process Methods 0.000 claims abstract description 5
- 238000010586 diagram Methods 0.000 description 1
- 230000005611 electricity Effects 0.000 description 1
- 238000005259 measurement Methods 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 238000012545 processing Methods 0.000 description 1
- 238000006467 substitution reaction Methods 0.000 description 1
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L61/00—Network arrangements, protocols or services for addressing or naming
- H04L61/50—Address allocation
- H04L61/5053—Lease time; Renewal aspects
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L12/00—Data switching networks
- H04L12/28—Data switching networks characterised by path configuration, e.g. LAN [Local Area Networks] or WAN [Wide Area Networks]
- H04L12/40—Bus networks
- H04L12/40169—Flexible bus arrangements
- H04L12/40176—Flexible bus arrangements involving redundancy
- H04L12/40195—Flexible bus arrangements involving redundancy by using a plurality of nodes
Abstract
The application relates to a method for dynamically distributing addresses of a master-multi-slave bus universal slave, which comprises the following steps: the host sequentially polls each communication address in the available communication range list; the slave starts to answer after randomly delaying for a preset time after receiving communication information consistent with the current address, and starts bus busy monitoring during the delay period, wherein the communication information is from the host, and the communication information comprises the currently polled communication address; if the bus is busy in the delay period, the slave device considers that the current address is preempted, selects a communication address from the residual address pool as the address of the slave device, and deletes the communication address from the residual address pool; otherwise, the current address is the address of the slave device. The method can realize dynamic allocation of the slave addresses and avoid the conflict of the slave addresses.
Description
Technical Field
The application relates to the technical field of communication, in particular to a method for dynamically distributing addresses of universal slave machines of a master-multi-slave bus.
Background
In the fields of white electricity, engineering and the like, a bus communication mode of one master and multiple slaves is often used, and the communication structure is shown in fig. 1. Specifically, a Modbus communication protocol is used to describe a bus communication mode of a master and multiple slaves, each slave has and has only one address, the address range is (0-247), when the master sends a slave address except address 0, the slaves with corresponding addresses return a group of data after receiving a request frame of the master, the response data is transmitted through an RS-485 bus, because other slaves are also connected to the RS-485 bus, when the requested slaves respond, other slaves can also receive response data sent by the requested slaves to the master at the same time, in order to prevent the other slaves from receiving the response data sent by the requested slaves and generating misoperation, the data address of the requested slaves is added into the response data of the requested slaves, so that the data address of the returned data is different from the slaves although the data returned to the master is received by the requested slaves, and the other slaves do not respond. Therefore, in the prior art, a bus communication mode of one master and multiple slaves is adopted, and usually, a communication address needs to be allocated to the slaves in advance, and the master station coordinates and manages the communication. However, it is complicated to implement the setting workload of increasing the allocation of the communication address.
Disclosure of Invention
In order to solve the above-mentioned problems, an objective of the present application is to provide a method for dynamically allocating addresses of all slave units of a master multi-slave bus.
A method of dynamic allocation of a master-multi-slave bus universal slave address, the method comprising:
presetting a list of available communication address ranges among the host slaves;
the slave machines are provided with factory default addresses, the factory default addresses are in the available communication address range, and the factory default addresses of the plurality of slave machines can be the same;
determining a residual address pool according to the factory default address of the slave and the available communication address range list, wherein the residual address pool is a list formed by the unoccupied available communication addresses at present;
the host sequentially polls each communication address in the available communication range list;
the slave starts to answer after randomly delaying for a preset time after receiving communication information consistent with the current address, and starts bus busy monitoring during the delay period, wherein the communication information is from the host, and the communication information comprises the currently polled communication address; if the bus is busy in the delay period, the slave device considers that the current address is preempted, selects a communication address from the residual address pool as the address of the slave device, and deletes the communication address from the residual address pool; otherwise, the current address is the address of the slave device.
Preferably, the remaining address pool is also determined according to the number of the slave devices, specifically:
and eliminating the factory default address of the slave from the available communication address range list, and eliminating communication addresses beyond the number of the slave devices to form an initial residual address pool.
Preferably, all slaves are assigned the same factory default address.
Preferably, the host sequentially polls each communication address in the available communication range list, including:
selecting addresses with the same number as the slave devices from the available communication address range list;
the host polls the selected addresses in sequence until the last address in the current sequence is sent, and then starts polling from the first address in the current sequence.
Preferably, the random delay preset time includes:
presetting a delay time range;
and randomly determining the delay time from the delay time range.
Preferably, the method further comprises: the current address of the slave device is saved after power down is set.
Preferably, the method further comprises: and setting a slave address setting parameter, and manually configuring the slave address through the slave address setting parameter.
Preferably, after the slave address is manually configured by the slave address setting parameter, the slave receives the communication information consistent with the current address and directly responds without performing random delay.
The method does not need to be realized as the slave machine to allocate addresses one by one, and can be used for carrying out address preemption in a mode of randomly delaying busy measurement by the slave machine, thereby realizing the dynamic allocation of the addresses of the slave machines with one master machine and multiple slave machines. The method does not need to improve hardware, is purely software logic, and is suitable for various bus communication modes with one master and multiple slaves.
Drawings
FIG. 1 is a schematic diagram of a master-multiple-slave communication structure in the prior art;
FIG. 2 is a flow chart of the master address switching and slave address switching according to the present application.
Detailed Description
Embodiments of the present application are described in detail below.
The present embodiment provides a method for dynamically allocating addresses of a master-multi-slave bus universal slave, as shown in fig. 1, where the method includes:
the host sequentially polls each communication address in the available communication range list;
the slave starts to answer after randomly delaying for a preset time after receiving communication information consistent with the current address, and starts bus busy monitoring during the delay period, wherein the communication information is from the host, and the communication information comprises the currently polled communication address; if the bus is busy during the delay period, the slave device considers that the current address is preempted, selects a communication address from the residual address pool as the address of the slave device, and deletes the communication address from the residual address pool to update the residual address pool; otherwise, the current address is the address of the slave device.
The method comprises the steps of presetting a list of available communication address ranges between host slaves;
the slave machines are provided with factory default addresses, the factory default addresses are in the available communication address range, and the factory default addresses of the plurality of slave machines can be the same;
and determining a residual address pool according to the factory default address of the slave and the available communication address range list, wherein the residual address pool is a list formed by the available communication addresses which are not occupied at present. When the method is executed for the first time, the residual address pool is a default residual address pool, and the default residual address pool is an address list after the outgoing address of the slave machine is removed from the available communication range list. And in the subsequent execution process of the method, the occupied communication addresses are sequentially removed, the residual address pool is updated, and the communication addresses are distributed for the slaves from the updated residual address pool in the subsequent execution process.
The address allocation principle of the method is as follows:
the factory default address is set for the slave, and the situation of address conflict of the slave is not required to be considered. After the host sends the communication information, the slave is provided with random delay for preempting the address, if the bus is busy during the delay period, the current address is occupied, and the address is allocated for the current slave from the residual address pool. The method comprises the step of randomly determining an address from the residual address pool to be allocated to the current slave. In other embodiments, a rule for selecting an address from the remaining address pool may be preset, and address allocation may be performed according to the preset rule.
By adopting the scheme, the conflict situation of the slave machine address can be detected in real time, and the slave machine address can be automatically replaced after the conflict of the slave machine address is detected.
In the embodiment, the same factory default address is allocated to all the slaves, so that the slaves do not need to be additionally set for multiple times, and the setting is convenient.
Preferably, the host sequentially polls each communication address in the available communication range list, including: selecting addresses with the same number as the slave devices from the available communication address range list; the host polls the selected addresses in sequence until the last address in the current sequence is sent, and then starts polling from the first address in the current sequence. And determining a residual address pool according to the number of the slave devices, specifically: and eliminating the factory default address of the slave from the available communication address range list, and eliminating communication addresses beyond the number of the slave devices to form an initial residual address pool. By limiting the number of communication addresses by using the number of devices, the number of host polling times and the processing of the remaining address pools can be reduced, and the execution efficiency of the method can be improved.
Preferably, a slave address setting parameter is set, by which the slave address is manually configured. After the slave address is manually configured through the slave address setting parameter, the slave directly responds without random delay after receiving communication information consistent with the current address. The method comprises the steps that a user can autonomously select a mode of using a dynamic address or a manual configuration mode to allocate an address to a slave according to actual demands, the address of a specific slave is kept unchanged by setting parameters of the slave address, and after the setting parameters of the slave address are started and configured, the slave does not randomly delay and enters a step of bus busy monitoring when responding, so that the specific slave response is guaranteed to be at the highest priority.
In the above method, the random delay preset time includes: presetting a delay time range; and randomly determining the delay time from the delay time range. In the embodiment, the random delay may be set to 1-10ms, or other time ranges may be set according to the actual requirements. The delay time of the slave machine is randomly determined by setting the delay time range, so that the response time of the plurality of slave machines to the communication information is different, and the preemption of the current address can be realized. In the method, the current address of the slave equipment is saved after power failure is set, so that the slave can still communicate with the current communication address after dynamic address allocation is carried out on the slave.
While embodiments of the present application have been shown and described, it will be understood by those of ordinary skill in the art that: many changes, modifications, substitutions and variations may be made to the embodiments without departing from the spirit and principles of the application, the scope of which is defined by the claims and their equivalents.
Claims (8)
1. A method for dynamically allocating addresses of a master-multi-slave bus universal slave, the method comprising:
presetting a list of available communication address ranges among the host slaves;
the slave machines are provided with factory default addresses, the factory default addresses are in the available communication address range, and the factory default addresses of the plurality of slave machines can be the same;
determining a residual address pool according to the factory default address of the slave and the available communication address range list, wherein the residual address pool is a list formed by the unoccupied available communication addresses at present;
the host sequentially polls each communication address in the available communication range list;
the slave starts to answer after randomly delaying for a preset time after receiving communication information consistent with the current address, and starts bus busy monitoring during the delay period, wherein the communication information is from the host, and the communication information comprises the currently polled communication address; if the bus is busy in the delay period, the slave device considers that the current address is preempted, selects a communication address from the residual address pool as the address of the slave device, and deletes the communication address from the residual address pool; otherwise, the current address is the address of the slave device.
2. The method for dynamically allocating addresses of a master-multi-slave bus universal slave according to claim 1, further comprising determining a remaining address pool based on the number of slave devices, in particular:
and eliminating the factory default address of the slave from the available communication address range list, and eliminating communication addresses beyond the number of the slave devices to form an initial residual address pool.
3. The method of claim 1, wherein the same factory default address is allocated to all slaves.
4. The method of claim 1, wherein the host sequentially polls each address in the list of available communication ranges in sequence, comprising:
selecting addresses with the same number as the slave devices from the available communication address range list;
the host polls the selected addresses in sequence until the last address in the current sequence is sent, and then starts polling from the first address in the current sequence.
5. The method of claim 1, wherein the randomly delaying the predetermined time comprises:
presetting a delay time range;
and randomly determining the delay time from the delay time range.
6. The method of claim 1, wherein the method further comprises: the current address of the slave device is saved after power down is set.
7. The method of claim 1, wherein the method further comprises: and setting a slave address setting parameter, and manually configuring the slave address through the slave address setting parameter.
8. The method of claim 7, wherein the slave addresses are manually configured by the slave address setting parameters, and the slave receives the communication information consistent with the current address and directly responds without random delay.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202311096957.6A CN117118951A (en) | 2023-08-29 | 2023-08-29 | Method for dynamically distributing addresses of universal slaves of one master and multiple slaves bus |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202311096957.6A CN117118951A (en) | 2023-08-29 | 2023-08-29 | Method for dynamically distributing addresses of universal slaves of one master and multiple slaves bus |
Publications (1)
Publication Number | Publication Date |
---|---|
CN117118951A true CN117118951A (en) | 2023-11-24 |
Family
ID=88796149
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202311096957.6A Pending CN117118951A (en) | 2023-08-29 | 2023-08-29 | Method for dynamically distributing addresses of universal slaves of one master and multiple slaves bus |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN117118951A (en) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN117614939A (en) * | 2024-01-19 | 2024-02-27 | 杭州方千科技有限公司 | 485 communication address automatic allocation method for image light supplementing device |
-
2023
- 2023-08-29 CN CN202311096957.6A patent/CN117118951A/en active Pending
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN117614939A (en) * | 2024-01-19 | 2024-02-27 | 杭州方千科技有限公司 | 485 communication address automatic allocation method for image light supplementing device |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
JP4857374B2 (en) | Method for assigning tasks, data processing system, client data processing node and machine-readable storage medium | |
CA2219526C (en) | System for determining the frequency of repetitions of polling active stations relative to the polling of inactive stations | |
CN108924268B (en) | Container cloud service system and pod creation method and device | |
CN106789498B (en) | Network address allocation method of Modbus communication network, slave node equipment and communication system | |
CN107040284B (en) | Multi-address access method for improving reliability and stability of data transmission | |
CN102571996B (en) | IP (Internet Protocol) address assignment method, IP address assignment device and network system | |
CN110505319A (en) | A kind of RS485 is from device address auto-allocation method and system | |
CN117118951A (en) | Method for dynamically distributing addresses of universal slaves of one master and multiple slaves bus | |
JP2009524308A (en) | Method and system for dynamic resource allocation | |
WO2022135064A1 (en) | Wired communication bus communication method and system | |
CN113242170B (en) | Address allocation method and device | |
CN107370647B (en) | Method for interconnecting local area internal controller systems and local area network system | |
CN111355751A (en) | Task scheduling method and device | |
CN109889421B (en) | Router management method, device, terminal, system and storage medium | |
CN109525417B (en) | Household appliance access method based on internet access, household appliance controller and storage medium | |
CN113596188B (en) | Multi-device management method and device | |
CN107968718B (en) | Method, device and equipment for confirming main standby state | |
CN111597034B (en) | Processor resource scheduling method and device, terminal equipment and computer storage medium | |
CN110855465B (en) | Message processing method and device | |
US10417156B2 (en) | Hardware resource sharing within peripheral component interconnect express (PCIE) environment capable of assigning hardware resource dynamically | |
CN114938542B (en) | BLE protocol stack multilink management method, chip and system | |
CN113612514B (en) | Media resource processing system, method and equipment | |
CN117614940B (en) | Method and system for automatic configuration of serial communication equipment address | |
CN112665035B (en) | Multi-connected air conditioning system and control method thereof | |
CN114938375B (en) | Container group updating equipment and container group updating method |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination |