The content of the invention
For this reason, it may be necessary to provide a kind of scheme of RS485 slave units address distribution, solves existing RS485 slave units address point
With the problem of.
To achieve the above object, a kind of system of RS485 slave units address distribution is inventor provided, including a master sets
Standby and multiple slave units, main equipment and slave unit all include RS485 interface modules, and the slave unit is equal by RS485 connectors
It is connected with main equipment,
The main equipment also includes address assignment module, arbitrates control module and arbitrating signals detection module;The master sets
Standby RS485 interface modules are connected with main frame arbitration control module, the main frame arbitration control module and the arbitrating signals
Processing module is connected, and the main frame arbitration control module is connected with the address assignment module;
The slave unit also includes slave unit arbitration control module, arbitration contest module;The slave unit RS485 interface moulds
Block is connected with slave unit arbitration control module, the slave unit arbitration control module and the slave unit arbitration contest module
Connection;
The slave unit arbitration contest module is connected with the main equipment arbitrating signals processing module by arbitration line;
The main equipment arbitration control module is used to control arbitrating signals processing module and arbitration information processing module, and
Send the order in slave unit address allocation procedure;
The arbitrating signals processing module is used to set arbitration line level signal and detects the level signal acquisition of arbitration line
Arbitration state;
The address assignment module is used to generate slave unit address;
The slave unit arbitration control module is used for the order for controlling arbitration contest module and the transmission of response main equipment;
The level signal that the arbitration contest module is used to detect arbitration line obtains arbitration state and sets arbitration line level
Signal.
Further, the address assignment module is used to manage allocated address.
And the present invention also provides a kind of method of RS485 slave units address distribution, comprises the following steps:
Step 20 main equipment draws high arbitration line;
Step 30 slave unit drags down arbitration line, and the slave unit of the arbitration line dragged down at first obtains address arbiter rights;
Step 50 main equipment generates unique slave unit address, and main equipment sends the address to the slave unit;
Step 60 slave unit receives the address of main equipment distribution, and slave unit preserves ground of the address as the slave unit
Location.
Further, it is further comprising the steps of:
Step 80 repeat step 20,30,50,60, until all slave units obtain address.
Further, in addition to:
Step 70 slave unit release arbitration line, exits arbitration.
Further, in addition to:
Step 40 slave unit is sent to main equipment confirms authority order, and main equipment examines the confirmation authority order received.
Main equipment verifies the authority and confirms whether order is correct, and step 20 main equipment is gone to if incorrect and draws high arbitration line, slave unit
Restart to seize arbitration bus.A kind of 8 RS485 bus slaves address distribution methods according to claim 3, wherein
Step 30 slave unit, which draws high arbitration bus, includes step:
The each slave unit of step 31 generates a random delay respectively;
Step 32 slave unit is immediately checked for arbitration line state after corresponding delay time-out, if arbitration line for should be from setting if high
The standby arbitration line that drags down obtains arbitration right, if arbitration line be the slave unit repeat step 31-32 if low until obtaining arbiter rights
Or main equipment exits arbitration.
Further, it is further comprising the steps of:
Step 10 main equipment broadcast arbitration initiation command;
Step 90 main equipment initiates arbitration end order and exits arbitration.
Further, wherein step 80 slave unit release arbitration bus also includes:The slave unit is after device address is preserved
Being exited command to main equipment hair request, main equipment sends allowance to the slave unit after receiving request and exiting command and exited command,
The slave unit discharges arbitration line after receiving allowance and exiting life.
Further, wherein step 20 main equipment is drawn high arbitration line and also included:Main equipment draws high arbitration line, if in setting
Arbitration line is not pulled low in time-out time, then completes the arbitration of address distribution.
Prior art is different from, above-mentioned technical proposal completes slave unit and obtain address by a signal wire, i.e. arbitration line
Sequencing, and main equipment can generate different addresses every time so that slave unit can obtain different addresses.
Embodiment
To describe the technology contents of technical scheme, construction feature, the objects and the effects in detail, below in conjunction with specific reality
Apply example and coordinate accompanying drawing to be explained in detail.
Referring to Fig. 1, the present embodiment is a kind of system of RS485 slave units address distribution, including located at RS485 (difference)
Main equipment 110 and multiple slave units 133 in bus.The slave unit passes through RS485 connectors 131 and main equipment 110
RS485 buses connect.The main equipment 110 includes main equipment RS485 interface modules 217, the main equipment RS485 interface modules
217 are connected with the RS485 converters, and the slave unit includes slave unit RS485 interface modules 235, the slave unit RS485
Interface module is connected with the RS485 converters.The main equipment 110 is also connected by an arbitration line and multiple slave units 133
Connect, in address allocation procedure, the arbitration line is used to choose the slave unit for needing to distribute address.In order to improve the drive of main equipment
The ability of dynamic arbitration line level, in certain embodiments, the arbitration line is provided with pull-up resistor in one end close to main equipment 110
120.Pull-up resistor is in order to which arbitrating signals processing module and arbitration contest module can set arbitration line signal.The arbitration line
Connection with main equipment is connected to the io mouths of main equipment for arbitration line, and the connection of the arbitration line and slave unit connects for arbitration line
To the io mouths of slave unit.
Referring to Fig. 2, each module of the system is as shown in the figure:Include arbitrating signals processing module 211, master in main equipment 210
Equipment arbitration control module 213, address assignment module 215, the interface module 217 of main equipment 485;Include arbitration in slave unit 230
Compete module 231, slave unit arbitration control module 233, slave unit RS485 interface modules 235.The main equipment arbitration control mould
Block is used to control arbitrating signals processing module and arbitration information processing module, and sends the life in slave unit address allocation procedure
Order;The arbitrating signals processing module is used to set arbitration line level signal and detects the level signal of arbitration line;The address
Distribute module is used to generate slave unit address;The slave unit arbitration control module is used to control arbitration contest module and response master
The order that equipment is sent;The arbitration contest module is used for the level signal for detecting arbitration line and sets arbitration line level signal.
The main equipment arbitration control module initiates arbitration initiation command, subsequent arbitrating signals by RS485 interface modules
Processing module draws high arbitration line immediately, and slave unit arbitration control module controls arbitration contest module after detecting arbitration initiation command
Drag down arbitration line and obtain arbiter rights, the slave unit for most dragging down arbitration bus soon obtains arbiter rights;The main equipment arbitration control
Molding block obtains address assignment module generation unique address, and passes to slave unit by the main equipment RS485 interface modules
RS485;Slave unit arbitration control module obtains and preserves the address, and the slave unit exits arbitration, and main equipment draws high arbitration line;Its
His equipment continues to compete arbitration line, and until all slave units all obtain device address, arbitration terminates.
This programme in original 485 network system by increasing arbitration bus, compared to 485 address distribution sides of piece choosing etc.
Formula reduces bus number, saves long range wiring cost.This programme chooses slave unit by way of arbitration, passes through main equipment
Address is distributed to slave unit, the uniqueness of slave unit address is ensure that, does not have the situation of slave unit address conflict.
Address assignment module records and managed slave unit address also in arbitrated procedure and 485 communication process.
In certain embodiments, main equipment 110 can be informed when proceeding by address distribution by dragging down arbitration line
Slave unit, then competition of the slave unit 133 to arbitration line can be by drawing high arbitration line.Now, in order to improve slave unit
Arbitration line level driver ability, pull-up resistor can be connected with close to one end of each slave unit in arbitration line.
The detailed implementation methods of the system refer to Fig. 3.I.e. a kind of 485 bus slave address distribution methods mainly include
Following steps:
Step 20 main equipment arbitrating signals processing module draws high arbitration line immediately, waits slave unit to pass through arbitration contest module
Seize arbitration line;
For step 30 slave unit after detecting that arbitration line level is drawn high, slave unit drags down arbitration line, the arbitration dragged down at first
The slave unit of line obtains address arbiter rights;Slave unit, if be pulled low, can be said by detecting whether arbitration line is pulled low
It is bright to have there is slave unit to obtain address arbiter rights (authority for obtaining address), then no longer drag down arbitration line;If not by
Drag down, then can be dragged down to obtain address arbiter rights.
Step 50 main equipment generates unique slave unit address, and sends institute to the slave unit by RS485 differential bus
State address;
The address of step 60 slave unit Receiving Host distribution, slave unit preserve address of the address as the slave unit;
The address assignment module of main equipment ensures that generated address is unique in systems by algorithm of Address Generation.
The distribution to slave unit address can be completed by step 20,30,50,60.The present embodiment is only with an arbitration line
The address distribution of slave unit can be completed, the structure of system is enormously simplify, reduces system cost.
For the distribution address to all slave units, repeat step 20,30,50,60 is all distributed until all slave units
Address is arrived.
In this embodiment, after slave unit obtains address, it oneself is the slave unit for having obtained address that the slave unit, which marks,
The arbitration contest module of the slave unit no longer goes to drag down arbitration bus in epicycle arbitration, that is, exits epicycle arbitration.So can be with
Prevent the address that is duplicatedly distributed.
Judge whether that all slave units are all assigned to address and can adopted in such a way:In arbitrating signals processing module
While drawing high arbitration line, main equipment arbitration control module opens time out timer, if not from setting within the time of setting
It is standby to seize arbitration bus, then it is assumed that all slave units are all assigned to address, and epicycle arbitration terminates.
There may be multiple slave units in certain embodiments while drag down arbitration bus, thus need after step 30
Sent comprising step 40 slave unit to main equipment and confirm authority order, main equipment examines the confirmation authority order received.Confirm power
Limit order is sent to main equipment by RS485 buses, confirms the specific identifier that authority order includes slave unit and main equipment is arranged
Data, such as 0xFF02, confirm that authority order also includes CRC check code.Examine and confirm that authority order is to enter in the following manner
Capable:Main equipment confirms order in the arbitration for receiving slave unit transmission, and the information received by CRC check is correct.
And whether specific mark data is included in the data that main equipment detection receives, continue step 50 if having.In some implementations
In in, such as in a upper embodiment, have multiple slave units in the step 32 while drag down arbitration bus, multiple slave units are simultaneously
Arbitration is sent to main equipment by RS485 buses and confirms order, the interference of RS485 buses can be caused, main equipment can not receive
Correct confirmation.When main equipment CRC check mistake or the confirmation for not including in the data received and arranging is detected,
Then main equipment goes to step 20 and draws high arbitration bus, and what slave unit started a new round seizes arbitration bus.
When main equipment detection, receive is correct confirmation, then main equipment arbitration control module control address distribution mould
Block generates unique slave unit address, and main equipment control module is sent to the address from setting by the interface module of main equipment 485
It is standby.
Step 30 slave unit seizes arbitration bus and includes step 31 and 32 in certain embodiments:
The each slave unit of step 31 generates a random delay respectively after arbitration initiation command is received;
Step 32 slave unit is immediately checked for arbitration line state after corresponding delay time-out, if arbitration line for should be from setting if high
Standby arbitration contest module drags down arbitration line and obtains arbitration right, straight for slave unit repeat step 31-32 if low if arbitration line
Arbitration is exited to acquisition arbiter rights or main equipment.Multiple slave units are reduced by such method and drag down arbitration bus simultaneously
Probability, improve address allocative efficiency.
Step 10 and step 90 are also included in certain embodiments:
Step 10 main equipment broadcast transmission on differential bus arbitrates initiation command;The order can be by specifically identifying
Distinguish, arbitrating initiation command in certain embodiments can be expressed as:0xFF01.
The broadcast arbitration of step 90 main equipment terminates order and exits arbitration;It is secondary that slave unit receives arbitration end order backed off after random
Cut out, no longer seize arbitration bus.Step 90 is to detect that no slave unit needs to distribute address or system needs in main equipment
Exit arbitration other in the case of perform.Step 10 and step 90 are to clearly identify the beginning and end of arbitration.
The step of slave unit release arbitration can be such in certain embodiments:The slave unit is preserving device address
Request being sent to main equipment afterwards and exiting life, main equipment sends allowance to the slave unit after receiving request and exiting life and exits life, should
Slave unit discharges arbitration line after receiving allowance and exiting life.It can so ensure slave unit in the address for obtaining distribution.
In summary, this programme in original 485 network system by increasing arbitration bus, compared to the 485 of piece choosing etc.
Address distribution reduces bus number, saves long range wiring cost.This programme chooses slave unit by way of arbitration,
Address is distributed to slave unit by main equipment, the uniqueness of slave unit address is ensure that, does not have the feelings of slave unit address conflict
Condition.
It should be noted that herein, such as first and second or the like relational terms are used merely to a reality
Body or operation make a distinction with another entity or operation, and not necessarily require or imply and deposited between these entities or operation
In any this actual relation or order.Moreover, term " comprising ", "comprising" or its any other variant are intended to
Nonexcludability includes, so that process, method, article or terminal device including a series of elements not only include those
Key element, but also the other element including being not expressly set out, or it is this process, method, article or end also to include
The intrinsic key element of end equipment.In the absence of more restrictions, limited by sentence " including ... " or " including ... "
Key element, it is not excluded that other key element in the process including the key element, method, article or terminal device also be present.This
Outside, herein, " being more than ", " being less than ", " exceeding " etc. are interpreted as not including this number;" more than ", " following ", " within " etc. understand
It is to include this number.
It should be understood by those skilled in the art that, the various embodiments described above can be provided as method, apparatus or computer program production
Product.These embodiments can use the embodiment in terms of complete hardware embodiment, complete software embodiment or combination software and hardware
Form.All or part of step in the method that the various embodiments described above are related to can by program come instruct the hardware of correlation come
Complete, described program can be stored in the storage medium that computer equipment can be read, for performing the various embodiments described above side
All or part of step described in method.The computer equipment, include but is not limited to:Personal computer, server, general-purpose computations
It is machine, special-purpose computer, the network equipment, embedded device, programmable device, intelligent mobile terminal, intelligent home device, wearable
Smart machine, vehicle intelligent equipment etc.;Described storage medium, include but is not limited to:RAM, ROM, magnetic disc, tape, CD, sudden strain of a muscle
Deposit, USB flash disk, mobile hard disk, storage card, memory stick, webserver storage, network cloud storage etc..
The various embodiments described above are with reference to method, equipment (system) and the computer program product according to embodiment
Flow chart and/or block diagram describe.It should be understood that can be by every in computer program instructions implementation process figure and/or block diagram
One flow and/or the flow in square frame and flow chart and/or block diagram and/or the combination of square frame.These computers can be provided
Programmed instruction is to the processor of computer equipment to produce a machine so that passes through the finger of the computing device of computer equipment
Order, which produces, to be used to realize what is specified in one flow of flow chart or multiple flows and/or one square frame of block diagram or multiple square frames
The device of function.
These computer program instructions may be alternatively stored in the computer that computer equipment can be guided to work in a specific way and set
In standby readable memory so that the instruction being stored in the computer equipment readable memory produces the manufacture for including command device
Product, the command device is realized to be referred in one flow of flow chart or multiple flows and/or one square frame of block diagram or multiple square frames
Fixed function.
These computer program instructions can be also loaded on computer equipment so that performed on a computing device a series of
Operating procedure is to produce computer implemented processing, so as to which the instruction performed on a computing device is provided for realizing in flow
The step of function of being specified in one flow of figure or multiple flows and/or one square frame of block diagram or multiple square frames.
Although the various embodiments described above are described, those skilled in the art once know basic wound
The property made concept, then other change and modification can be made to these embodiments, so embodiments of the invention are the foregoing is only,
Not thereby the scope of patent protection of the present invention, every equivalent structure made using description of the invention and accompanying drawing content are limited
Or equivalent flow conversion, or other related technical areas are directly or indirectly used in, similarly it is included in the patent of the present invention
Within protection domain.