Background
In most PLC application occasions, the PLC is externally connected with a touch screen, when an upper computer system of the PLC is abnormal, operation and maintenance personnel can observe key operation data through the touch screen, and when the PLC is abnormal, control instructions are timely issued to the PLC through the touch screen, so that accidents are avoided. The early touch screen and the CPU card of the PLC are communicated by adopting an RS232 or RS485 interface, but most of the PLCs and the touch screens on the market at present are communicated by adopting a network interface.
According to the operation logic of the master CPU and the slave CPU of the PLC, the slave CPU cannot respond to external control commands. It must be ensured that the touch screen is in communication with the main CPU to issue control commands to the PLC. Therefore, after the master and slave CPUs of the PLC are switched, the touch screen needs to break communication with the original master CPU and establish communication connection with the original slave and current master CPU. However, most touch screens in the market only support communication with 1 IP, and in early systems, when PLC has a master-slave switch, it is necessary to manually reconfigure the communication connection IP of the touch screen, and set the IP as the IP address of the current main CPU. However, the method is inconvenient for operation and maintenance management of the system, the system cannot be operated automatically, and human errors are easy to occur.
The main CPU shares an IP, which is used for communication with the touch screen, only the main CPU has the IP in any case, and after the main CPU is switched, the original main CPU uninstalls the currently bound shared IP from the own network card, and the original auxiliary CPU binds the shared IP to the own network card, so that the problems of manual operation switching and inconvenient operation and maintenance are avoided. The operating system generally applied to the PLC includes a command for binding or unloading the IP corresponding to the network card, for example, the linux operating system, and the function of unloading/binding the IP address can be achieved by calling the system command ifconfig related to the network card configuration.
However, after the original slave CPU rises as the master and executes the command of binding the shared IP to the own network card, the touch screen cannot establish communication connection with the CPU immediately. About tens of seconds to one minute, communication can be restored, that is, the shared IP cannot be immediately validated after the PLC master-slave switch. If the object monitored by the PLC is abnormal in this period, the object cannot be processed by issuing a control command through the touch screen, so that the whole system may be subjected to fatal influence.
Therefore, the fact that the PLC external touch screen cannot establish communication connection with the CPU immediately after the master CPU and the slave CPU are switched is a technical problem that needs to be solved by those skilled in the art.
Disclosure of Invention
The invention provides a method for rapidly effecting the shared IP of a dual-CPU redundant PLC after master-slave switching, which aims to solve the problem that the shared IP in the prior art cannot be immediately effected after the master-slave switching of the PLC.
The technical scheme adopted by the invention is as follows:
a method for rapidly effecting the shared IP of a dual CPU redundant PLC after master-slave switching comprises the following steps:
The main CPU of the PLC queries ARP information of the sharing IP of the main CPU every time t, and obtains the IP and the MAC address of the network segment equipment where the sharing IP is located from the ARP information.
The main CPU transmits the IP and the MAC address of the network segment equipment where the shared IP is located to the slave CPU, and the slave CPU receives the IP and the MAC address and stores the IP and the MAC address in a memory of the slave CPU.
After the PLC generates the master-slave switching of the CPU, the switched master CPU binds the own network card and the shared IP, and the switched slave CPU unloads the shared IP from the own network card.
The switched main CPU creates a link layer original socket comprising an ARP simulation response message through a socket function according to the IP and the MAC address of the network segment equipment where the shared IP is located in the memory, and the link layer original socket is submitted to a local network card driving layer through a sendto function and is sent to the equipment through the network card.
After receiving the original socket of the link layer, the equipment self IP protocol stack compares the destination MAC address in the original socket of the link layer, if the destination IP address is the same as the MAC address and the IP address of the equipment self, the equipment further analyzes the source MAC address and the source IP address in the original socket of the link layer, inquires the ARP list of the equipment self, judges whether the IP which is the same as the source IP in the original socket of the link layer exists or not, if the IP which is the same as the source IP in the original socket of the link layer exists, the source MAC in the original socket of the link layer is used for replacing the MAC corresponding to the existing IP, and the ARP list is updated. If not, the source MAC address and the source IP address in the original socket of the link layer are added to the ARP list.
Preferably, the ARP simulation response message comprises a destination MAC address, a source MAC address, an Ethernet frame type, a hardware type, a protocol type, a MAC address length, an IP address length, an ARP type, a source MAC address, a source IP address, a destination MAC address and a destination IP address.
Preferably, the time t is set to 1 minute.
Preferably, the device is a touch screen.
As a preferred scheme, the calling system command for inquiring the ARP information of the shared IP of the main CPU is:
The ARP-H ether-i eth0 represents ARP information of the network card eth0 where the main CPU shared IP is queried.
As a preferred scheme, the calling system command bound by the main CPU network card and the shared IP is as follows:
the ifconfig eth0 shares IP, and the network card eth0.
As a preferred scheme, the call system command for unloading the shared IP from the network card from the CPU is:
IP ADDR DEL share the IP/subnet mask dev eth0, network card eth0.
Preferably, the first parameter of the socket function is designated as pf_packet.
The method has the beneficial effects that the shared IP of the dual-CPU redundant PLC is quickly validated after the master-slave switching, after the master-slave switching of the PLC, the PLC automatically constructs an ARP simulation message and actively pushes the ARP simulation message to equipment of a shared IP network segment, so that the ARP simulation message immediately updates an ARP list of the PLC, and compared with the existing scheme of only unloading and rebinding the shared IP, the method can shorten the link interrupt recovery time between the PLC and a touch screen using the shared IP communication from tens of seconds to within 20ms, ensure that the touch screen can timely display possible abnormal conditions of a PLC monitoring object after the master-slave switching, respond to control commands issued by operation and maintenance personnel, and avoid accidents caused by failure of timely processing of the abnormality.
Detailed Description
The invention will be further described with reference to specific examples.
The PLC system architecture employing dual CPU hot standby redundancy is generally as shown in fig. 1:
The CPU card is the main controller of the PLC, is also the most core, structure and program complex component, is responsible for communicating with various IO cards through a field bus, collects data, outputs control commands, and performs a large amount of arithmetic and logic operations according to a certain period, and compared with other components of the PLC, the probability of abnormality of the CPU card in operation is relatively higher. Therefore, in the important process control occasion, a dual-CPU hot standby redundancy scheme is adopted to improve the overall reliability of the PLC.
When the CPU is running, 1 CPU is the master, 1 CPU is the slave, the master is responsible for communicating with the IO module, collecting data, issuing control command and logic operation, the slave is only responsible for monitoring the running state of the master, no external control command is responded, the master periodically sends the collected data and operation intermediate result to the slave, and when the master fails, the slave immediately takes over the work of the master.
When an ARP list of an embedded IP protocol stack of a touch screen cannot be updated in time along with the switching of a master CPU and a slave CPU of a PLC, the touch screen also considers that the shared IP belongs to the CPU before switching after switching, so that the touch screen always tries to communicate with the master CPU before switching until the ARP list reaches the update timeout, the IP protocol stack can resend ARP broadcasting to request the MAC address of a network card corresponding to the shared IP, and when the existing master CPU responds to the ARP broadcasting sent by the touch screen, the communication between the touch screen and the new master CPU can be established.
Under normal conditions, the mapping relation between the IP address and the MAC address of the main CPU is always stored in the ARP list of the touch screen, and after the master-slave CPU is switched by the PLC, the shared IP is bound to the original slave CPU, but the mapping relation between the IP and the MAC of the main CPU in the local ARP list is unchanged for the touch screen, and the MAC is still the MAC of the original main CPU and is not updated due to master-slave switching. Thus, when the touch screen sends a message to the main CPU, the message is still sent to the original main CPU, but not the current main CPU. After the fixed updating period of the ARP list is reached, the IP protocol stack can carry out ARP broadcasting again, the MAC address of the existing main CPU can be added into the ARP list of the touch screen, and communication can be recovered. The update period of this ARP is related to the IP protocol stack itself, typically not less than 30 seconds, up to several minutes.
Although the operation state monitoring and control of the PLC mainly depends on upper computer software, once the upper computer system is abnormal or a communication network between the local PLC and the upper computer system is attacked, the local touch screen is the last reserved monitoring control means, so that the touch screen can accurately display the operation state of the PLC in any situation, and the control is necessary for the PLC to be issued in some key occasions.
A method for rapidly effecting the shared IP of a dual CPU redundant PLC after master-slave switching comprises the following steps:
1) The main CPU of the PLC periodically inquires the ARP information of the same network segment of the local and shared IP in the running process so as to acquire the MAC addresses and the IP addresses of all devices which communicate with the PLC shared IP.
2) The main CPU sends the acquired MAC address and the IP address corresponding to the equipment belonging to the same network segment with the shared IP to the auxiliary CPU through the redundant network port, and the auxiliary CPU receives the information and stores the information in the local memory.
3) When the PLC generates master-slave switching, after the switched main CPU binds the network card with the shared IP, the main CPU bypasses the local IP protocol stack according to the MAC address and the IP address of the equipment which are received before switching and belong to the same network segment with the shared IP, automatically constructs an ARP simulation response message and actively transmits the ARP simulation response message to the equipment which accesses the PLC through the shared IP. The device is enabled to update its ARP list immediately, thereby enabling communication between the device and the PLC to resume immediately.
The following describes embodiments of the present invention by taking a dual CPU redundancy PLC system including 3 touch screens as an example, with reference to the accompanying drawings.
Step 1, assume that the shared IP of the PLC is set to be 192.168.2.1, 192.168.2.2, and 192.168.2.3 for 192.168.2.100,3 touch screens, respectively. The CPU operating system of the PLC is Linux.
And 2, inquiring the ARP information of the host CPU of the PLC once every 1 minute, and calling a system command of ARP-H ether-i eth0 for the Linux operating system, wherein eth0 is the name of the network card where the shared IP is located. The ARP-H ether-i eth0 represents ARP information for inquiring the network card where the sharing IP of the main CPU is located.
The information returned by the system is as follows:
192.168.0.10 00:11:13:fb:53:0a
192.168.0.11 00:32:14:f9:13:0b
192.168.1.22 01:03:98:e9:05:03
192.168.2.1 02:05:fc:01:09:46
192.168.2.2 02:05:fc:01:0a:10
192.168.2.3 02:05:fc:01:0a:20
The main CPU needs to parse the returned information and record 3 pieces of information of 192.168.2.X this network segment, namely the IP and MAC addresses of the touch screen located in the same IP network segment as the shared IP.
And 3, the main CPU transmits the IP and MAC information which belongs to the shared IP network segment equipment and is analyzed in the step 2 to the auxiliary CPU through a redundant network port, and the auxiliary CPU receives the IP and MAC information and stores the IP and MAC information in a memory of the auxiliary CPU.
Step 4, when the PLC generates CPU master-slave switching, the CPU which is the master at present is used for binding the own network card and the shared IP by calling a system command (for example, in a linux system, an ifconfig eth0 192.168.2.100 command is called, wherein eth0 is a descriptor of the network card, 192.168.2.100 is a shared IP), and the CPU which is the slave at present is used for unloading the shared IP from the own network card (for example, in the linux system, a IP ADDR DEL 192.168.2.100/24dev eth0 command is called to unload the shared IP, wherein 192.168.2.100 is the shared IP,24 represents a subnet mask, and eth0 is a network card descriptor).
Step 5, the original slave and master CPU constructs ARP simulation response messages according to the equipment IP and MAC information received in step 3, and the structure of the ARP simulation response messages is shown in Table 1 by taking a touch screen with the IP address of 192.168.2.1 and the MAC address of 02:05:fc:01:09:46 as an example:
Step 6, the main CPU program uses socket function to create 1 link layer original socket, note that the first parameter of function is designated as PF_PACKET, so that the network data receiving and transmitting can be performed by using the socket to bypass the local IP protocol stack, avoid the IP protocol stack from modifying data, then uses sendto function to submit the constructed 3 PACKET Wen Zhijie to the network card driving layer of the local network card based on the above created original socket, the network card sends the message to 3 touch screens, after the touch screen receives the message, the own IP protocol stack compares the destination MAC address in the message, if the destination IP address is the same as the own MAC address and IP address, then further analyzes the source MAC address and the source IP address in the message, and then queries the own ARP list to see if the IP is the same as the source IP in the message, if the IP is the same as the source IP in the message, the source MAC in the message is used to replace the MAC corresponding to the existing IP, and the ARP list is updated. The IP and source MAC are not added to the ARP list. Thus, when the touch screen and the current main CPU communicate and organize the Ethernet frame message package, the MAC address of the current main CPU is used instead of the MAC address of the original main CPU.
The foregoing is merely a preferred embodiment of the present invention and it should be noted that modifications and adaptations to those skilled in the art may be made without departing from the principles of the present invention, which are intended to be comprehended within the scope of the present invention.