CN110505319A - A kind of RS485 is from device address auto-allocation method and system - Google Patents

A kind of RS485 is from device address auto-allocation method and system Download PDF

Info

Publication number
CN110505319A
CN110505319A CN201910724108.8A CN201910724108A CN110505319A CN 110505319 A CN110505319 A CN 110505319A CN 201910724108 A CN201910724108 A CN 201910724108A CN 110505319 A CN110505319 A CN 110505319A
Authority
CN
China
Prior art keywords
equipment
address
temporary
temporary address
response message
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
CN201910724108.8A
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.)
Jinling Institute of Technology
Original Assignee
Jinling Institute of Technology
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 Jinling Institute of Technology filed Critical Jinling Institute of Technology
Priority to CN201910724108.8A priority Critical patent/CN110505319A/en
Publication of CN110505319A publication Critical patent/CN110505319A/en
Pending legal-status Critical Current

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L61/00Network arrangements, protocols or services for addressing or naming
    • H04L61/50Address allocation
    • H04L61/5038Address allocation for local use, e.g. in LAN or USB networks, or in a controller area network [CAN]

Abstract

The invention discloses a kind of RS485 from device address auto-allocation method and system, and method includes: to generate temporary address when initializing from device power, and set pre-assignment of addresses state for equipment state;Main equipment broadcasts from equipment according to predetermined period and finds to instruct;If being pre-assignment of addresses state from the equipment state of equipment, receive from equipment and find to instruct, and includes the response message of temporary address to main equipment transmission;Whether main equipment receives the response message from equipment, detect occupied from the temporary address of equipment in response message, and sends address setting command to from equipment according to testing result;Address setting command is received from equipment, parse actual address and temporary address, if temporary address in the setting command of address and being matched from the temporary address of equipment, set actual address to from the address of equipment, and will be revised as having distributed address state from the equipment state of equipment.Using preceding method, the address allocative efficiency from equipment can be greatly promoted.

Description

