CN115442333A - Self-networking method and device based on RS485 communication, computer equipment and medium - Google Patents

Self-networking method and device based on RS485 communication, computer equipment and medium Download PDF

Info

Publication number
CN115442333A
CN115442333A CN202211000068.0A CN202211000068A CN115442333A CN 115442333 A CN115442333 A CN 115442333A CN 202211000068 A CN202211000068 A CN 202211000068A CN 115442333 A CN115442333 A CN 115442333A
Authority
CN
China
Prior art keywords
address
networking
slave
instruction
network
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
Application number
CN202211000068.0A
Other languages
Chinese (zh)
Inventor
薛文锋
张碎红
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
CHANGJIANG ELECTRIC EQUIPMENT
Original Assignee
CHANGJIANG ELECTRIC EQUIPMENT
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by CHANGJIANG ELECTRIC EQUIPMENT filed Critical CHANGJIANG ELECTRIC EQUIPMENT
Priority to CN202211000068.0A priority Critical patent/CN115442333A/en
Publication of CN115442333A publication Critical patent/CN115442333A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L12/00Data switching networks
    • H04L12/02Details
    • H04L12/16Arrangements for providing special services to substations
    • H04L12/18Arrangements for providing special services to substations for broadcast or conference, e.g. multicast

Abstract

The application discloses a self-networking method, a device, computer equipment and a medium based on RS485 communication, wherein the self-networking method based on RS485 communication comprises the following steps executed by a host end: sending a networking broadcast instruction to a network; receiving a slave instruction response data packet which carries a true random address and is returned by a target slave end, and caching the slave instruction response data packet; matching an internal networking address for a target slave machine end based on a true random address corresponding to a slave machine instruction response data packet and a data packet arrival sequence; sending an address modification instruction carrying an internal networking address to a target slave terminal; and when the current time of the system meets the longest delay waiting time limit, the step of sending the networking broadcast instruction to the network is repeatedly executed until the network self-networking is completed. The Ad-hoc network method based on RS485 communication does not need to manually set a fixed address, and improves the intellectualization and the automatic expandability of the RS485 network.

Description

