Summary of the invention
The embodiment of the present invention provides a kind of address distribution method and device from node device, for realizing for multiple inversions
Device distributes address.
The embodiment of the present invention adopts the following technical solutions:
A kind of address distribution method from node device, comprising: receive the address registration instruction of host node device transmission
Afterwards, each to send respective identification information to the host node device respectively from node device;The master is received from node device
Instruction is distributed in the address that node device is sent, wherein includes the correspondence of identification information and address in the address distribution instruction
Relationship, the address is by the host node device according to receiving each identification information unique address generated;If from section
Identification information and the identification information match success of itself in instruction are distributed in the address that point device receives, it is determined that receive
The address in instruction is distributed as the address of itself in address.
Further, receive host node device transmission address registration instruction after, it is each from node device respectively to institute
State the step of host node device sends respective identification information, comprising: receive the address registration instruction of host node device transmission
Afterwards, it is each from node device respectively after waiting and reaching itself delay time, Xiang Suoshu host node device sends respective mark
Know information, wherein each that different delay times is respectively corresponded from node device.
Further, before the address registration instruction for receiving host node device transmission, the method also includes: it is initial
Change host node device and from node device.
Further, the initialization host node device and the step of from node device, comprising: setting messaging parameter, institute
Stating messaging parameter includes message frame format and baud rate, and the message frame format includes the frame format of the address registration instruction,
And the frame format of the address distribution instruction.
Further, the described the step of address distribution instruction that the host node device is sent is received from node device, packet
It includes: receiving the address distribution instruction that the host node device is broadcasted one by one from node device, wherein the distribution instruction of each address
In include an identification information and an address corresponding relationship.
A kind of address distributing device from node device, comprising: identification information sending module, for receiving host node
It is each to send respective mark letter to the host node device respectively from node device after the address registration instruction that equipment is sent
Breath;Command reception module, the address distribution instruction sent for receiving the host node device, wherein the address distribution refers to
It include the corresponding relationship of identification information and address in order, the address is each according to receiving by the host node device
Identification information unique address generated;Address determination module, for from the address distribution instruction that node device receives
Identification information and itself identification information match success, it is determined that receive address distribution instruction in address as itself
Address.
Further, the identification information sending module, is specifically used for, and infuses in the address for receiving host node device transmission
After volume instruction, it is each from node device respectively after waiting and reaching itself delay time, Xiang Suoshu host node device sends each
From identification information, wherein it is each that different delay times is respectively corresponded from node device.
Further, described device further include: initialization module, for initializing host node device and from node device.
Further, the initialization module, is specifically used for, and messaging parameter is arranged, the messaging parameter includes message frame
Format and baud rate, the message frame format include the frame format and address distribution instruction of the address registration instruction
Frame format.
Further, command reception module is specifically used for, and receives the address distribution that the host node device is broadcasted one by one and refers to
It enables, wherein include the corresponding relationship of an identification information and an address in the distribution instruction of each address.
The address distribution method and device of the slave node device provided through the embodiment of the present invention, set receiving host node
It is each to send respective identification information to host node device respectively from node device after the address registration instruction that preparation is sent,
Then the address that host node device is sent is received from node device and distribute instruction, wherein include mark in the distribution instruction of address
The corresponding relationship of information and address, if from identification information and the mark of itself in the address distribution instruction that node device receives
Information matches success, it is determined that address of the address in the distribution instruction of address received as itself.Since address above mentioned is
By host node device according to each identification information unique address generated is received, it can guarantee each equipment from node
The uniqueness of address is embodied as each function from node device distribution unique address.
Specific embodiment
To make the object, technical solutions and advantages of the present invention clearer, below in conjunction with the specific embodiment of the invention and
Technical solution of the present invention is clearly and completely described in corresponding attached drawing.Obviously, described embodiment is only the present invention one
Section Example, instead of all the embodiments.Based on the embodiments of the present invention, those of ordinary skill in the art are not doing
Every other embodiment obtained under the premise of creative work out, shall fall within the protection scope of the present invention.
As shown in Figure 1, the embodiment of the present invention provides a kind of address distribution method from node device, for realizing being multiple
Address is distributed from node device, in the embodiment, host node device is specifically as follows a host computer, specifically can be with from node device
It is inverter, which includes the following steps:
S101: receive host node device transmission address registration instruction after, it is each from node device respectively to the master
Node device sends respective identification information.
Referring to Fig. 2, the address distribution method provided in an embodiment of the present invention from node device, can apply in Modbus
In communication network, the Modbus communications network system includes a host node device and multiple from node device, the main section
It point device and described is connected respectively in Modbus bus from node device.
It is multiple from node device, referring to fig. 2 in slave node 1, from node 2 ..., from node N, N at this is represented from section
The quantity of point.Each includes a unique sequence number from node, and is distributed only after the operation for passing through subsequent step
One address.
In the embodiment, host node device and microprocessor may each comprise from node device;Communication unit etc..It is preferred that feelings
Under condition, the microprocessor can be the single-chip microcontroller of model C8051F021;The communication unit can be RS-485 interface core
Piece.
Address registration instruction at this, can be and broadcast sending by host node device, in this way, each from node device
Address above mentioned register instruction is received, it is then each to send respective mark to the host node device respectively from node device
Know information.Identification information at this can be used for identifying each unique identities from node device, for example, specifically can be each
A sequence number from node device.
It is each from node device respectively to the host node device send respective identification information when, host node device may be used also
To judge whether to wait time-out, if judging, host node device waits time-out, and host node device is directly currently received
From node device (practical is identification information) distribution unique address;If host node device waits time-out not yet, host node is set
It is standby to continue waiting for, to receive more identification informations.
S102: the address distribution instruction that the host node device is sent is received from node device, wherein the address distribution
It include the corresponding relationship of identification information and address in instruction, the address is each according to receiving by the host node device
A identification information unique address generated.
In the step, the format of address distribution instruction can be identification information+address.The main section is received from node device
Instruction is distributed in the address that point device is sent, and specifically can be from node device and receives the address that the host node device is broadcasted one by one
Distribution instruction, wherein include the corresponding relationship of an identification information and an address in the distribution instruction of each address.
When the step specifically executes, since host node device periodically can send address point from node device to each
With instruction, the identification information and address distribution that address distribution instruction instruction compares its own from node device instruct the mark carried
Whether consistent know information.
S103: if from identification information and the identification information match of itself in the address distribution instruction that node device receives
Success, it is determined that address of the address in the distribution instruction of address received as itself.
The address distribution method of the slave node device provided through the embodiment of the present invention is sent receiving host node device
Address registration instruction after, it is each to send respective identification information to host node device respectively from node device, then from
Node device receive host node device send address distribute instruction, wherein address distribution instruction in include identification information and
The corresponding relationship of address, if from identification information and the identification information of itself in the address distribution instruction that node device receives
With success, it is determined that address of the address in the distribution instruction of address received as itself.Since address above mentioned is by main section
Point device can guarantee the address of each equipment from node according to each identification information unique address generated is received
Uniqueness is embodied as each function from node device distribution unique address.
It is each from node after the address registration instruction for receiving host node device transmission in the S101 of above-described embodiment
The step of equipment sends respective identification information to the host node device respectively, can specifically include:
It is each to wait arrival itself respectively from node device after the address registration instruction for receiving host node device transmission
Delay time (the specially numerical value of a period, such as 1 millisecond, 2 milliseconds etc.) after, Xiang Suoshu host node device sends respective
Identification information, wherein it is each that different delay times is respectively corresponded from node device.
Can be while receiving above-mentioned register instruction from node device due to each, from the quantity of node device be it is multiple,
It is each to have opened turnaround time from node device is wrong when replying identification information to host node device, avoid the same time simultaneously
Message congestion caused by identification information is replied to host node device.
For each delay time from node device, can be by raw according to the sequence number of its own from node device
At, for example, it is each from node device according to unified Linearity Formula, sequence number is as input value, and delay time is as defeated
It is worth out, since each sequence number is different, different delay times can be obtained by above-mentioned Linearity Formula.
In addition, before receiving the address registration instruction that host node device is sent in the S101 of above-described embodiment, it can be with
Include the following steps: to initialize host node device and from node device.
It initializes host node device and the step of from node device, specifically can be setting messaging parameter, the communication is joined
Number includes message frame format and baud rate, and the message frame format includes the frame format of address registration instruction and described
The frame format of address distribution instruction.In a kind of specific embodiment, using the RTU frame lattice based on Modbus communications protocol
Formula, RTU frame format include that there are four fields, are address field, functional domain, data field and CRC check respectively.
It is corresponding with above method embodiment, implement the present invention also provides a kind of from the address distributing device 300 of node device
Example, as shown in figure 3, the device includes:
Identification information sending module 301 can be used for after receiving the address registration instruction of host node device transmission, respectively
It is a to send respective identification information to the host node device respectively from node device;
Command reception module 302 can be used for receiving the address distribution instruction that the host node device is sent, wherein institute
State address distribution instruction in include identification information and address corresponding relationship, the address is by the host node device root
According to receiving each identification information unique address generated;
Address determination module 303 can be used for the identification information in instructing from the address distribution that node device receives
With the identification information match success of itself, it is determined that address of the address in the distribution instruction of address received as itself.
The address distributing device of the slave node device provided through the embodiment of the present invention is sent receiving host node device
Address registration instruction after, it is each to send respective identification information to host node device respectively from node device, then from
Node device receive host node device send address distribute instruction, wherein address distribution instruction in include identification information and
The corresponding relationship of address, if from identification information and the identification information of itself in the address distribution instruction that node device receives
With success, it is determined that address of the address in the distribution instruction of address received as itself.Since address above mentioned is by main section
Point device can guarantee the address of each equipment from node according to each identification information unique address generated is received
Uniqueness is embodied as each function from node device distribution unique address.
The identification information sending module 301, specifically can be used for, in the address registration for receiving host node device transmission
After instruction, it is each from node device respectively after waiting and reaching itself delay time, Xiang Suoshu host node device sends respective
Identification information, wherein it is each that different delay times is respectively corresponded from node device.
As shown in figure 3, described device can also include: initialization module 304, for initializing host node device and from section
Point device.The initialization module 304, is specifically used for, and messaging parameter is arranged, the messaging parameter includes message frame format and wave
Special rate, the message frame format include the frame format of the address registration instruction and the frame format of address distribution instruction.
Command reception module 302, is specifically used for, and receives the address distribution instruction that the host node device is broadcasted one by one,
In, it include the corresponding relationship of an identification information and an address in the distribution instruction of each address.
It should be understood by those skilled in the art that, the embodiment of the present invention can provide as method, system or computer program
Product.Therefore, complete hardware embodiment, complete software embodiment or reality combining software and hardware aspects can be used in the present invention
Apply the form of example.Moreover, it wherein includes the computer of computer usable program code that the present invention, which can be used in one or more,
The computer program implemented in usable storage medium (including but not limited to magnetic disk storage, CD-ROM, optical memory etc.) produces
The form of product.
The present invention be referring to according to the method for the embodiment of the present invention, the process of equipment (system) and computer program product
Figure and/or block diagram describe.It should be understood that every one stream in flowchart and/or the block diagram can be realized by computer program instructions
The combination of process and/or box in journey and/or box and flowchart and/or the block diagram.It can provide these computer programs
Instruct the processor of general purpose computer, special purpose computer, Embedded Processor or other programmable data processing devices to produce
A raw machine, so that being generated by the instruction that computer or the processor of other programmable data processing devices execute for real
The device for the function of being specified in present one or more flows of the flowchart and/or one or more blocks of the block diagram.
These computer program instructions, which may also be stored in, is able to guide computer or other programmable data processing devices with spy
Determine in the computer-readable memory that mode works, so that it includes referring to that instruction stored in the computer readable memory, which generates,
Enable the manufacture of device, the command device realize in one box of one or more flows of the flowchart and/or block diagram or
The function of being specified in multiple boxes.
These computer program instructions also can be loaded onto a computer or other programmable data processing device, so that counting
Series of operation steps are executed on calculation machine or other programmable devices to generate computer implemented processing, thus in computer or
The instruction executed on other programmable devices is provided for realizing in one or more flows of the flowchart and/or block diagram one
The step of function of being specified in a box or multiple boxes.
In a typical configuration, calculating equipment includes one or more processors (CPU), input/output interface, net
Network interface and memory.
Memory may include the non-volatile memory in computer-readable medium, random access memory (RAM) and/or
The forms such as Nonvolatile memory, such as read-only memory (ROM) or flash memory (flash RAM).Memory is computer-readable medium
Example.
Computer-readable medium includes permanent and non-permanent, removable and non-removable media can be by any method
Or technology come realize information store.Information can be computer readable instructions, data structure, the module of program or other data.
The example of the storage medium of computer includes, but are not limited to phase change memory (PRAM), static random access memory (SRAM), moves
State random access memory (DRAM), other kinds of random access memory (RAM), read-only memory (ROM), electric erasable
Programmable read only memory (EEPROM), flash memory or other memory techniques, read-only disc read only memory (CD-ROM) (CD-ROM),
Digital versatile disc (DVD) or other optical storage, magnetic cassettes, tape magnetic disk storage or other magnetic storage devices
Or any other non-transmission medium, can be used for storage can be accessed by a computing device information.As defined in this article, it calculates
Machine readable medium does not include temporary computer readable media (transitory media), such as the data-signal and carrier wave of modulation.
It should also be noted that, the terms "include", "comprise" or its any other variant are intended to nonexcludability
It include so that the process, method, commodity or the equipment that include a series of elements not only include those elements, but also to wrap
Include other elements that are not explicitly listed, or further include for this process, method, commodity or equipment intrinsic want
Element.In the absence of more restrictions, the element limited by sentence "including a ...", it is not excluded that including element
There is also other identical elements in process, method, commodity or equipment.
The above is only the embodiment of the present invention, are not intended to restrict the invention.To those skilled in the art,
The invention may be variously modified and varied.It is all within the spirit and principles of the present invention made by any modification, equivalent replacement,
Improve etc., it should be included within scope of the presently claimed invention.