A kind of RS485 is from device address auto-allocation method and system
Technical field
The present invention relates to RS485 bus address distribution field more particularly to a kind of RS485 from the device address side of distribution automatically Method and system.
Background technique
RS485 bus has many advantages, such as that simple circuit design, high reliablity, strong antijamming capability, transmission range are long, wide It is general to be applied in the fields such as industrial field control, Internet of Things, multi-point and lon g-distance monitoring.The characteristic requirements of RS485 master-slave communication from Equipment will be provided with unique device identification, i.e. device address.
Traditional setting RS485 has two methods of hardware setting and software setting from device address.Hardware setting, each RS485 has a toggle switch from equipment, and device address is arranged using toggle switch in user, in order to prevent the reasons pair such as external force The value of toggle switch impacts, and the toggle switch of usual equipment exposed outside will not make that address is arranged in this way, needs Want detaching equipment that could use toggle switch.Software setting usually uses PC software transmitting order to lower levels setting address one by one, this Setting method is comparatively laborious, and difficulty is larger for layman.When more from equipment in system, no matter hardware is used Or software is arranged from device address, all be easy to cause the duplicate mistake in the address of setting.
Based on above drawback, industry also proposed several methods for solving to distribute automatically from device address, specifically include that
1, an arbitration line is added on the basis of original RS485 is connected to the network, and is chosen by arbitration line from equipment Address distribution is carried out to from equipment.In this method, due to increasing an arbitration line, RS485 bus is made to lose two wires biography Defeated advantage really implements relatively difficult.
2, using the distribution method from equipment active probe, actively issued after equipment starting probe message to other from It stands, before obtaining free address, continuous always can attempt to use different addresses as probe message.This method is from setting The standby process time-consuming for obtaining free address is too long, and address allocative efficiency is low.
Summary of the invention
The present invention provides a kind of RS485 from device address auto-allocation method and system, existing from equipment to solve In address distribution method, is chosen by arbitration line from equipment and carry out address distribution to from equipment, or used from equipment master The address distribution method of dynamic detection, causes RS485 bus to lose the advantage of two wires transmission, really implement it is relatively difficult with And this low problem of address allocative efficiency.
In a first aspect, the embodiment of the present invention provides a kind of RS485 from device address auto-allocation method, the method packet It includes:
Step 1, temporary address is generated from equipment, and is set as pre-assignment of addresses shape from the equipment state of equipment for described State;
Step 2, main equipment broadcasts from equipment according to predetermined period and finds to instruct;
Step 3, if it is described from the equipment state of equipment be pre-assignment of addresses state, it is described from equipment receive from equipment find Response message is sent to main equipment after instruction, the response message includes from the temporary address of equipment;
Step 4, the main equipment receives the response message from equipment, detects in the response message from equipment provisionally Whether location is occupied, and sends address setting command from equipment to described according to testing result;
Step 5, described to receive address setting command from equipment, actual address is parsed from the address setting command And temporary address, if temporary address in the address setting command and being matched from the temporary address of equipment, will it is described practically Location is set as from the address of equipment, and is revised as having distributed address state from the equipment state of equipment by described.
With reference to first aspect, in one implementation, the step 4, comprising:
Step 4-1 judges to have occupied whether address table includes from the temporary address of equipment in the main equipment;
Step 4-2, if having occupied address table not and include from the temporary address of equipment, the detection knot in the main equipment Fruit be it is unoccupied, distributed to the temporary address as actual address from equipment by the address setting command;
Step 4-3, if the address table that occupied in the main equipment includes from the temporary address of equipment, the testing result To be occupied, other addresses in address table are not being occupied as actual address for any by the address setting command It distributes to from equipment.
With reference to first aspect, in one implementation, the step 1, comprising:
It the use of the address having used is temporary address if described have the address having used from equipment;
If the address not having used from equipment, random generation one meets RS485 bus protocol rule Temporary address.
With reference to first aspect, in one implementation, the step 3, comprising: described to send response message from equipment Before main equipment, in the case that bus mode is idle, a delay time is randomly generated, again when the delay time reaches Response message is sent to main equipment.
With reference to first aspect, in one implementation, the step 4, comprising: the main equipment is being received from equipment Time-out time is set when response message, when time-out time arrives, the main equipment stops receiving the response message from equipment,
If the main equipment does not receive any response message from equipment, then in current system not when time-out time arrives There are the slave equipment of address to be allocated, restarting finds timer from equipment, the slave equipment discovery of next round is waited to act.
With reference to first aspect, in one implementation, the step 4, comprising:
Step 4-4, main equipment compare described in each of receive response message from equipment;
Step 4-5, when there are repeat described in two or more from the temporary address in the response message of equipment When, it waits temporary address unduplicated after the distribution of device address, is sent provisionally to temporary address is duplicate from equipment Location resetting order.
Second aspect, the embodiment of the present invention provide a kind of RS485 from device address automatic distribution system, the system packet It includes: main equipment and from equipment;
The main equipment, for finding the slave equipment that newly accesses in instruction identification system by sending from equipment, for from setting Back-up matches the address RS485;
When repeating in system there are two or more slave equipment temporary address, temporary address is waited not repeat From device address distribution after, to temporary address it is duplicate from equipment send temporary address resetting order;
It is practical to being sent from equipment when the slave equipment temporary address that two or more are not present in system repeats Address setting command;
It is described from equipment, after generating temporary address, receive main equipment send slave equipment discovery instruction and to master set Preparation send response message;
When repeating in system there are the temporary address of two or more slave equipment, temporary address is waited not weigh After the multiple distribution from device address, receives resetting from address for main equipment and order and reset temporary address;
When two or more the temporary address repetition of slave equipment is not present in system, the reality of main equipment is received Simultaneously actual address is arranged in border address setting command.
In conjunction with second aspect, in one implementation, the main equipment includes:
Address table is occupied, for occupied from device address in preservation system;
From equipment discovery module, find to instruct from equipment for broadcast transmission;
Frame processing module parses the temporary address from equipment response message for receiving the response message from equipment, and Carry out respective handling, comprising:
Vacant unit, if not having from the temporary address of equipment occupied for described, the main equipment is by temporary address As the actual address from equipment;
Unit is occupied, if occupied for the temporary address from equipment, the main equipment is according to having occupied ground Location table selects a unappropriated address as the actual address from equipment;
Address replicated blocks have used identical temporary address for two or more slave equipment if it exists, When i.e. the temporary address of two or more slave equipment repeats, the main equipment sends temporary address reset indication to institute It is duplicate from equipment to state temporary address.
Address assignment module, for sending address distribution instruction from equipment to specified;
It is in one implementation, described from equipment in conjunction with second aspect, comprising:
Address logging modle, for recording from the device address that equipment last time uses when online.
It is in one implementation, described from equipment in conjunction with second aspect, comprising:
Temporary address generation module, for generating from the temporary address of equipment, the temporary address is preferentially protected using equipment The address that the last time deposited uses, if the address that the last time that the equipment saves uses is not present, random generation one meets The address of RS485 communications protocol rule;
Respond module is pre-assignment of addresses state for working as described from the equipment state of equipment, receives and refer to from equipment discovery Response message is sent to main equipment after order, the response message includes from the temporary address of equipment;
Address setting module, the address for handling main equipment set instruction, the setting actual address from equipment;
State switching module, for it is described obtain actual address from equipment after, by the equipment state from equipment by Pre-assignment of addresses state, which is switched to, has distributed address state;
Temporary address resets module, for two or more slave equipment if it exists used it is identical provisionally Location is regenerated from the temporary address of equipment, under waiting when that is, the temporary address of two or more slave equipment repeats One wheel is found.
From the above technical scheme, the embodiment of the present invention provide a kind of RS485 from device address auto-allocation method and System.The method comprise the steps that
Step 1, temporary address is generated from equipment, and is set as pre-assignment of addresses shape from the equipment state of equipment for described State;Step 2, main equipment broadcasts from equipment according to predetermined period and finds to instruct;Step 3, if described be from the equipment state of equipment Pre-assignment of addresses state, described receive from equipment from equipment find to instruct, and send response message, the response letter to main equipment Breath includes from the temporary address of equipment;Step 4, the main equipment receives the response message from equipment, detects the response message In it is whether occupied from the temporary address of equipment, and according to testing result to it is described from equipment send address setting command;Step 5, it is described to receive address setting command from equipment, actual address and temporary address are parsed from the address setting command, If temporary address in the address setting command and it is described matched from the temporary address of equipment, set the actual address to It is revised as having distributed address state from the equipment state of equipment from the address of equipment, and by described.
In the prior art, when being chosen from equipment by arbitration line to address distribution is carried out from equipment, the funeral of RS485 bus The advantage for having lost two wires transmission, really implements relatively difficult;Or using from the address distribution method of equipment active probe, The process time-consuming for obtaining free address from equipment is too long, and address allocative efficiency is low.And preceding method or system are used, it is not needing In the case where increasing additional hardware and not needing manual intervention, only the distributing automatically from device address by software realization Effect improves the address allocative efficiency from equipment compared with the existing technology.
Detailed description of the invention
In order to illustrate more clearly of technical solution of the present invention, letter will be made to attached drawing needed in the embodiment below Singly introduce, it should be apparent that, for those of ordinary skills, without any creative labor, It is also possible to obtain other drawings based on these drawings.
Fig. 1 is a kind of work for RS485 bus slave address automatic allocating method that part of the embodiment of the present invention provides Flow diagram;
Fig. 2 is that master sets in a kind of RS485 bus slave address automatic allocating method of part of embodiment of the present invention offer Standby workflow schematic diagram;
Fig. 3 is in a kind of RS485 bus slave address automatic allocating method that part of the embodiment of the present invention provides from setting Standby workflow schematic diagram;
Fig. 4 is a kind of structure for RS485 bus slave address automatic distribution system that part of the embodiment of the present invention provides Schematic diagram.
Specific embodiment
In order to make the foregoing objectives, features and advantages of the present invention clearer and more comprehensible, with reference to the accompanying drawing and specific real Applying mode, the present invention is described in further detail.
The embodiment of the present invention discloses a kind of RS485 from device address auto-allocation method, and this method is applied to principal and subordinate link Under mode, distributed automatically in RS485 bus from the address of equipment.
It referring to Fig.1, is a kind of RS485 bus slave address automatic allocating method of part of embodiment of the present invention offer Workflow schematic diagram, comprising the following steps:
Step 1, temporary address is generated from equipment, and is set as pre-assignment of addresses shape from the equipment state of equipment for described State;
In this step, described pass through during initialization from equipment generates temporary address, and realization is faced with main equipment Shi Tongxin.Specifically, be marked to from the equipment state of equipment herein, if being embodied as code, it is equivalent to a state The assignment of variable.
Step 2, main equipment broadcasts from equipment according to predetermined period and finds to instruct;
In this step, the main equipment during initialization by from equipment find timer setting predetermined period, Can timing the slave equipment newly accessed is inquired, i.e., when the predetermined period time then, carry out from equipment discovery act.Pass through This step can guarantee the operation of regular traffic in bus, specifically, capableing of the goal task of safeguards system by this step Operate normally, for example, in a data collection system, main equipment and from the goal task between equipment may include inquiry number According to, upload the business such as data.
Step 3, if it is described from the equipment state of equipment be pre-assignment of addresses state, it is described from equipment receive from equipment find Response message is sent to main equipment after instruction, the response message includes from the temporary address of equipment;
In the present embodiment, all can receive from equipment from equipment finds to instruct in system, but only in pre- point Slave equipment with address state is able to respond from equipment and finds to instruct, i.e., the only slave equipment of pre-assignment of addresses state is to main equipment Send response message.And the slave equipment of original state is not responding to any instruction of main equipment, has distributed the slave equipment of address state Ignore from equipment and finds to instruct.
Step 4, the main equipment receives the response message from equipment, detects in the response message from equipment provisionally Whether location is occupied, and sends address setting command from equipment to described according to testing result;
In this step, have in the main equipment and occupied address table, it is described occupied to have recorded in address table distributed From device address, i.e., the described address occupied in address table has been occupied by other from equipment.It is described to have occupied address table In, device address is indicated with value.
Step 5, described to receive address setting command from equipment, actual address is parsed from the address setting command And temporary address, if temporary address in the address setting command and being matched from the temporary address of equipment, will it is described practically Location is set as from the address of equipment, and is revised as having distributed address state from the equipment state of equipment by described.
In a kind of RS485 bus slave address automatic allocating method described in the present embodiment, the step 4, comprising:
Step 4-1 judges to have occupied whether address table includes from the temporary address of equipment in the main equipment;
Step 4-2, if having occupied address table not and include from the temporary address of equipment, the detection knot in the main equipment Fruit be it is unoccupied, distributed to the temporary address as actual address from equipment by the address setting command;
Step 4-3, if the address table that occupied in the main equipment includes from the temporary address of equipment, the testing result To be occupied, other addresses in address table are not being occupied as actual address for any by the address setting command It distributes to from equipment.
In this step, other described addresses are not in having occupied address table and to meet the ground of RS485 bus protocol Location, other described addresses must also be legal address.Specifically, not occupying ground for any by the address setting command It distributes to as actual address from equipment other addresses in the table of location, comprising: main equipment finds idle legal address conduct From the actual address of equipment, actual address is distributed to from equipment by address setting command again later.
In a kind of RS485 bus slave address automatic allocating method described in the present embodiment, the step 1, comprising:
It the use of the address having used is temporary address if described have the address having used from equipment;
Specifically, being saved in register in the present embodiment from equipment by the address having used, deposited by reading Device, if legitimate value can be read, expression has the address having used from equipment.
If the address not having used from equipment, random generation one meets RS485 bus protocol rule Temporary address.
In a kind of RS485 bus slave address automatic allocating method described in the present embodiment, the step 3, comprising: described In the case where the bus mode free time, a delay time is randomly generated before sending response message to main equipment from equipment, when The delay time, which retransmits response message when reaching, can be avoided bus collision by this step to main equipment.
In a kind of RS485 bus slave address automatic allocating method described in the present embodiment, the step 4, comprising: described Main equipment sets time-out time when receiving from the response message of equipment, when time-out time arrives, the main equipment stop receiving from The response message of equipment,
In this step, pass through the reasonable time-out time of setting, it is ensured that there are two above slave equipment simultaneously access system when, Main equipment can receive each response message from equipment.Specifically, can be adjusted according to practical application scene, such as in system The slave equipment needed is relatively more, and longer time-out time is arranged.
If the main equipment does not receive any response message from equipment, then in current system not when time-out time arrives There are the slave equipment of address to be allocated, restarting finds timer from equipment, the slave equipment discovery of next round is waited to act.
In a kind of RS485 bus slave address automatic allocating method described in the present embodiment, the step 4, comprising:
Step 4-4, main equipment compare described in each of receive response message from equipment;
It is each whether equal from the temporary address of equipment by judging in this step, it compares and each believes from the response of equipment Breath.Specifically, the temporary address of two or more slave equipment is equal if it exists, then determine described two or two Temporary address in the response message of above slave equipment repeats;Two or more slave equipment is interim if it does not exist Address is equal, then determines that the temporary address in described two or more than two response messages from equipment does not repeat.
Step 4-5, when there are repeat described in two or more from the temporary address in the response message of equipment When, it waits temporary address unduplicated after the distribution of device address, is sent provisionally to temporary address is duplicate from equipment Location resetting order.
In this step, specifically, for example, once from device discovery procedure, it was found that three slave equipment newly accessed, Temporary address is 2,3,3 respectively, then system is that the slave equipment that temporary address is 2 distributes address and then to temporary address It is 3 slave equipment transmission temporary address resetting order.In another example once from device discovery procedure, it was found that 5 from setting It is standby, it is each 2,3,3,4,4 respectively from the temporary address of equipment, likewise, being that the slave equipment that temporary address is 2 distributes address It afterwards, then to temporary address is 3 and slave equipment that temporary address is 4 sends temporary address resetting order, this 4 temporary addresses weights Their temporary address of multiple equipment replacement.After temporary address resetting order is received from equipment, again it is random generate it is new interim Address.
Using a kind of RS485 disclosed by the embodiments of the present invention from device address auto-allocation method, there are following advantages:
Firstly, this method does not need to increase additional hardware in addition to main equipment and from equipment, the feelings of manual intervention are not needed Under condition, only pass through automatic distribution of the software realization from device address.
Secondly, when not having occupied from equipment temporary address, temporary address is exactly for he from the high-efficient of device address distribution Final actual address, even if occupied from equipment temporary address, main equipment can also help to create one from equipment practically Location only exists in the duplicate situation in equipment temporary address, and more than two discovery periods is needed to complete from device address point Match.
Finally, if occur surprisingly going offline from equipment, or from equipment need power-off service after online situation again, from setting The standby device address that can be distributed before preferential use, this for some with device address be index it is some to having been carried out from equipment The system that configuration information saves has very big advantage, and device configuration information haves no need to change.
As shown in Fig. 2, being a kind of RS485 bus slave address automatic allocating method that part of the embodiment of the present invention provides The workflow schematic diagram of middle main equipment.
In order to guarantee the operation of regular traffic in bus, new access looking into from equipment is carried out between main equipment at regular intervals It askes, during initialization, the gap periods found from equipment are arranged in main equipment, i.e., the described predetermined period is arrived when cycle time When, acted from equipment discovery.
In order to realize that main equipment is the function of distributing address from equipment, has in the main equipment and occupied address table, remember Record all occupied device addresses of current system.
Whether the equipment of being distributed address, main equipment broadcast hair are needed in main equipment interval period regular time detection system It send from equipment and finds to instruct.It is all in system to receive this instruction from equipment, but only it is in pre-assignment of addresses state Slave equipment respond this instruction, this instruction of the response sends response message from equipment to main equipment, has distributed setting for address It is standby that this instruction is ignored.
Main equipment is uniformly handled, therefore main equipment is wanted when receiving response after receiving all responses from equipment Suitable time-out time is set, it is ensured that can receive all from equipment response.
If main equipment do not receive it is any responded from equipment, show that there is no addresses to be allocated from setting in current system Standby, restarting equipment finds timer, and the slave equipment of next round is waited to find.
Main equipment is received to be responded from equipment, is analyzed one by one from equipment response, is taken out interim in each response Address, from equipment temporary address there are three types of situation, main equipment is as follows to the processing of three kinds of situations:
1) there is no other are identical with this equipment temporary address from equipment, and from the temporary address of equipment not by other The equipment for distributing address occupies, and uses then this temporary address can be used as this from the actual address of equipment, main equipment issues address It assigns the call to from equipment.
2) it is identical with the temporary address of this equipment from equipment that other are not present, but the temporary address of equipment has been distributed by other The equipment of address occupies, and main equipment is according to address table has been occupied at this time, and to search a free address from equipment, main equipment is issued Address is assigned the call to from equipment.
3) there are two or more equipment temporary address having the same, main equipment records this state, and After all address distribution movement is completed, that is, it is all meet it is above-mentioned 1), 2) after the slave equipment of condition distributes address, hair It send from equipment temporary address and resets message, this message is broadcast message, and all online slave equipment can receive, but only not divide Slave equipment with address responds this message, and the equipment for having distributed address is ignored.
The main equipment issue from the distribution instruction of device address, contain from the temporary address of equipment and practically When location, the temporary address from equipment decision instruction and itself matching, this message is responded, is otherwise ignored.
As shown in figure 3, being a kind of RS485 bus slave address automatic allocating method that part of the embodiment of the present invention provides In from the workflow schematic diagram of equipment.
In order to complete from the automatic distribution function in device address, it is described from equipment preserve last time it is online when device address.
It is described from equipment in initialization, generate temporary address according to temporary address create-rule, juxtaposition oneself state is Pre-assignment of addresses state.
The temporary address create-rule follows such algorithm: first determine whether from equipment with the presence or absence of last time it is online when Device address, and if it exists, use the device address of last time as temporary address, if it does not exist, then random generation one meets The temporary address of RS485 communications protocol.
The temporary address generating algorithm preferentially uses the reason of device address having used is as temporary address to exist In, when equipment due to physical connection surprisingly disconnect or equipment be only be removed carry out daily maintenance it is online again when, The device address having used can also be maintained constant, this brings convenience to system configuration.
The equipment discovery instruction for waiting main equipment to send after the initialization is completed from equipment, and respond and sent out from equipment It now instructs, the temporary address information of itself is had in response.
It is described to be responded after equipment discovery instruction from equipment, the instruction that main equipment is sent is continued to, if in instruction Temporary address and itself temporary address match, then be further processed, otherwise, ignore this instruction.
It is described that process instruction is wanted by temporary address matching determination from equipment, type is analyzed the instruction, there are two types of possible fingers Enable type: from device address setting command and temporary address reset indication, the processing mode instructed from equipment to both is as follows:
1) address setting command is received, this indicates that main equipment has been that suitable actual address is assigned with from equipment, this When, the actual address in instruction is parsed from equipment, is set as the device address of itself, and oneself state is revised as having distributed Address state indicates to have obtained actual address from equipment, terminate from the process of equipment distribution address.
2) temporary address resetting order is received, this indicates that there are the slave equipment of other addresses to be allocated and facing for this equipment When address it is identical, at this point, regenerate temporary address from equipment using random fashion, and wait and receive main equipment next time and send Slave equipment find instruction.
It is described from equipment after entering and having distributed address state, any instruction no longer in response address assigning process, packet It includes: distributing instruction from equipment discovery instruction, from device address and from equipment temporary address reset indication.
In addition, being based on a kind of RS485 bus slave address automatic allocating method, the present embodiment also provides one kind RS485 is from device address automatic distribution system, the system comprises: main equipment and from equipment;
In the present embodiment, the quantity of the main equipment is 1, it is described from the quantity of equipment be positive integer more than or equal to 1.
The main equipment, for finding the slave equipment that newly accesses in instruction identification system by sending from equipment, for from setting Back-up matches the address RS485;
When repeating in system there are two or more slave equipment temporary address, temporary address is waited not repeat From device address distribution after, to temporary address it is duplicate from equipment send temporary address resetting order;
It is practical to being sent from equipment when the slave equipment temporary address that two or more are not present in system repeats Address setting command;
It is described from equipment, after generating temporary address, receive main equipment send slave equipment discovery instruction and to master set Preparation send response message;
When repeating in system there are the temporary address of two or more slave equipment, temporary address is waited not weigh After the multiple distribution from device address, receives resetting from address for main equipment and order and reset temporary address;
When two or more the temporary address repetition of slave equipment is not present in system, the reality of main equipment is received Simultaneously actual address is arranged in border address setting command.
From the automatic distribution system of device address, the main equipment includes: a kind of RS485 described in the present embodiment
Address table is occupied, for occupied from device address in preservation system;
From equipment discovery module, find to instruct from equipment for broadcast transmission;
Frame processing module parses the temporary address from equipment response message for receiving the response message from equipment, and Carry out respective handling, comprising:
Vacant unit, if not having from the temporary address of equipment occupied for described, the main equipment is by temporary address As the actual address from equipment;
Unit is occupied, if occupied for the temporary address from equipment, the main equipment is according to having occupied ground Location table selects a unappropriated address as the actual address from equipment;
Address replicated blocks have used identical temporary address for two or more slave equipment if it exists, When i.e. the temporary address of two or more slave equipment repeats, the main equipment sends temporary address reset indication to institute It is duplicate from equipment to state temporary address.
Address assignment module, for sending address distribution instruction from equipment to specified;
Specifically, described specify refers to: the mode that main equipment distributes address is " one-to-one ", and in RS485 agreement, it is main Equipment cannot send it is " one-to-one " instruction, broadcasting instructions can only be sent, therefore, in the instruction that main equipment issues at the same carry from Temporary address+true address of equipment.All slave equipment can receive this instruction, but pass through in decision instruction from equipment Temporary address and itself temporary address it is whether identical, to determine whether to respond this instruction.
A kind of RS485 described in the present embodiment is described from equipment from the automatic distribution system of device address, comprising:
Address logging modle, for recording from the device address that equipment last time uses when online.
It, can be from equipment by recording and saving from the device address that equipment last time uses when online in the present embodiment Not lost devices address when power down.
A kind of RS485 described in the present embodiment is described from equipment from the automatic distribution system of device address, comprising:
Temporary address generation module, for generating from the temporary address of equipment, the temporary address is preferentially protected using equipment The address that the last time deposited uses, if the address that the last time that the equipment saves uses is not present, random generation one meets The address of RS485 communications protocol rule;
Respond module is pre-assignment of addresses state for working as described from the equipment state of equipment, receives and refer to from equipment discovery Response message is sent to main equipment after order, the response message includes from the temporary address of equipment;
Address setting module, the address for handling main equipment set instruction, the setting actual address from equipment;
State switching module, for it is described obtain actual address from equipment after, by the equipment state from equipment by Pre-assignment of addresses state, which is switched to, has distributed address state;
Temporary address resets module, for two or more slave equipment if it exists used it is identical provisionally Location is regenerated from the temporary address of equipment, under waiting when that is, the temporary address of two or more slave equipment repeats One wheel is found.
In the prior art, when being chosen from equipment by arbitration line to address distribution is carried out from equipment, the funeral of RS485 bus The advantage for having lost two wires transmission, really implements relatively difficult;Or using from the address distribution method of equipment active probe, The process time-consuming for obtaining free address from equipment is too long, and address allocative efficiency is low.And preceding method or system are used, it is not needing In the case where increasing additional hardware and not needing manual intervention, only the distributing automatically from device address by software realization Effect improves the address allocative efficiency from equipment compared with the existing technology.
In the specific implementation, the present invention also provides a kind of computer storage mediums, wherein the computer storage medium can store There is program, which may include a kind of RS485 provided by the invention when executing from device address auto-allocation method and system Step some or all of in each embodiment.The storage medium can for magnetic disk, CD, read-only memory (English: Read-only memory, referred to as: ROM) or random access memory (English: random access memory, referred to as: RAM) etc..
It is required that those skilled in the art can be understood that the technology in the embodiment of the present invention can add by software The mode of general hardware platform realize.Based on this understanding, the technical solution in the embodiment of the present invention substantially or Say that the part that contributes to existing technology can be embodied in the form of software products, which can deposit Storage is in storage medium, such as ROM/RAM, magnetic disk, CD, including some instructions are used so that computer equipment (can be with It is personal computer, server or the network equipment etc.) execute certain part institutes of each embodiment of the present invention or embodiment The method stated.
Same and similar part may refer to each other between each embodiment in this specification.Invention described above is real The mode of applying is not intended to limit the scope of the present invention..