Self-networking method and device based on RS485 communication, computer equipment and medium
Technical Field
The invention relates to the technical field of industrial internet communication, in particular to an RS485 communication-based ad hoc network method, an RS485 communication-based ad hoc network device, computer equipment and a medium.
Background
In the RS485 communication network, a master-slave communication mode is generally adopted, that is, one master has a plurality of slaves. The RS485 communication is in a half-duplex mode, the host and the slave are hung on the bus in a parallel mode, only one terminal can send data to the system bus in the communication network at the same time, and the communication mode of the host and the slave is a one-question-one-answer mode, namely, the host sends a data packet to the bus, wherein the data packet contains the address of the slave which the host wants to communicate; after receiving the data packet of the host, the slave compares whether the address in the data packet is consistent with the slave address of the slave, thereby determining whether the data packet is sent to the local machine.
The slave addresses are usually fixed addresses manually set, and the master needs to manually input all the slave addresses in the network to perform normal communication. By adopting the mode, the local addresses of the host and the slave need to be manually set to be fixed, and the operation is complicated; the addresses of the slave machines must keep uniqueness, and the same slave machine addresses cannot exist in the network, so that errors are easily caused in manual address setting, network abnormity is caused, and normal work cannot be realized; in the case of unattended operation, the method of manually setting the local address is difficult to operate normally.
Disclosure of Invention
Embodiments of the present invention provide an ad hoc network method, apparatus, computer device and medium based on RS485 communication, to solve the problems that a network is abnormal due to an error easily occurring in manually setting an address, and thus the network cannot work normally, and that a manner of manually setting a local address is difficult to operate normally in an unattended scene.
An Ad hoc network method based on RS485 communication comprises the following steps executed by a host side:
sending networking broadcast instructions to a network, wherein the networking broadcast instructions are used for generating true random addresses by a plurality of slave computers based on the networking broadcast instructions;
receiving a slave computer instruction response data packet which is returned by a target slave computer end and carries a true random address, and caching the slave computer instruction response data packet; matching an internal networking address for a target slave machine end based on a true random address corresponding to a slave machine instruction response data packet and a data packet arrival sequence within the longest delay waiting time limit;
sending a modification address instruction carrying an internal networking address to a target slave end so that the target slave end replaces a corresponding true random address with the internal networking address;
and when the current time of the system meets the longest delay waiting time limit, the step of sending the networking broadcast instruction to the network is repeatedly executed until the continuous times of receiving no slave instruction response data packet returned by any slave end meet the maximum waiting times, and the network ad hoc network is completed.
An Ad hoc network device based on RS485 communication, includes the host computer end, and the host computer end includes:
the broadcast networking instruction sending module is used for sending networking broadcast instructions to a network and generating true random addresses by a plurality of slave computers based on the networking broadcast instructions;
the cache response data packet module is used for receiving a slave instruction response data packet which is returned by the target slave end and carries a true random address, and caching the slave instruction response data packet;
the matching internal networking address module is used for matching an internal networking address for a target slave machine end based on a true random address corresponding to a slave machine instruction response data packet and a data packet arrival sequence within the longest delay waiting time limit;
the sending modification address instruction module is used for sending a modification address instruction carrying an internal networking address to the target slave end so that the target slave end replaces the corresponding true random address with the internal networking address;
and the network ad hoc networking completion module is used for repeatedly executing the step of sending the networking broadcast instruction to the network when the current time of the system meets the maximum delay waiting time limit until the continuous times of receiving no slave instruction response data packets returned by any slave end meet the maximum waiting times, and completing the network ad hoc networking.
A computer device comprises a memory, a processor and a computer program which is stored in the memory and can run on the processor, and the RS485 communication-based ad hoc network method is realized when the processor executes the computer program.
A computer readable medium, which stores a computer program, and when the computer program is executed by a processor, the RS485 communication-based ad hoc network method is implemented.
An RS485 communication-based ad hoc network method comprises the following steps executed by a host side:
receiving a networking broadcast instruction sent by a host computer on a network;
generating a true random address based on the networking broadcast instruction, and generating random delay time based on the true random address;
after delaying according to the random delay time, returning a slave instruction response data packet carrying a true random address to the host end;
receiving a modified address instruction which is sent by a host end and carries an internal networking address;
and replacing the true random address corresponding to the local machine with an internal networking address, and entering a slave silent state.
An ad-hoc network device based on RS485 communication comprises a slave end, wherein the slave end comprises:
the broadcast instruction receiving module is used for receiving a networking broadcast instruction sent by a host computer on a network;
the real random address generating module is used for generating a real random address based on the networking broadcasting instruction and generating random delay time based on the real random address;
the return response data packet module is used for returning a slave instruction response data packet carrying a true random address to the host end after delaying according to the random delay time;
the receiving and modifying address instruction module is used for receiving a modifying address instruction which is sent by the host end and carries an internal networking address;
and the silent state entering module is used for replacing the true random address corresponding to the local computer with the internal networking address and entering a silent state of the slave computer.
A computer device comprises a memory, a processor and a computer program which is stored in the memory and can run on the processor, and the RS485 communication-based ad hoc network method is realized when the computer program is executed by the processor.
A computer readable medium, which stores a computer program, and when the computer program is executed by a processor, the RS485 communication-based ad hoc network method is implemented.
According to the RS485 communication-based ad hoc network method, the RS485 communication-based ad hoc network device, the networking broadcast instruction is sent to the network through the host, the multiple slave ends can generate the true random addresses based on the address range and send the true random addresses to the host, the host can sequentially match the internal networking addresses with the slave ends according to the true random addresses, automatic allocation of the slave addresses is achieved, communication ad hoc network is achieved, manual setting of fixed addresses is not needed, and intelligence and automatic expandability of the RS485 networking are improved.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings needed to be used in the description of the embodiments of the present invention will be briefly introduced below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and it is obvious for those skilled in the art that other drawings can be obtained according to these drawings without inventive labor.
FIG. 1 is a schematic diagram illustrating an application environment of an Ad hoc network based on RS485 communication according to an embodiment of the present invention;
FIG. 2 is a flowchart illustrating an Ad hoc network based on RS485 communication according to an embodiment of the present invention;
FIG. 3 is a first flowchart illustrating an Ad hoc network based on RS485 communication according to an embodiment of the present invention;
FIG. 4 is a second flowchart of an Ad hoc network based on RS485 communication according to an embodiment of the present invention;
FIG. 5 is a schematic diagram illustrating a first round of address assignment timing sequence in an Ad hoc network based on RS485 communication according to an embodiment of the present invention;
FIG. 6 is a third flowchart illustrating an Ad hoc network based on RS485 communication according to an embodiment of the present invention;
FIG. 7 is a diagram illustrating an exemplary flowchart of a host end in an Ad hoc network based on RS485 communication according to an embodiment of the present invention;
FIG. 8 is a diagram illustrating an exemplary flow of a slave end in an Ad hoc network based on RS485 communication according to an embodiment of the present invention;
FIG. 9 is a schematic diagram illustrating an Ad hoc network device based on RS485 communication according to an embodiment of the invention;
FIG. 10 is a diagram illustrating a computer device according to an embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
RS485 is a standard defined to balance the electrical characteristics of drivers and receivers in digital multipoint systems, defined by the telecommunications industry association and the electronics industry consortium. Digital communication networks using this standard can efficiently transmit signals in remote and electronically noisy environments. RS-485 enables a configuration that connects the local network and the multi-drop communication link. RS485 mainly adopts a two-wire system wiring mode. The wiring mode is a bus topology, and at most 32 nodes can be connected on the same bus. In the RS485 communication network, a master-slave communication mode is generally adopted, that is, a master has a plurality of slaves. The RS485 communication speed is high, and the maximum transmission speed can reach more than 10 Mb/s.
RS485 Communication is a Half duplex (Half duplex Communication) mode of operation, which means that at any time during the Communication process, information can be transmitted from a to B and from B to a, but only transmission in one direction exists. When the half-duplex mode is adopted, the transmitter and the receiver at each end of the communication system are switched to the communication line through the receiving/transmitting switch to switch the direction, and time delay is generated.
RS485 master-slave multi-machine communication protocol (data transmission protocol): this protocol defines a message structure that a controller can recognize as being used regardless of the network over which they communicate. It describes the process of a controller requesting access to other devices, how to respond to requests from other devices, and how to detect errors and log them. This protocol determines what action each controller needs to know the slave's artificially set device address, recognize messages sent from the address, and determine what action to take place. If a response is required, the controller generates feedback information and sends the feedback information according to the protocol. The master device can communicate with the slave devices individually or in a broadcast manner.
The communication mode between the master device and the slave device is based on the situation that the master device should know the communication address of the slave device in advance, so that the network expansion is not facilitated, or the address conflict of the slave device may occur. In this embodiment, based on the foregoing problems, an ad hoc network method based on RS485 communication is provided in an embodiment of the present invention, and can be applied in an application environment as shown in fig. 1, where the ad hoc network method based on RS485 communication is applied in an ad hoc network system based on RS485 communication, and the ad hoc network system based on RS485 communication includes a host end and a plurality of slave ends, where the host end communicates with the plurality of slave ends, such as a sensor, through a network.
The self-networking method based on RS485 communication comprises the following steps executed by a host side:
and sending networking broadcast instructions to the network, wherein the networking broadcast instructions are used for generating true random addresses by a plurality of slave computers based on the networking broadcast instructions.
And receiving a slave instruction response data packet which carries a true random address and is returned by the target slave end, and caching the slave instruction response data packet.
And matching an internal networking address for the target slave terminal based on the true random address corresponding to the slave instruction response data packet and the data packet arrival sequence within the longest delay waiting time limit.
And sending a modified address instruction carrying an internal networking address to the target slave end so that the target slave end replaces the corresponding true random address with the internal networking address.
And when the current time of the system meets the maximum delay waiting time limit, the step of sending the networking broadcast instruction to the network is repeatedly executed until the continuous times of receiving the slave instruction response data packets returned by any slave end meet the maximum waiting times, and the network ad hoc network is completed.
The self-networking method based on RS485 communication further comprises the following steps executed from the slave end:
and receiving a networking broadcast instruction sent by a host computer on the network.
Generating a true random address based on the networking broadcast instruction, and generating a random delay time based on the true random address.
And after delaying according to the random delay time, returning a slave instruction response data packet carrying a true random address to the host end.
And receiving a modified address instruction which is sent by the host and carries an internal networking address.
And replacing the true random address corresponding to the local machine with an internal networking address, and entering a slave silent state.
In an embodiment, as shown in fig. 2, an ad hoc network method based on RS485 communication is provided, which is described by taking an example that the method is applied to a host end and a slave end in fig. 1, and specifically includes the following steps:
s11, a host side sends a networking broadcast instruction to a network, and the networking broadcast instruction is used for generating true random addresses by a plurality of slave sides based on the networking broadcast instruction.
The networking broadcast instruction is sent from a host to a network, and each slave can receive the instruction for generating the true random address. The true random instruction is obtained by the slave terminal through address matching according to the address range sent by the host terminal.
Specifically, the present embodiment may adopt a baud rate of 115200bps and a half-duplex operating mode, where communication is initiated by the upper computer and the lower computer responds. The number of bits representing the address is set to eight, so that the network can accommodate 256 nodes, and all slave addresses are zero when the system is powered on. At this time, the master limits the address range corresponding to the assignable slave at the slave end to be 1-240, and the slave can match an address from the range randomly as an eight-bit true random address corresponding to the slave in the network.
The address range is set by the host side according to the number of nodes that can be accommodated in the network, and for example, if a maximum of 256 nodes are accommodated in the network, the address range of the slave side can be set as follows: 0 to 240, setting the address range of the host and the bus monitoring unit as follows: 241 to 255. Further, the address range further includes a number of bits for representing the address, and in this embodiment, the number of bits for representing the address may be set to eight bits.
The host end sends the networking broadcast instruction to the slave end, and the following communication data packet format can be adopted:
Figure BDA0003807111800000051
the three items of "destination address", "source address" and "instruction" are the objects mainly used in the present embodiment. The source address is an address corresponding to a host end sent by the data packet, the target address is an address corresponding to a slave end receiving the data packet, and the instruction is used for loading the networking broadcast sending instruction and explaining the function and the type of the data packet. It is understood that the above communication data packet format can be modified according to actual requirements.
The method for generating the true random range provided by the embodiment is beneficial to dynamically setting the node size according to the network node size by the host, and timely adjusting the address range corresponding to the slave without manually setting the address range from the slave end, so that the dynamic property and the centralized control property of the network set address range are improved.
And S21, receiving a networking broadcast instruction sent by a host computer on the network from the slave computer.
Specifically, the slave side can receive various broadcast instructions sent by the host side in time in a network monitoring state, for example, networking broadcast instructions for networking and generating a true random address.
And S22, generating a true random address from the slave terminal based on the networking broadcast instruction, and generating random delay time based on the true random address.
The random delay time is the waiting time after the slave terminal generates the true random address, and the true random address is returned to the host terminal after the waiting time is met, so that the host terminal can distinguish the true random addresses returned by different slave terminals, and address validity judgment is carried out based on different true random addresses.
Specifically, the slave may use a multiple of a numerical value corresponding to the eight true random addresses, and in this embodiment, two times may be used as the delay time, unit: ms. Such as: and the generated true random address is 10, the delay time is 20ms.
And S23, after delaying according to the random delay time, the slave machine end returns a slave machine instruction response data packet carrying a true random address to the host machine end.
The slave instruction response data packet is a data packet which is returned from a networking broadcast instruction sent by the slave base on the host side and comprises a true random address. The slave end may load the slave instruction response packet by referring to the communication packet format adopted by the host end, which is not described herein again.
Specifically, the slave end returns a slave command response packet to the host end, which also indicates that the slave end is still in an unaddressed state and needs to be confirmed by the host end. All the slave terminals take the received networking broadcast instruction of the host terminal as a time starting point, and delay to send a slave instruction response data packet to the host terminal according to the respective generated random delay time. The "source address" in the slave command reply packet uses an eight-bit true random address.
And S12, the host end receives a slave instruction response data packet which is returned by the target slave end and carries a true random address, and caches the slave instruction response data packet.
Specifically, the host continuously receives response packets sent by the target slave and stores the response packets in a buffer for subsequent centralized processing.
And S13, the host side matches an internal networking address with the target slave side based on a true random address corresponding to the slave instruction response data packet and a data packet arrival sequence within the longest delay waiting time limit.
The longest delay waiting time limit is the longest time for the master end to wait for receiving the slave instruction response data packet returned by the slave end every time. The longest latency time limit is set based on the longest random latency time, i.e. the longest latency time limit should be larger than the longest random latency time. For example, if the address of the slave is 240 and the random delay time is 480ms, the longest delay waiting time limit may be set to 500ms in this embodiment.
Specifically, after the duration of 500ms ends, the host stops receiving the data packets and extracts the correct data packets in the buffer. And based on the receiving time, that is, the receiving order, of each slave instruction response data packet as an arrival order, resetting the internal networking address for the slave end in sequence, for example, resetting the address of the slave end with the original address of 122 that the first bit arrives at as the internal networking address 122-1, that is, resetting the address of the slave end with 122 as the internal networking address 1, and incrementing the address of the internal networking of the second bit by 1.
After the slave receives the networking instruction from the host, the generated eight-bit random address must be a true random address. The range of the number of the slave side address is 1 to 240. And (3) the delay time of sending the networking instruction response data packet by each slave terminal is =2 × random address, and the maximum delay time is 480ms. The shortest time interval for sending the networking response data packet by the two slave terminals generating different true random addresses is 2ms, and the longest time interval is 478ms. The communication baud rate is 115200, the length of the data packet is 12 bytes, and the slave end needs 1.042ms to send the response data packet. The slave end needs to respond to the host networking data packet in real time, and response delay is within 500 us.
S14, the host side sends a modification address instruction carrying an internal networking address to the target slave side, so that the target slave side replaces the corresponding true random address with the internal networking address.
The modification address instruction is an instruction for informing a target slave end to modify an original true random address into an internal networking address by a host end.
Specifically, the master end modifies the slave instructions to modify the true random addresses of the slaves corresponding to the sequenced slave instruction response data packets into the internal networking addresses in sequence.
And S24, receiving a modified address instruction carrying an internal networking address sent by the host side from the slave side.
S25, the slave terminal replaces the true random address corresponding to the local machine with the internal networking address and enters a slave silent state.
Specifically, after receiving the address modification instruction data packet, the slave side updates its own address and replies to the host side, and the internal networking address corresponding to the slave side is successfully allocated. Then the slave computer enters a slave computer silent state, does not respond to the address modification command sent by the host computer any more, and only responds to the 'all slave computer networking command' and the 'networking finishing command' sent by the host computer.
In the networking process, the slave machine end (including the slave machine end with the address allocated in the last networking) which has already allocated the address does not respond to other instructions sent by the host machine end except the instructions of 'all slave machines responding to networking' and 'networking ending instruction' sent by the host machine end, and the normal operation is recovered after the networking is ended.
And S15, when the current time of the system meets the maximum delay waiting time limit, the host repeatedly executes the step of sending the networking broadcast instruction to the network until the continuous times of receiving no slave instruction response data packet returned by any slave end meet the maximum waiting times, and then the network self-networking is completed.
For example, the host end cannot receive any complete and correct slave instruction response data packet returned by the slave end for five times, and the host end can end the networking polling to complete the networking of the network ad hoc network, that is, no new internal networking address is allocated to any slave end.
Specifically, after the host end sends the networking instruction data packet, the host end enters a receiving state, receives the data packet sent by the slave end, stores the data packet in a buffer area, analyzes the data packet in the buffer area after the duration lasts for 500ms, the complete and correct data packet is the slave end which randomly generates the unique true random address, and the wrong data packet is discarded. The host can communicate with the slave which generates the unique address independently, then the host terminal redistributes the address to the slave terminal, and the address dereferencing uses the sequencing serial number of the received slave terminal correct data packet.
After the host end waits for 500ms each time, the process returns to step S11 to perform the next round of address allocation. And until the master computer receives no complete and correct slave computer response data packet within 500ms after the master computer sends the networking broadcast command in a broadcast mode. And returning to the step S11 to repeat the execution of the maximum waiting time, which is reduced by one, for example, if none of the complete and correct slave instruction response data packets replied by the slave is received for five times, the host may broadcast and send a "networking end" instruction data packet, thereby completing the networking.
The host computer end uses the reading equipment information instruction data packet according to the distributed internal networking address corresponding to the slave computer end, sequentially reads the 'unique identification code' of the slave computer end, and establishes the real corresponding relation between the internal networking address and the slave computer end.
According to the RS485 communication-based ad hoc network method provided by the embodiment, the host end sends a networking broadcast instruction to the network, the multiple slave ends can generate true random addresses based on address ranges and send the true random addresses to the host end, the host end can sequentially match internal networking addresses with the slave ends according to the true random addresses, the automatic allocation of slave addresses is achieved, namely, communication ad hoc network is achieved, manual setting of fixed addresses is not needed, and the intelligence and automatic expandability of the RS485 networking are improved.
In a specific embodiment, as shown in fig. 3, in S11, that is, in sending the network broadcast instruction to the network, the method specifically includes the following steps:
and S111, the host side acquires the networking state.
And S112, if the networking state is a full response state, the host side sends an initial networking broadcast instruction of all slave computers needing to respond to the networking to the network, and the address range comprises all available addresses.
And S113, if the networking state is a partial response state, the host end sends a re-networking broadcast instruction of partial slave machines needing to respond to the networking to the network, and the address range comprises the remaining available addresses.
The all-response state is the state when the host sends a networking broadcast instruction for the first time when starting a new round of internal address allocation polling, and at this time, the host needs to wait for slave instruction response data packets returned by all the slave terminals.
The partial response state is the state of the master end in the second and later times of new networking polling, and at this time, only part of the slave ends in the network need to respond to the second and later-issued re-networking broadcast instructions, and at this time, the master end only needs to wait for a part of slave instruction response data packets returned by the slave ends.
The remaining available addresses are those remaining in the range of addresses used by the previous poll.
Specifically, the host end broadcasts and sends an initial networking broadcast instruction, the first round of the networking process uses all networking instructions responded by the slave end, the second round and the later rounds use the slave end which is not allocated with addresses to respond to the networking instructions, and then the state of receiving the response data packet of the slave end is entered.
The ad hoc network command data packet sent by the upper computer is divided into two types, one type is 'all slave response networking', and the other type is 'slave response networking without address allocation'.
Initial networking broadcast instruction: the command is executed when the host-side software starts to run, or the host-side software user actively executes, and the networking process is in a first round state, and all slave terminals respond to the networking command at the moment.
Networking again and broadcasting the instruction: the command is executed when the host computer terminal conducts the second round networking and the back round networking, or the host computer terminal software user actively executes the command, at the moment, the slave computer terminal which is not allocated with the address responds to the networking command, and the slave computer terminal which is allocated with the address does not respond. For a system which is successfully networked normally, when a new slave terminal is added, the command can be used for enabling the newly added slave terminal to carry out local networking without influencing the slave terminal which is added into the network.
In the method provided by this embodiment, the master end may determine, through the networking state, the number of slave instruction response packets returned from the receiving slave end, so as to flexibly set the waiting time without waiting for the delay time returned by all the slave ends each time.
In a specific embodiment, as shown in fig. 4, in S13, that is, matching the internal networking address to the target slave end in the true random address corresponding to the slave instruction reply packet and the packet arrival order, the method specifically includes the following steps:
s131, the host side determines the validity of the true random address.
And S132, if the true random address meets the legality, the host end extracts the data packet arrival sequence of the true random address, and the data packet arrival sequence is used as an internal networking address.
In particular, the legitimacy of a truly random address includes the uniqueness and correctness of the address. Only if the addresses returned by the two slave terminals are not repeated and no data error exists, the host terminal considers that the slave terminals return effective true random addresses, and then the internal networking addresses are allocated to the slave terminals corresponding to the legal true random addresses.
Each complete correct slave command response data packet indicates that the slave end is not interfered by other slave ends in the process of sending the data packet, the slave end has uniqueness in the time delay of sending data, and the generated eight-bit true random address has uniqueness.
For example, as shown in fig. 5, fig. 5 is a schematic diagram of a first round address allocation timing sequence in an ad hoc network process. The host sends a command of 'all slave responses networking', and after all the slave receives the command data packet, 8-bit true random number addresses are generated, and the address range is (1-240).
The slave machine uses twice the true random number 8-bit address value as the delay time, unit: ms.
All the slave machines take the received ad hoc network command data packet of the upper computer as a time starting point, and delay to send ad hoc network command response data packets to the host machine according to the random delay time generated by each slave machine. The "source address" in the slave reply packet uses the generated 8-bit true random number address.
As can be seen from the figure, since the slaves 2, 5, and 8 do not collide with other slaves when transmitting data packets, the master receives the complete and correct data packets transmitted from the slaves 2, 5, and 8, and the slaves 2, 5, and 8 are successfully allocated in the present round of address allocation.
The slave 4 and the slave 10, the slave 1, the slave 3, the slave 9, and the slave 6 and the slave 7 all collide when sending data packets, so that the master cannot receive complete and correct data packets, and the slave 4, 10,1,3,9,6,7 fails to be allocated in the address allocation of the current round, and enters the next round of address allocation.
In a specific embodiment, in S15, that is, before the step of repeatedly executing the step of sending the networking broadcast instruction to the network when the current time of the system satisfies the longest latency time limit, the method further specifically includes the following steps:
s150, the host end stores the maximum internal networking address, and is used for adding one to the maximum internal networking address to serve as the initial value of the internal networking address of the next-round networking.
Specifically, after the host end processes all the data packets in the buffer sequentially, the sorting address of the last data packet is saved, and the address is added by one in the next round of address allocation to serve as the initial value of the sorting address.
In a specific embodiment, as shown in fig. 6, in S25, that is, after entering the slave silent state, the method further specifically includes the following steps:
and S251, the slave terminal receives a networking ending broadcast instruction or an initial networking broadcast instruction sent by the host terminal.
And S252, the slave terminal enters a network monitoring state.
The network listening state is a state in which the slave receives a broadcast command sent by the host.
Specifically, the slave end receives a broadcast instruction of networking end sent by the host end broadcast, or receives an initial networking broadcast instruction, which indicates that the address allocation of the current round is ended or a new round of address allocation is restarted.
In the ad hoc network method based on RS485 communication provided in this embodiment, as shown in fig. 7, a diagram of a full flow example of a host end in the ad hoc network method based on RS485 communication is shown, where a FailCnt: not receiving the correct packet state count; fig. 8 is a diagram showing a full flow example of a slave side in an ad hoc network method based on RS485 communication, wherein DevAddr is a local address, setAddrFlag is an address assignment status flag. 0: unallocated and 1: allocated. The ad-hoc network method based on RS485 communication provided in this embodiment sends a networking broadcast instruction to a network through a host side, multiple slave sides can generate a true random address based on an address range and send the true random address to the host side, and the host side can match an internal networking address with the slave sides in sequence according to the true random address, so as to realize automatic allocation of slave addresses, that is, realize communication ad-hoc network, and improve intelligence and automatic expandability of the RS485 networking without manually setting a fixed address.
In an embodiment, an ad hoc network device based on RS485 communication is provided, and the ad hoc network device based on RS485 communication corresponds to the ad hoc network method based on RS485 communication in the above embodiments one to one. As shown in fig. 9, the host 10 in the ad hoc network device based on RS485 communication includes a broadcast networking instruction sending module 11, a cache response data packet module 12, an internal networking address matching module 13, an address modification sending module 14, and a network ad hoc networking completion module 15. The functional modules are explained in detail as follows:
and the broadcast networking instruction sending module 11 is configured to send a networking broadcast instruction to a network, and is configured to generate true random addresses by the multiple slave terminals based on the networking broadcast instruction.
And the cache response data packet module 12 is configured to receive a slave instruction response data packet carrying a true random address and returned by the target slave end, and cache the slave instruction response data packet.
And the matching internal networking address module 13 is used for matching an internal networking address for the target slave end based on the true random address corresponding to the slave instruction response data packet and the data packet arrival sequence within the longest delay waiting time limit.
And the address modification instruction sending module 14 is configured to send an address modification instruction carrying an internal networking address to the target slave, so that the target slave replaces the corresponding true random address with the internal networking address.
And a network ad hoc networking completion module 15, configured to repeatedly execute the step of sending a networking broadcast instruction to the network when the current time of the system meets the maximum delay latency time limit, and complete network ad hoc networking until the number of consecutive times that no slave instruction response data packet returned by any slave terminal is received meets the maximum latency time.
In an embodiment, an ad hoc network device based on RS485 communication is provided, and the ad hoc network device based on RS485 communication corresponds to the ad hoc network method based on RS485 communication in the above embodiments one to one. The slave terminal 20 in the ad hoc network device based on RS485 communication includes a broadcast receiving instruction module 21, a true random address generating module 22, a response returning data packet module 23, an address receiving and modifying instruction module 24, and a silence entering module 25. The detailed description of each functional module is as follows: a broadcast instruction receiving module 21, configured to receive a networking broadcast instruction sent by a host on a network.
And a true random address generating module 22, configured to generate a true random address based on the networking broadcast instruction, and generate a random delay time based on the true random address.
And the response packet returning module 23 is configured to return a slave instruction response packet carrying a true random address to the host after delaying according to the random delay time.
And the address modification instruction receiving module 24 is configured to receive an address modification instruction carrying an internal networking address and sent by a host.
And entering a silent state module 25, configured to replace the true random address corresponding to the local computer with an internal networking address, and entering a slave silent state.
Specific limitations on the ad-hoc network device based on RS485 communication can be referred to the above limitations on the ad-hoc network method based on RS485 communication, and are not described herein again. The modules in the ad-hoc network device based on RS485 communication may be wholly or partially implemented by software, hardware and a combination thereof. The modules can be embedded in a hardware form or independent from a processor in the computer device, and can also be stored in a memory in the computer device in a software form, so that the processor can call and execute operations corresponding to the modules.
In one embodiment, a computer device is provided, which may be a server, and its internal structure diagram may be as shown in fig. 10. The computer device includes a processor, a memory, a network interface, and a database connected by a system bus. Wherein the processor of the computer device is configured to provide computing and control capabilities. The memory of the computer device includes a non-volatile medium, an internal memory. The non-volatile medium stores an operating system, a computer program, and a database. The internal memory provides an environment for the operating system and the computer programs in the non-volatile medium to run. The database of the computer equipment is used for storing data to be stored in the self-networking method based on RS485 communication. The network interface of the computer device is used for communicating with an external terminal through a network connection. The computer program is executed by a processor to implement an ad-hoc network method based on RS485 communication.
In an embodiment, a computer device is provided, which includes a memory, a processor, and a computer program stored on the memory and executable on the processor, and when the processor executes the computer program, the RS485 communication-based ad hoc networking method of the above embodiments is implemented, for example, S11 to S25 shown in fig. 2. Alternatively, the processor, when executing the computer program, implements the functions of the modules/units of the ad hoc network device based on RS485 communication in the above embodiments, such as the functions of the modules 11 to 25 shown in fig. 9. To avoid repetition, further description is omitted here.
In an embodiment, a computer readable medium is provided, on which a computer program is stored, and the computer program is executed by a processor to implement the ad-hoc network method based on RS485 communication in the above embodiments, or the computer program is executed by the processor to implement the functions of the modules/units in the ad-hoc network device based on RS485 communication in the above embodiments of the device. To avoid repetition, further description is omitted here.
It will be understood by those skilled in the art that all or part of the processes of the methods of the embodiments described above can be implemented by hardware instructions of a computer program, which can be stored in a non-volatile computer-readable medium, and when executed, can include the processes of the embodiments of the methods described above. Any reference to memory, storage, database, or other medium used in the embodiments provided herein may include non-volatile and/or volatile memory, among others. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically Programmable ROM (EPROM), electrically Erasable Programmable ROM (EEPROM), or flash memory. Volatile memory can include Random Access Memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in a variety of forms such as Static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double Data Rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous Link DRAM (SLDRAM), rambus (Rambus) direct RAM (RDRAM), direct Rambus Dynamic RAM (DRDRAM), and Rambus Dynamic RAM (RDRAM), among others.
It should be clear to those skilled in the art that, for convenience and simplicity of description, the foregoing division of the functional units and modules is only used for illustration, and in practical applications, the above function distribution may be performed by different functional units and modules as needed, that is, the internal structure of the apparatus may be divided into different functional units or modules to perform all or part of the above described functions.
The above examples are only intended to illustrate the technical solution of the present invention, and not to limit it; although the present invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; such modifications and substitutions do not depart from the spirit and scope of the embodiments of the present invention, and they should be construed as being included therein.

