Summary of the invention
For this reason, need the scheme providing a kind of RS485 to distribute from device address, solve the problem that existing RS485 distributes from device address.
For achieving the above object, inventor provide the system that a kind of RS485 distributes from device address, comprise a main equipment and multiple from equipment, main equipment and all comprise RS485 interface module from equipment, to be describedly all connected with main equipment by RS485 connector from equipment,
Described main equipment also comprises address assignment module, arbitration control module and arbitrating signals detection module; Described main equipment RS485 interface module is arbitrated control module with described main frame and is connected, and described main frame arbitration control module is connected with described arbitrating signals processing module, and described main frame arbitration control module is connected with described address assignment module;
Describedly also comprise from equipment arbitration control module from equipment, arbitration contest module; Describedly to be connected from equipment arbitration control module from equipment RS485 interface module with described, described from equipment arbitration control module and describedly compete model calling from equipment arbitration;
Described from equipment arbitration competition module be connected by arbitration line with described main equipment arbitrating signals processing module;
Described main equipment arbitration control module for controlling arbitrating signals processing module and arbitration information processing module, and sends from the order the assigning process of device address;
Described arbitrating signals processing module obtains arbitrate state for the level signal arranging arbitration line level signal and detection arbitration line;
Described address assignment module is used for generating from device address;
The described order sent with response main equipment for controlling arbitration contest module from equipment arbitration control module;
Described arbitration contest module obtains arbitrate state for the level signal detecting arbitration line and arranges arbitration line level signal.
Further, described address assignment module is for managing the address distributed.
And the present invention also provides a kind of RS485 method of distributing from device address, comprises the following steps:
Step 20 main equipment draws high arbitration line;
Step 30 drags down arbitration line from equipment, the arbitration line dragged down at first from equipment address acquisition arbiter rights;
Step 50 main equipment generates unique from device address, and main equipment sends described address to this from equipment;
Step 60 should receive from equipment address that main equipment distributes, and preserved this address as this address from equipment from equipment.
Further, further comprising the steps of:
Step 80 repeats step 20,30,50,60, until all from equipment address acquisition.
Further, also comprise:
Step 70 from equipment release arbitration line, should exit arbitration.
Further, also comprise:
Step 40 should send from equipment to main equipment and confirm authority order, and main equipment checks the confirmation authority order received.Main equipment verifies this authority and confirms that whether order is correct, if incorrect, go to step 20 main equipments and draws high arbitration line, restart to seize arbitration bus from equipment.8 a kind of RS485 bus slave address distribution methods according to claim 3, wherein step 30 is drawn high arbitration bus from equipment and is comprised step:
Step 31 is each generates a random delay respectively from equipment;
Step 32 checks arbitration line state from equipment at once after the time delay time-out of correspondence, if arbitration line is height, should arbitration line be dragged down from equipment and obtained arbitration right, if arbitration line is low, should from device repeats steps 31-32 until obtain arbiter rights or main equipment exits arbitration.
Further, further comprising the steps of:
Step 10 main equipment broadcast arbitration initiation command;
Step 90 main equipment is initiated arbitration the finish command and is exited arbitration.
Further, wherein step 80 also comprises from equipment release arbitration bus: behind preservation device address, should send out request from equipment to main equipment and exit command, main equipment sends allowance and exits command after the request of receiving exits command to this from equipment, should discharge arbitration line receiving after life is exited in allowance from equipment.
Further, wherein step 20 main equipment is drawn high arbitration line and is also comprised: main equipment draws high arbitration line, if arbitration line is not dragged down in the time-out time of setting, then completes the arbitration of address assignment.
Be different from prior art, technique scheme is by a signal wire, and namely arbitration line completes and obtains address sequencing from equipment, and main equipment all can generate different addresses at every turn, makes can obtain different addresses from equipment.
Embodiment
By describe in detail technical scheme technology contents, structural attitude, realized object and effect, coordinate accompanying drawing to be explained in detail below in conjunction with specific embodiment.
Refer to Fig. 1, the present embodiment is the system that a kind of RS485 distributes from device address, comprises and is located at main equipment 110 in RS485 (difference) bus and multiple from equipment 133.Describedly to be connected with the RS485 bus of main equipment 110 from equipment by RS485 connector 131.Described main equipment 110 comprises main equipment RS485 interface module 217, described main equipment RS485 interface module 217 is connected with described RS485 converter, describedly comprise from equipment RS485 interface module 235 from equipment, to be describedly connected with described RS485 converter from equipment RS485 interface module.Described main equipment 110 is also connected from equipment 133 with multiple by an arbitration line, in address allocation procedure, described arbitration line for choose need allocation address from equipment.In order to improve the ability of the driving arbitration line level of main equipment, in certain embodiments, described arbitration line is provided with pull-up resistor 120 in the one end near main equipment 110.Pull-up resistor is in order to arbitrating signals processing module and arbitration contest module can arrange arbitration line signal.The connection of described arbitration line and main equipment is the io mouth that arbitration line is connected to main equipment, described arbitration line with from the connection of equipment be the io mouth that arbitration line is connected to from equipment.
Refer to Fig. 2, each module of native system as shown in the figure: comprise in main equipment 210 arbitrating signals processing module 211, main equipment arbitration control module 213, address assignment module 215, main equipment 485 interface module 217; Arbitration contest module 231 is comprised, from equipment arbitration control module 233, from equipment RS485 interface module 235 in equipment 230.Described main equipment arbitration control module for controlling arbitrating signals processing module and arbitration information processing module, and sends from the order the assigning process of device address; Described arbitrating signals processing module is for arranging the level signal of arbitration line level signal and detection arbitration line; Described address assignment module is used for generating from device address; The described order sent with response main equipment for controlling arbitration contest module from equipment arbitration control module; Described arbitration contest module is for detecting the level signal of arbitration line and arranging arbitration line level signal.
Described main equipment arbitration control module initiates arbitration initiation command by RS485 interface module, arbitrating signals processing module draws high arbitration line immediately subsequently, drag down arbitration line obtain arbiter rights from controlling arbitration contest module after equipment arbitration control module detects arbitration initiation command, what drag down arbitration bus the soonest obtains arbiter rights from equipment; Described main equipment arbitration control module address acquisition distribution module generates unique address, and passes to from equipment RS485 by described main equipment RS485 interface module; Obtain from equipment arbitration control module and preserve this address, should exit arbitration from equipment, main equipment draws high arbitration line; Other equipment continues competition arbitration line, until all from equipment all equipment addresses, arbitration terminates.
This programme by increasing arbitration bus in original 485 network systems, and 485 address distribution comparing sheet choosing etc. decrease bus number, saves long distance wiring cost.This programme is chosen from equipment by the mode of arbitration, is given from equipment allocation address, ensure that the uniqueness from device address, do not have the situation from device address collision by main equipment.
Address assignment module also records and manages from device address in arbitrated procedure and 485 communication processs.
In certain embodiments, main equipment 110, can by dragging down arbitration line to inform from equipment when starting to carry out address assignment, then from the competition of equipment 133 pairs of arbitration lines can be by drawing high arbitration line.Now, in order to improve the arbitration line level driving force from equipment, pull-up resistor can be connected with near each from one end of equipment in arbitration line.
The detailed implementation methods of native system refers to Fig. 3.Namely a kind of 485 bus slave address distribution methods mainly comprise following steps:
Step 20 main equipment arbitrating signals processing module draws high arbitration line immediately, waits for from equipment and seizes arbitration line by arbitration contest module;
Step 30 after detecting that arbitration line level is drawn high, drags down arbitration line from equipment from equipment, the arbitration line dragged down at first from equipment address acquisition arbiter rights; Whether can be dragged down by detecting arbitration line from equipment, if dragged down, then illustrating and having from equipment address acquisition arbiter rights (i.e. the authority of address acquisition), then no longer dragging down arbitration line; If do not dragged down, then can carry out dragging down with address acquisition arbiter rights.
Step 50 main equipment generates unique from device address, and sends described address by RS485 differential bus to this from equipment;
Address that step 60 should be distributed from equipment Receiving Host, preserves this address as this address from equipment from equipment; The address assignment module of main equipment, by algorithm of Address Generation, ensures that the address generated is unique in systems in which.
Can be completed the distribution from device address by step 20,30,50,60.The present embodiment only can complete the address assignment from equipment by an arbitration line, enormously simplify the structure of system, reduces system cost.
In order to all allocation address from equipment, repeat step 20,30,50,60 until all be all assigned to address from equipment.
In this embodiment, after obtaining address from equipment, should from device flag oneself be address acquisition from equipment, no longer should go to drag down arbitration bus epicycle arbitration from the arbitration contest module of equipment, and namely exit epicycle and arbitrate.The address that is duplicatedly distributed can be prevented like this.
Judge whether all are all assigned to address from equipment and can adopt in such a way: while arbitrating signals processing module draws high arbitration line, main equipment arbitration control module opens time out timer, if do not seize arbitration bus from equipment within the time of setting, then think all and be all assigned to address from equipment, epicycle arbitration terminates.
May have in certain embodiments and multiplely drag down arbitration bus from equipment simultaneously, so just need to comprise after step 30 step 40 and send from equipment to main equipment and confirm authority order, main equipment checks the confirmation authority order received.Confirm that authority order sends to main equipment by RS485 bus, confirm that authority order comprises the specific identifier data from equipment and main equipment agreement, such as 0xFF02, confirms that authority order also comprises CRC check code.Inspection confirms that authority order is carried out in the following manner: main equipment is receiving the arbitration acknowledge command sent from equipment, and the information received by CRC check is correct.And main equipment detects in the data received whether comprise specific identification data, if having, continue step 50.In in some are implemented, such as in a upper embodiment, have in the step 32 and multiplely drag down arbitration bus from equipment simultaneously, multiplely send arbitration acknowledge command by RS485 bus to main equipment from equipment simultaneously, can cause the interference of RS485 bus, main equipment cannot receive correct confirmation.When not comprising the confirmation of agreement in the data that main equipment CRC check mistake or detect receives, then main equipment goes to step 20 and draws high arbitration bus, and from equipment, a new round seizes arbitration bus.
Be correct confirmation when main equipment detects what receive, then main equipment arbitration control module controls address assignment module and generates unique from device address, and main equipment control module is sent to this address from equipment by main equipment 485 interface module.
Step 30 is seized arbitration bus from equipment and is comprised step 31 and 32 in certain embodiments:
Step 31 each from equipment receive arbitration initiation command after, respectively generate a random delay;
Step 32 checks arbitration line state from equipment at once after the time delay time-out of correspondence, if arbitration line is high, arbitration line should be dragged down from the arbitration contest module of equipment and obtain arbitration right, if arbitration line is low, should from device repeats steps 31-32 until obtain arbiter rights or main equipment exits arbitration.Reduce multiple probability simultaneously dragging down arbitration bus from equipment by such method, improve address assignment efficiency.
Also comprise step 10 and step 90 in certain embodiments:
Step 10 main equipment is broadcast transmission arbitration initiation command on differential bus; This order can by specifically identifying differentiation, and arbitrating initiation command in certain embodiments can be expressed as: 0xFF01.
Step 90 main equipment broadcast arbitration the finish command exits arbitration; Receive the arbitration of arbitration the finish command backed off after random from equipment, no longer seize arbitration bus.Step 90 performs main equipment detects do not need allocation address or system to need other situations exiting arbitration from equipment.Step 10 and step 90 are beginning in order to clearly identify arbitration and end.
The step of arbitrating from equipment release in certain embodiments can be such: should send request to main equipment behind preservation device address from equipment and exit life, main equipment sends allowance and exits life after life is exited in the request of receiving to this from equipment, should discharge arbitration line receiving after life is exited in allowance from equipment.Can ensure from equipment in the address obtaining distribution like this.
In sum, this programme by increasing arbitration bus in original 485 network systems, and 485 address distribution comparing sheet choosing etc. decrease bus number, saves long distance wiring cost.This programme is chosen from equipment by the mode of arbitration, is given from equipment allocation address, ensure that the uniqueness from device address, do not have the situation from device address collision by main equipment.
It should be noted that, in this article, the such as relational terms of first and second grades and so on is only used for an entity or operation to separate with another entity or operational zone, and not necessarily requires or imply the relation that there is any this reality between these entities or operation or sequentially.And, term " comprises ", " comprising " or its any other variant are intended to contain comprising of nonexcludability, thus make to comprise the process of a series of key element, method, article or terminal device and not only comprise those key elements, but also comprise other key elements clearly do not listed, or also comprise by the intrinsic key element of this process, method, article or terminal device.When not more restrictions, the key element limited by statement " comprising ... " or " comprising ... ", and be not precluded within process, method, article or the terminal device comprising described key element and also there is other key element.In addition, in this article, " be greater than ", " being less than ", " exceeding " etc. be interpreted as and do not comprise this number; " more than ", " below ", " within " etc. be interpreted as and comprise this number.
Those skilled in the art should understand, the various embodiments described above can be provided as method, device or computer program.These embodiments can adopt the form of complete hardware embodiment, completely software implementation or the embodiment in conjunction with software and hardware aspect.The hardware that all or part of step in the method that the various embodiments described above relate to can carry out instruction relevant by program has come, described program can be stored in the storage medium that computer equipment can read, for performing all or part of step described in the various embodiments described above method.Described computer equipment, includes but not limited to: personal computer, server, multi-purpose computer, special purpose computer, the network equipment, embedded device, programmable device, intelligent mobile terminal, intelligent home device, wearable intelligent equipment, vehicle intelligent equipment etc.; Described storage medium, includes but not limited to: the storage of RAM, ROM, magnetic disc, tape, CD, flash memory, USB flash disk, portable hard drive, storage card, memory stick, the webserver, network cloud storage etc.
The various embodiments described above describe with reference to the process flow diagram of method, equipment (system) and computer program according to embodiment and/or block scheme.Should understand can by the combination of the flow process in each flow process in computer program instructions realization flow figure and/or block scheme and/or square frame and process flow diagram and/or block scheme and/or square frame.These computer program instructions can being provided to the processor of computer equipment to produce a machine, making the instruction performed by the processor of computer equipment produce device for realizing the function of specifying in process flow diagram flow process or multiple flow process and/or block scheme square frame or multiple square frame.
These computer program instructions also can be stored in can in the computer equipment readable memory that works in a specific way of vectoring computer equipment, the instruction making to be stored in this computer equipment readable memory produces the manufacture comprising command device, and this command device realizes the function of specifying in process flow diagram flow process or multiple flow process and/or block scheme square frame or multiple square frame.
These computer program instructions also can be loaded on computer equipment, make to perform sequence of operations step on a computing device to produce computer implemented process, thus the instruction performed on a computing device is provided for the step realizing the function of specifying in process flow diagram flow process or multiple flow process and/or block scheme square frame or multiple square frame.
Although be described the various embodiments described above; but those skilled in the art are once obtain the basic creative concept of cicada; then can make other change and amendment to these embodiments; so the foregoing is only embodiments of the invention; not thereby scope of patent protection of the present invention is limited; every utilize instructions of the present invention and accompanying drawing content to do equivalent structure or equivalent flow process conversion; or be directly or indirectly used in other relevant technical fields, be all in like manner included within scope of patent protection of the present invention.