Claims (10)

1. a kind of RS485 is from device address auto-allocation method, which is characterized in that the described method includes:
Step 1, temporary address is generated when initializing from device power, and is set as pre-allocating from the equipment state of equipment by described Address state;
Step 2, main equipment broadcasts from equipment according to predetermined period and finds to instruct;
Step 3, if it is described from the equipment state of equipment be pre-assignment of addresses state, it is described from equipment receive from equipment find instruct Response message is sent to main equipment afterwards, the response message includes from the temporary address of equipment;
Step 4, the main equipment receives the response message from equipment, and detect in the response message is from the temporary address of equipment It is no occupied, and address setting command is sent from equipment to described according to testing result;
Step 5, described to receive address setting command from equipment, actual address is parsed from the address setting command and is faced When address the actual address is set if temporary address in the address setting command and being matched from the temporary address of equipment It is set to from the address of equipment, and is revised as having distributed address state from the equipment state of equipment by described.
2. a kind of RS485 according to claim 1 is from device address auto-allocation method, which is characterized in that the step 4, comprising:
Step 4-1 judges to have occupied whether address table includes from the temporary address of equipment in the main equipment;
Step 4-2, if in the main equipment to have occupied address table not include from the temporary address of equipment, the testing result is It is unoccupied, it is distributed to the temporary address as actual address from equipment by the address setting command;
Step 4-3, if the address table that occupied in the main equipment includes from the temporary address of equipment, the testing result is It is occupied, other addresses in address table are not being occupied as actual address distribution for any by the address setting command To from equipment.
3. a kind of RS485 according to claim 1 is from device address auto-allocation method, which is characterized in that the step 1, comprising:
It the use of the address having used is temporary address if described have the address having used from equipment;
If the address not having used from equipment, random generation one meets facing for RS485 bus protocol rule When address.
4. a kind of RS485 according to claim 1 is from device address auto-allocation method, which is characterized in that the step 3, comprising: described in the case where the bus mode free time, to be randomly generated one before sending response message to main equipment from equipment Delay time retransmits response message to main equipment when the delay time reaches.
5. a kind of RS485 according to claim 1 is from device address auto-allocation method, which is characterized in that the step 4, comprising: the main equipment sets time-out time when receiving from the response message of equipment, when time-out time arrives, the main equipment Stop receiving the response message from equipment;
If the main equipment does not receive any response message from equipment when time-out time arrives, then it is not present in current system The slave equipment of address to be allocated, restarting find timer from equipment, the slave equipment discovery of next round are waited to act.
6. a kind of RS485 according to claim 5 is from device address auto-allocation method, which is characterized in that the step 4, comprising:
Step 4-4, main equipment compare described in each of receive response message from equipment;
Step 4-5, when there are being repeated described in two or more from the temporary address in the response message of equipment, etc. After to the unduplicated distribution from device address in temporary address, temporary address resetting is sent from equipment to temporary address is duplicate Order.
7. a kind of RS485 is from device address automatic distribution system, which is characterized in that the system comprises: main equipment and from equipment;
The main equipment, for finding the slave equipment newly accessed in instruction identification system by sending from equipment, to divide from equipment With the address RS485;
When in system there are two or more slave equipment temporary address repeat when, wait temporary address it is unduplicated from After device address is distributed, temporary address resetting order is sent from equipment to temporary address is duplicate;
When the slave equipment temporary address that two or more are not present in system repeats, actual address is sent to from equipment Setting command;
It is described from equipment, after generating temporary address, receive main equipment send slave equipment discovery instruction and to main equipment send out Send response message;
When repeating in system there are the temporary address of two or more slave equipment, wait temporary address unduplicated After the distribution of device address, receives resetting from address for main equipment and order and reset temporary address;
When two or more the temporary address repetition of slave equipment is not present in system, main equipment is received practically Simultaneously actual address is arranged in location setting command.
8. a kind of RS485 according to claim 7 is from device address automatic distribution system, which is characterized in that the master sets It is standby to include:
Address table is occupied, for occupied from device address in preservation system;
From equipment discovery module, find to instruct from equipment for broadcast transmission;
Frame processing module parses the temporary address from equipment response message, and carry out for receiving the response message from equipment Respective handling, comprising:
Vacant unit, if for it is described do not have from the temporary address of equipment it is occupied, the main equipment using temporary address as From the actual address of equipment;
Occupied unit, if occupied for the temporary address from equipment, the main equipment according to having occupied address table, Select a unappropriated address as the actual address from equipment;
Address replicated blocks have used identical temporary address, i.e., two for two or more slave equipment if it exists When a or more than two repetitions from the temporary address of equipment, the main equipment sends temporary address reset indication and faces to described When address it is duplicate from equipment.
Address assignment module, for sending address distribution instruction from equipment to specified.
9. a kind of RS485 according to claim 7 is from device address automatic distribution system, which is characterized in that described from setting It is standby, comprising:
Address logging modle, for recording from the device address that equipment last time uses when online.
10. a kind of RS485 according to claim 8 is from device address automatic distribution system, which is characterized in that described from setting It is standby, comprising:
Temporary address generation module, for generating from the temporary address of equipment, the temporary address preferentially uses equipment to save The address that last time uses, if the address that the last time that the equipment saves uses is not present, it is logical that random generation one meets RS485 The address of protocol rule is interrogated as temporary address;
Respond module is pre-assignment of addresses state for working as described from the equipment state of equipment, receives and find after instructing from equipment Response message is sent to main equipment, the response message includes from the temporary address of equipment;
Address setting module, the address for handling main equipment set instruction, the setting actual address from equipment;
State switching module, for it is described obtain actual address from equipment after, by the equipment state from equipment by dividing in advance It is switched to address state and has distributed address state;
Temporary address resets module, has used identical temporary address for two or more slave equipment if it exists, When i.e. the temporary address of two or more slave equipment repeats, regenerates from the temporary address of equipment, wait next Wheel is found.
CN201910724108.8A 2019-08-07 2019-08-07 A kind of RS485 is from device address auto-allocation method and system Pending CN110505319A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910724108.8A CN110505319A (en) 2019-08-07 2019-08-07 A kind of RS485 is from device address auto-allocation method and system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910724108.8A CN110505319A (en) 2019-08-07 2019-08-07 A kind of RS485 is from device address auto-allocation method and system