Claims (10)

1. An RS485 communication-based ad hoc network method is applied to a host side and is characterized by comprising the following steps:
sending a networking broadcast instruction to a network, wherein the networking broadcast instruction is used for generating true random addresses by a plurality of slave computers based on the networking broadcast instruction;
receiving a slave computer instruction response data packet which carries a true random address and is returned by a target slave computer end, and caching the slave computer instruction response data packet;
matching an internal networking address for the target slave machine end based on the true random address corresponding to the slave machine instruction response data packet and the data packet arrival sequence within the longest delay waiting time limit;
sending a modified address instruction carrying the internal networking address to the target slave end so that the target slave end replaces the corresponding true random address with the internal networking address;
and when the current time of the system meets the longest delay waiting time limit, the step of sending the networking broadcast instruction to the network is repeatedly executed until the continuous times of receiving no slave instruction response data packet returned by any slave end meet the maximum waiting times, and the network self-networking is completed.
2. The ad-hoc network method based on RS485 communication of claim 1, wherein the sending a networking broadcast command to the network comprises:
acquiring a networking state;
if the networking state is a full response state, sending an initial networking broadcast instruction of all slave computers needing to respond to the networking to the network, wherein the address range comprises all available addresses;
and if the networking state is a partial response state, sending a re-networking broadcast instruction of partial slave computers needing to respond to the networking to the network, wherein the address range comprises the rest available addresses.
3. The RS485 communication based ad hoc network method according to claim 1, wherein said matching an internal networking address to said target slave side based on said true random address and packet arrival order corresponding to said slave command reply packet comprises:
determining the validity of the true random address;
and if the true random address meets the legality, extracting the data packet arrival sequence of the true random address, and taking the data packet arrival sequence as the internal networking address.
4. The RS485 communication based ad-hoc network method according to claim 1, wherein before the step of repeatedly executing the step of sending the networking broadcast command to the network when the current time of the system satisfies the longest latency time limit, further comprising:
and saving the maximum internal networking address, and adding one to the maximum internal networking address to serve as an initial value of the internal networking address of the lower-wheel networking.
5. An ad-hoc network method based on RS485 communication is applied to a slave terminal, and is characterized by comprising the following steps:
receiving a networking broadcast instruction sent by a host computer on a network;
generating a true random address based on the networking broadcast instruction, and generating random delay time based on the true random address;
after delaying according to the random delay time, returning a slave instruction response data packet carrying the true random address to the host end;
receiving a modified address instruction which is sent by the host and carries an internal networking address;
and replacing the true random address corresponding to the local machine with the internal networking address, and entering a slave silent state.
6. The RS485 communication based ad hoc network method according to claim 5, wherein after said entering slave silent state, further comprising:
receiving a networking ending broadcast instruction or an initial networking broadcast instruction sent by the host end;
and entering a network monitoring state.
7. The utility model provides an from network deployment device based on RS485 communication which characterized in that, includes the host computer end, the host computer end includes:
the network-networking-instruction-sending module is used for sending a network-networking broadcast instruction to a network and generating true random addresses by a plurality of slave computers based on the network-networking broadcast instruction;
the cache response data packet module is used for receiving a slave machine instruction response data packet which is returned by the target slave machine end and carries a true random address, and caching the slave machine instruction response data packet;
the matched internal networking address module is used for matching an internal networking address for the target slave terminal based on the true random address corresponding to the slave instruction response data packet and the data packet arrival sequence within the longest delay waiting time limit;
a modified address sending instruction module, configured to send a modified address instruction carrying the internal networking address to the target slave end, so that the target slave end replaces the corresponding true random address with the internal networking address;
and the network self-networking completion module is used for repeatedly executing the step of sending the networking broadcast instruction to the network when the current time of the system meets the longest delay waiting time limit until the continuous times of receiving no slave instruction response data packets returned by any slave end meet the maximum waiting times, and then completing the network self-networking.
8. An ad-hoc network device based on RS485 communication, comprising a slave end, wherein the slave end comprises:
the broadcast instruction receiving module is used for receiving a networking broadcast instruction sent by a host computer on a network;
the real random address generating module is used for generating a real random address based on the networking broadcasting instruction and generating random delay time based on the real random address;
the return response data packet module is used for returning a slave instruction response data packet carrying the true random address to the host end after delaying according to the random delay time;
the receiving and modifying address instruction module is used for receiving a modifying address instruction which is sent by the host end and carries an internal networking address;
and the silent state entering module is used for replacing the true random address corresponding to the local computer with the internal networking address and entering a slave silent state.
9. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor implements the RS485 communication based ad hoc network method according to any one of claims 1 to 4 when executing the computer program, or wherein the processor implements the RS485 communication based ad hoc network method according to any one of claims 5 to 6 when executing the computer program.
10. A computer-readable medium, in which a computer program is stored, which, when being executed by a processor, implements the RS485 communication based ad hoc network method according to any one of claims 1 to 4, or which, when being executed by a processor, implements the RS485 communication based ad hoc network method according to any one of claims 5 to 6.
CN202211000068.0A 2022-08-19 2022-08-19 Self-networking method and device based on RS485 communication, computer equipment and medium Pending CN115442333A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211000068.0A CN115442333A (en) 2022-08-19 2022-08-19 Self-networking method and device based on RS485 communication, computer equipment and medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211000068.0A CN115442333A (en) 2022-08-19 2022-08-19 Self-networking method and device based on RS485 communication, computer equipment and medium

