Automatic address negotiation system and method for PLC (programmable logic controller) expansion moduleTechnical Field
The invention relates to the technical field of PLC expansion, in particular to an automatic address negotiation system and method for a PLC expansion module.
Background
Typically, a PLC will have a main unit, power module, CPU, I/O module all integrated together. In some cases, since the number of points required by the control object is relatively large, the number of I/O points of the main unit is insufficient, and an expansion module needs to be added, or certain control modules (a communication module, an analog module, etc.) are required in some fields, but these modules are not integrated on the main unit, so that these expansion modules need to be added to meet the control requirement of the system.
Because of the lack of an interface, PLCs often require the use of expansion modules, which typically communicate with the PLC via a bus, each expansion module must have an address or ID that is unique from the other modules.
There are two types of address setting modes of the expansion module commonly used at present:
1. the expansion module is provided with a dial switch, the numerical value of the dial switch is the module address, and if the address of the module needs to be changed, the dial switch is changed. If the number of modules on a bus is large, two or more module addresses may be identical due to human error, so that communication errors are caused, and further more human check is needed.
2. The expansion module is connected with a computer, and the module address is set by using related computer software and stored in the module. Similar to the mode 1, the mode also has manual errors, so that each module address on one bus cannot be guaranteed to be unique, and computer cooperation is required for changing the module address, so that the mode is inconvenient.
Disclosure of Invention
Based on the technical problems in the background technology, the invention provides a PLC expansion module address auto-negotiation system and a method.
The invention provides a PLC expansion module address auto-negotiation system, which comprises a PLC and a plurality of expansion modules, wherein the PLC is provided with a bus interface, each expansion module is provided with a bus interface and two RS232 interfaces, the two RS232 interfaces are respectively provided with a transmitting interface and a receiving interface, the expansion modules are sequentially connected, the receiving interface of the first expansion module in the expansion modules is left, the transmitting interface of the last expansion module is left, the transmitting interfaces of the other expansion modules are connected with the receiving interface of the next expansion module, the PLC and the expansion modules are connected in cascade through expansion buses to form a bus topology structure, and the expansion modules are provided with nonvolatile memories (such as EEPROMs) for storing module addresses.
Preferably, the expansion bus is a CAN bus.
Preferably, the number of the expansion modules is between one and one hundred.
Preferably, the expansion module is respectively provided with an RS232 transmitting interface and an RS232 receiving interface.
A method for automatically negotiating the address of a PLC expansion module, wherein a transmission interface of the expansion module periodically transmits own address codes, and a receiving interface can receive the address codes transmitted by other modules connected with the transmission interface, the method comprises the following steps:
s1: starting a negotiation flow, resetting a local address to 1, wherein the local address is denoted by a;
s2: entering a judging box, identifying whether address information is received or not, and entering a next operation step after the address information is identified;
s3: after the judgment box recognizes that the information is received, the received address is denoted by b, and then the local address is set as: a=b+1, and then judging whether to end the distribution flow;
s4: when the end of the distribution flow is identified, saving a to a memory and setting the memory as a local address, and ending the negotiation flow;
s5: and S2, whether address information is received or not is identified, if not, whether the distribution flow is ended is judged in a judging box directly, and if not, the local address is sent to a judging box of the step S2 to judge, and the cyclic reciprocating operation is carried out.
Preferably, after the auto-negotiation process starts in S1, the module resets its own address code to 1.
Preferably, in the step S4, when the end of the allocation procedure is identified, the allocated address is saved to the memory, and after the next start-up, the expansion module takes the address in the memory as a default address.
Preferably, the expansion module reads address data in the memory after each power-up, and if no auto-negotiation instruction sent by the PLC is received, the address data is used for bus communication.
Preferably, the address code of the module in S1 is set to be the received address code plus one.
The invention provides that two RS232 interfaces are added in each expansion module, one is used for receiving and the other is used for transmitting, the left side of the expansion module in the figure 1 is used for receiving and the right side is used for transmitting, a transmitting port can transmit the address code of the expansion module in the process of automatic negotiation, and a receiving port can receive the module address code connected with the expansion module.
When the device is used, according to the expected ordering, the receiving port of the first module is left blank, the receiving port of the second module is connected with the receiving port of the first module, the sending port of each module is connected with the receiving port of the next module in sequence, and the sending port of the last module is left blank.
After the hardware connection is completed and the normal starting is completed, a broadcast instruction (the broadcast instruction does not need a module address) is sent to each expansion module by a communication bus, and the instruction content is an automatic negotiation starting address.
The program flow of negotiating addresses for each module is shown in fig. 2:
after the negotiation is started, the module resets the own address a to 1, and continuously checks whether the address code of the adjacent module is received, if not, the module is the first one, no other modules are connected with the receiving port, if the address b sent by the other modules is received, the own address a is set to b+1, and in the negotiation process, the module needs to periodically send the own address, so that the modules connected with the back of the module can calculate the corresponding addresses.
The whole negotiation process is automatically carried out, the address allocation of more than 100 modules can be completed within 1 second after the circulation is carried out every 5ms in the negotiation process, the PLC can send the command for ending the automatic negotiation after delay for 2 seconds after sending the command for starting the negotiation, the module stores the local address for subsequent use after receiving the command for ending the negotiation, and the next startup is not needed to be negotiated again.
The invention provides a PLC expansion module address auto-negotiation system and a method, which enable modules on the same bus to automatically allocate addresses according to sequence without manual intervention, and are convenient, quick and not easy to make mistakes.
Drawings
FIG. 1 is a block diagram of an address auto-negotiation system of a PLC expansion module according to the present invention;
fig. 2 is a block diagram of a method for automatically negotiating an address of a PLC extension module according to the present invention.
Detailed Description
The invention is further illustrated below in connection with specific embodiments.
Examples
The embodiment provides a PLC expansion module address auto-negotiation system, including PLC and a plurality of expansion module, be provided with the bus interface on the PLC, every expansion module has bus interface and two RS232 interfaces, and two RS232 interfaces are provided with send interface and receiving interface respectively, and a plurality of expansion module is connected in proper order, and first expansion module receiving interface in a plurality of expansion modules leaves the space, and last expansion module send interface leaves the space, and other expansion module send interface all is connected with next module receiving interface, PLC and a plurality of expansion module pass through expansion bus concatenation and form bus topology structure, be provided with nonvolatile memory (like EEPROM) on the expansion module, nonvolatile memory is used for storing the module address.
In this embodiment, the expansion bus is a CAN bus.
In this embodiment, the number of the expansion modules is between one and one hundred.
In this embodiment, the expansion module is provided with an RS232 transmission interface and an RS232 reception interface, respectively.
A method for automatically negotiating the address of a PLC expansion module, wherein a transmission interface of the expansion module periodically transmits own address codes, and a receiving interface can receive the address codes transmitted by other modules connected with the transmission interface, the method comprises the following steps:
s1: starting a negotiation flow, resetting a local address to 1, wherein the local address is denoted by a;
s2: entering a judging box, identifying whether address information is received or not, and entering a next operation step after the address information is identified;
s3: after the judgment box recognizes that the information is received, the received address is denoted by b, and then the local address is set as: a=b+1, and then judging whether to end the distribution flow;
s4: when the end of the distribution flow is identified, saving a to a memory and setting the memory as a local address, and ending the negotiation flow;
s5: and S2, whether address information is received or not is identified, if not, whether the distribution flow is ended is judged in a judging box directly, and if not, the local address is sent to a judging box of the step S2 to judge, and the cyclic reciprocating operation is carried out.
In this embodiment, after the auto-negotiation process starts in S1, the module resets its own address code to 1.
In this embodiment, when the end of the allocation procedure is identified in S4, the allocated address is saved to the memory, and after the next start-up, the expansion module takes the address in the memory as the default address.
In this embodiment, the expansion module reads the address data in the memory after each power-up, and if the auto-negotiation instruction sent by the PLC is not received, the address data is used for bus communication.
In this embodiment, the address code of the module in S1 is set to be the received address code plus one.
As shown in fig. 1, in a conventional case, the PLC and the expansion modules are originally connected only by using a communication bus, and the PLC communicates with the corresponding expansion module according to an address code, which requires that the addresses of the expansion modules be set in advance.
The invention provides that two RS232 interfaces are added in each expansion module, one is used for receiving and the other is used for transmitting, the left side of the expansion module in the figure 1 is used for receiving and the right side is used for transmitting, a transmitting port can transmit the address code of the expansion module in the process of automatic negotiation, and a receiving port can receive the module address code connected with the expansion module.
When the device is used, according to the expected ordering, the receiving port of the first module is left blank, the receiving port of the second module is connected with the receiving port of the first module, the sending port of each module is connected with the receiving port of the next module in sequence, and the sending port of the last module is left blank.
After the hardware connection is completed and the normal starting is completed, a broadcast instruction (the broadcast instruction does not need a module address) is sent to each expansion module by a communication bus, and the instruction content is an automatic negotiation starting address.
The program flow of negotiating addresses for each module is shown in fig. 2:
after the negotiation is started, the module resets the own address a to 1, and continuously checks whether the address code of the adjacent module is received, if not, the module is the first one, no other modules are connected with the receiving port, if the address b sent by the other modules is received, the own address a is set to b+1, and in the negotiation process, the module needs to periodically send the own address, so that the modules connected with the back of the module can calculate the corresponding addresses.
The whole negotiation process is automatically carried out, the address allocation of more than 100 modules can be completed within 1 second after the circulation is carried out every 5ms in the negotiation process, the PLC can send the command for ending the automatic negotiation after delay for 2 seconds after sending the command for starting the negotiation, the module stores the local address for subsequent use after receiving the command for ending the negotiation, and the next startup is not needed to be negotiated again.
The foregoing is only a preferred embodiment of the present invention, but the scope of the present invention is not limited thereto, and any person skilled in the art, who is within the scope of the present invention, should make equivalent substitutions or modifications according to the technical scheme of the present invention and the inventive concept thereof, and should be covered by the scope of the present invention.