Publications (1)

Publication Number Publication Date
CN110505319A true CN110505319A (en) 2019-11-26

Family

ID=68586414

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910724108.8A Pending CN110505319A (en) 2019-08-07 2019-08-07 A kind of RS485 is from device address auto-allocation method and system

Country Status (1)

Country Link
CN (1) CN110505319A (en)

Cited By (13)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111241019A (en) * 2019-12-31 2020-06-05 苏州阿德文斯电子科技有限公司 RS485 bus arbitration and address automatic identification method
CN111371659A (en) * 2020-03-09 2020-07-03 深圳市锐同技术有限公司 Method for automatically allocating RS485 slave equipment address
CN111629080A (en) * 2020-05-22 2020-09-04 浙江东鸿电子科技有限公司 Method for automatically allocating electric meter address
CN112084126A (en) * 2020-09-08 2020-12-15 南京华天科技发展股份有限公司 RS485 automatic address generation method
CN113055504A (en) * 2021-03-16 2021-06-29 威海新北洋数码科技有限公司 ID number setting method and system with master and slave devices
CN113852699A (en) * 2021-08-19 2021-12-28 依米康软件技术(深圳)有限责任公司 System and method for automatically distributing bus address
WO2022000969A1 (en) * 2020-07-01 2022-01-06 维谛技术有限公司 Link device and link device communication address configuration method
CN113938348A (en) * 2021-10-12 2022-01-14 深圳市丛文安全电子有限公司 Wireless communication method and communication system based on LoRa technology
CN113965308A (en) * 2021-10-26 2022-01-21 上海三思电子工程有限公司 Connection communication method, slave device and device control system
CN114285824A (en) * 2021-12-31 2022-04-05 磐石电气(常州)有限公司 Master-slave equipment addressing method
CN114301731A (en) * 2021-12-31 2022-04-08 德力西电气有限公司 Address management method, master device and slave device
TWI816570B (en) * 2022-10-04 2023-09-21 新唐科技股份有限公司 Method and system for automatically setting addresses
CN117135142A (en) * 2023-10-26 2023-11-28 浙江大学 Address allocation device and method for performance test of flexible production line of electric automobile motor

Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR20050014201A (en) * 2003-07-30 2005-02-07 엘지전자 주식회사 Method for Grant Internet Protocol Address in The Home Network System
EP1631042A1 (en) * 2004-08-24 2006-03-01 Bosch Rexroth AG Method for allocating a device address to a substation in a network as well as such substation and main station for said network
CN101631147A (en) * 2009-08-07 2010-01-20 华为技术有限公司 Method for distributing serial bus slave node address, electronic device and electronic system
CN101958939A (en) * 2010-10-15 2011-01-26 德讯科技股份有限公司 Automatic distribution method and system for multi-machine communication node equipment key address
CN102291448A (en) * 2011-08-08 2011-12-21 华南理工大学 Automatic IP (Internet protocol) address allocation method based on geographical position in mobile ad hoc network
CN103716420A (en) * 2014-01-03 2014-04-09 西南大学 Automatic station address obtaining method of Modbus ASCII slave station and slave station
CN103856578A (en) * 2014-01-03 2014-06-11 西南大学 Automatic slave station address acquisition method through Modbus RTU and slave station
CN106878488A (en) * 2017-04-29 2017-06-20 成都工鼎科技有限公司 A kind of Modbus RTU bus address auto-allocation methods
CN108737590A (en) * 2018-05-15 2018-11-02 浙江正泰电器股份有限公司 A kind of method that address is distributed automatically, system, Modbus main websites, Modbus slave stations