Publications (1)

Publication Number Publication Date
CN115442333A true CN115442333A (en) 2022-12-06

Family

ID=84242476

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211000068.0A Pending CN115442333A (en) 2022-08-19 2022-08-19 Self-networking method and device based on RS485 communication, computer equipment and medium

Country Status (1)

Country Link
CN (1) CN115442333A (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116389505A (en) * 2023-03-29 2023-07-04 上海正泰智能科技有限公司 Networking method based on CAN bus and computer equipment
CN116723176A (en) * 2023-08-11 2023-09-08 广东云驰时代技术有限公司 Continuous addressing communication method, system, computer device and storage medium
CN117255322A (en) * 2023-09-15 2023-12-19 江苏果下科技有限公司 Wireless ad hoc network method and system based on energy storage battery

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2003143157A (en) * 2001-11-05 2003-05-16 Toshiba Kyaria Kk Communication system, master, slave, mac address server, and communication method
WO2018113432A1 (en) * 2016-12-24 2018-06-28 华为技术有限公司 Broadcast realisation method, apparatus and device
CN113114793A (en) * 2021-03-22 2021-07-13 珠海格力电器股份有限公司 Slave node address competition method and device and electrical appliance system

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2003143157A (en) * 2001-11-05 2003-05-16 Toshiba Kyaria Kk Communication system, master, slave, mac address server, and communication method
WO2018113432A1 (en) * 2016-12-24 2018-06-28 华为技术有限公司 Broadcast realisation method, apparatus and device
CN113114793A (en) * 2021-03-22 2021-07-13 珠海格力电器股份有限公司 Slave node address competition method and device and electrical appliance system

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116389505A (en) * 2023-03-29 2023-07-04 上海正泰智能科技有限公司 Networking method based on CAN bus and computer equipment
CN116723176A (en) * 2023-08-11 2023-09-08 广东云驰时代技术有限公司 Continuous addressing communication method, system, computer device and storage medium
CN116723176B (en) * 2023-08-11 2023-10-20 广东云驰时代技术有限公司 Continuous addressing communication method, system, computer device and storage medium
CN117255322A (en) * 2023-09-15 2023-12-19 江苏果下科技有限公司 Wireless ad hoc network method and system based on energy storage battery

Similar Documents

Publication Publication Date Title
CN115442333A (en) Self-networking method and device based on RS485 communication, computer equipment and medium
US10204072B2 (en) Method for automatically allocating addresses to similar bus users
US4423414A (en) System and method for name-lookup in a local area network data communication system
US4410889A (en) System and method for synchronizing variable-length messages in a local area network data communication system
EP0074865A2 (en) Expandable and contractible local area network system
CN103856578B (en) The automatic acquisition station address approach of Modbus RTU slave stations and slave station
CN103716420A (en) Automatic station address obtaining method of Modbus ASCII slave station and slave station
KR20130053650A (en) Method and apparatus for transmitting data in a device to device communition service system
CN112165733B (en) Method and system for building point-to-point multichannel network of private protocol
CN112565349B (en) Wireless communication method based on central range hood and related equipment
CN110708400B (en) Network address allocation method, device, node equipment and storage medium
CN115314470A (en) RS-485 networking communication address automatic allocation method, host, slave and system
US10848419B2 (en) Data transmission method, communication network and master participant
CN114500472B (en) Method for automatically distributing RS485 communication address
CN107025131B (en) Task scheduling method and device
CN112929249A (en) RS-485 bus multi-machine communication address automatic allocation method, device and system
CN111182611A (en) Communication method and device
US7539215B2 (en) Subscriber device for a high-performance communication system
CN113938351A (en) Data acquisition method, system and computer readable storage medium
JP2004280304A (en) Field bus system, communication method and master/ slave
CN107318128B (en) Wireless communication optimization method, device, storage medium and computer equipment thereof
CN114868371A (en) Data collection management device and data collection system
CN107968718B (en) Method, device and equipment for confirming main standby state
CN115334041A (en) Method for automatically allocating addresses to communication equipment of master station and slave station, master station, slave station and system
US11528348B2 (en) Communication system, communication device, communication method, and program for reliably receiving periodic data

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