Patent Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR20050014201A (en) * 2003-07-30 2005-02-07 엘지전자 주식회사 Method for Grant Internet Protocol Address in The Home Network System
EP1631042A1 (en) * 2004-08-24 2006-03-01 Bosch Rexroth AG Method for allocating a device address to a substation in a network as well as such substation and main station for said network
CN101631147A (en) * 2009-08-07 2010-01-20 华为技术有限公司 Method for distributing serial bus slave node address, electronic device and electronic system
CN101958939A (en) * 2010-10-15 2011-01-26 德讯科技股份有限公司 Automatic distribution method and system for multi-machine communication node equipment key address
CN102291448A (en) * 2011-08-08 2011-12-21 华南理工大学 Automatic IP (Internet protocol) address allocation method based on geographical position in mobile ad hoc network
CN103716420A (en) * 2014-01-03 2014-04-09 西南大学 Automatic station address obtaining method of Modbus ASCII slave station and slave station
CN103856578A (en) * 2014-01-03 2014-06-11 西南大学 Automatic slave station address acquisition method through Modbus RTU and slave station
CN106878488A (en) * 2017-04-29 2017-06-20 成都工鼎科技有限公司 A kind of Modbus RTU bus address auto-allocation methods
CN108737590A (en) * 2018-05-15 2018-11-02 浙江正泰电器股份有限公司 A kind of method that address is distributed automatically, system, Modbus main websites, Modbus slave stations

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
BAI LI .ETC: "Research on the detecting system of distributed nodes based on RS-485 bus", 《 2010 INTERNATIONAL CONFERENCE ON EDUCATIONAL AND NETWORK TECHNOLOGY》 *
王娜等: "水产物联网系统传感器插拔方案及实现", 《信息化研究》 *

Cited By (16)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111241019A (en) * 2019-12-31 2020-06-05 苏州阿德文斯电子科技有限公司 RS485 bus arbitration and address automatic identification method
CN111371659B (en) * 2020-03-09 2022-05-03 深圳市锐同技术有限公司 Method for automatically allocating RS485 slave equipment address
CN111371659A (en) * 2020-03-09 2020-07-03 深圳市锐同技术有限公司 Method for automatically allocating RS485 slave equipment address
CN111629080A (en) * 2020-05-22 2020-09-04 浙江东鸿电子科技有限公司 Method for automatically allocating electric meter address
WO2022000969A1 (en) * 2020-07-01 2022-01-06 维谛技术有限公司 Link device and link device communication address configuration method
CN112084126A (en) * 2020-09-08 2020-12-15 南京华天科技发展股份有限公司 RS485 automatic address generation method
CN113055504A (en) * 2021-03-16 2021-06-29 威海新北洋数码科技有限公司 ID number setting method and system with master and slave devices
CN113852699A (en) * 2021-08-19 2021-12-28 依米康软件技术(深圳)有限责任公司 System and method for automatically distributing bus address
CN113938348A (en) * 2021-10-12 2022-01-14 深圳市丛文安全电子有限公司 Wireless communication method and communication system based on LoRa technology
CN113965308A (en) * 2021-10-26 2022-01-21 上海三思电子工程有限公司 Connection communication method, slave device and device control system
CN114301731A (en) * 2021-12-31 2022-04-08 德力西电气有限公司 Address management method, master device and slave device
CN114285824A (en) * 2021-12-31 2022-04-05 磐石电气(常州)有限公司 Master-slave equipment addressing method
CN114301731B (en) * 2021-12-31 2023-12-22 德力西电气有限公司 Address management method, master device and slave device
TWI816570B (en) * 2022-10-04 2023-09-21 新唐科技股份有限公司 Method and system for automatically setting addresses
CN117135142A (en) * 2023-10-26 2023-11-28 浙江大学 Address allocation device and method for performance test of flexible production line of electric automobile motor
CN117135142B (en) * 2023-10-26 2024-02-06 浙江大学 Address allocation device and method for performance test of flexible production line of electric automobile motor

Similar Documents

Publication Publication Date Title
CN110505319A (en) A kind of RS485 is from device address auto-allocation method and system
CN100389392C (en) Method for realizing load uniform in clustering system, system and storage controller
CN101459618B (en) Data packet forwarding method and device for virtual machine network
CN108924268B (en) Container cloud service system and pod creation method and device
US10846186B2 (en) Central processing unit CPU hot-remove method and apparatus, and central processing unit CPU hot-add method and apparatus
CN108733604A (en) A kind of 485 bus intelligent expansion method and devices based on modbus communications protocol
CN102025630A (en) Load balancing method and load balancing system
CN109040184B (en) Host node election method and server
CN103458013A (en) Streaming media server cluster load balancing system and balancing method
CN101729425A (en) Method and equipment for flow sending in VRRP networking
CN107645540A (en) The load-balancing method of web application systems
CN102594668A (en) Message forwarding method, device and exchange equipment
CN106101171A (en) Server method of attachment and device
CN102572012B (en) Message processing method, switchboard and system
CN113163008B (en) Connection intelligent management method and device of network service system and related equipment thereof
CN112492030B (en) Data storage method, device, computer equipment and storage medium
CN106231003B (en) A kind of address distribution method and device
CN109889421B (en) Router management method, device, terminal, system and storage medium
CN102148760B (en) Identification (ID) application method, device and system
CN108833570B (en) Cluster storage and balanced transmission system based on cloud storage
CN103002038A (en) Processing method and device for elastic load balancing
CN110557399A (en) Management data synchronization method and device, storage equipment and readable storage medium
US10320741B2 (en) Server IP address assignment system and method
EP3481099B1 (en) Load balancing method and associated device
CN106028303B (en) Intelligent device discovery method and device

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
RJ01 Rejection of invention patent application after publication

Application publication date: 20191126

RJ01 Rejection of invention patent application after publication