A method for quickly taking effect of shared IP of dual CPU redundant PLC after master-slave switching

By constructing ARP simulated response messages in PLC, the problem that the shared IP cannot be effective immediately after the PLC master-slave CPU switch is solved, and the rapid recovery of communication between the PLC and the touch screen is achieved, ensuring the system's timely response capabilities.

CN114942613BActive Publication Date: 2025-04-01NANJING NARI WATER RESOURCES & HYDROPOWER TECH CO LTD +1

Patent Information

Application Number
CN202210637582.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-06-07
Publication Date
2025-04-01
Estimated Expiration
2042-06-07

AI Technical Summary

Technical Problem

After the PLC's master-slave CPU switch, the shared IP cannot take effect immediately, resulting in interruption of communication between the touch screen and the CPU, and the abnormal situation of the PLC monitoring object cannot be responded to in time.

Method used

The PLC master CPU regularly querys the ARP information of the shared IP, obtains the IP and MAC addresses of the network segment device, and transmits this information to the slave CPU. After switching, the main CPU constructs an ARP simulated reply message, actively sends it to the device sharing the IP network segment, updates its ARP list, and restores communication.

Benefits of technology

The link interrupt recovery time between the PLC and the touch screen is shortened, from tens of seconds to less than 20ms, ensuring that the touch screen can timely display the abnormal situations of the PLC monitoring objects and respond to the control orders of the operation and maintenance personnel.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114942613B_ABST
    Figure CN114942613B_ABST
Patent Text Reader

Abstract

The invention discloses a method for quickly taking effect of a shared IP of a dual-CPU redundant PLC after master-slave switching. After the master-slave switching of the PLC occurs, an ARP simulation message is constructed by itself and actively pushed to the device of the shared IP network segment, so that the device immediately updates its own ARP list. Compared with the existing solution of only unloading and rebinding the shared IP, the link interruption recovery time between the PLC and a touch screen using the shared IP communication can be shortened from tens of seconds to within 20ms, ensuring that the touch screen can timely display the abnormal situation that may occur in the PLC monitoring object after the master-slave switching, respond to the control order issued by the operation and maintenance personnel, and avoid the occurrence of accidents due to the failure to handle the abnormality in time.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to a method for quickly validating a shared IP of a dual-CPU redundant PLC after master-slave switching, and belongs to the technical field of industrial control of PLCs. Background Art

[0002] In most PLC applications, PLCs are connected to touch screens. When the PLC host system fails, maintenance personnel can observe key operating data through the touch screen, and issue control instructions to the PLC through the touch screen in a timely manner to avoid unexpected situations. Early touch screens and PLC CPU cards communicated via RS232 or RS485 interfaces, but most PLCs and touch screens on the market now use network ports for communication.

[0003] According to the operation logic of the master and slave CPUs of the PLC, the slave CPU cannot respond to external control commands. Therefore, it is necessary to ensure that the touch screen is communicating with the master CPU before issuing control commands to the PLC. Therefore, when the master and slave CPUs of the PLC are switched, the touch screen needs to disconnect the communication with the original master CPU and establish a communication connection with the original slave CPU that is now the master. However, most touch screens on the market only support communication with one IP. In early systems, when the PLC switches from master to slave, it is necessary to manually reconfigure the communication connection IP of the touch screen and set the IP to the IP address of the current master CPU. However, this method is very inconvenient for system operation and maintenance management. The system cannot achieve fully automated operation and is prone to human errors.

[0004] The current mainstream solution is that the master and slave CPUs share an IP, which is used to communicate with the touch screen. In any case, only the master CPU has this IP. When the master and slave CPUs are switched, the CPU that was originally the master will uninstall the currently bound shared IP from its own network card, and the CPU that was originally the slave will bind this shared IP to its own network card, thus eliminating the need for manual switching and inconvenient operation and maintenance. The operating systems generally used for PLCs contain commands for binding or uninstalling the IP corresponding to the network card. For example, in the Linux operating system, the function of uninstalling / binding the IP address can be achieved by calling the system command ifconfig related to the network card configuration.

[0005] However, after the original slave CPU is upgraded to the master and executes the command to bind the shared IP to its own network card, the touch screen cannot immediately establish a communication connection with the CPU. It takes about tens of seconds to a minute for the communication to return to normal, that is, the shared IP cannot take effect immediately after the PLC master-slave switch. During this period, if the object monitored by the PLC is abnormal, it cannot be processed by issuing a control command through the touch screen, which may have a fatal impact on the entire system.

[0006] Therefore, the inability of the PLC external touch screen to immediately establish a communication connection with the CPU after the master and slave CPUs are switched is a technical problem that those skilled in the art urgently need to solve. Summary of the invention

[0007] Purpose: In order to overcome the problem in the prior art that the shared IP cannot take effect immediately after the master-slave switching of the PLC, the present invention provides a method for quickly taking effect of the shared IP of a dual-CPU redundant PLC after the master-slave switching.

[0008] Technical solution: To solve the above technical problems, the technical solution adopted by the present invention is:

[0009] A method for quickly taking effect of a shared IP of a dual-CPU redundant PLC after master-slave switching, comprising the following steps:

[0010] The main CPU of the PLC queries the ARP information of the main CPU shared IP at intervals t, and obtains the IP and MAC addresses of the devices in the network segment where the shared IP is located from the ARP information.

[0011] The master CPU transmits the IP and MAC addresses of the device in the network segment where the shared IP is located to the slave CPU, which receives the IP and MAC addresses and saves them in its own memory.

[0012] When the PLC CPU switches from master to slave, the switched master CPU binds its own network card to the shared IP; the switched slave CPU uninstalls the shared IP from its own network card.

[0013] After the switch, the main CPU creates a link layer raw socket including an ARP simulation reply message through the socket function according to the IP and MAC address of the device in the network segment where the shared IP is located in the memory. The link layer raw socket is submitted to the local network card driver layer through the sendto function, and then sent to the device by the network card.

[0014] After receiving the link layer raw socket, the device's own IP protocol stack compares the destination MAC address in the link layer raw socket to see if the destination IP address is the same as its own MAC address and IP address. If they are the same, it further resolves the source MAC address and source IP address in the link layer raw socket, and then queries its own ARP list to determine whether there is an IP that is the same as the source IP in the link layer raw socket. If so, use the source MAC in the link layer raw socket to replace the MAC corresponding to the existing IP and update the ARP list. If not, add the source MAC address and source IP address in the link layer raw socket to the ARP list.

[0015] As a preferred solution, the ARP simulation reply message includes: destination MAC address, source MAC address, Ethernet frame type, hardware type, protocol type, MAC address length, IP address length, ARP type, source MAC address, source IP address, destination MAC address, and destination IP address.

[0016] As a preferred solution, the time t is set to 1 minute.

[0017] As a preferred solution, the device is a touch screen.

[0018] As a preferred solution, the calling system command for querying the ARP information of the main CPU shared IP is:

[0019] arp–H ether–i eth0, which means querying the ARP information of the network card eth0 where the main CPU shared IP is located.

[0020] As a preferred solution, the calling system command for binding the main CPU network card and the shared IP is:

[0021] ifconfig eth0 shared IP, network card eth0.

[0022] As a preferred solution, the system command for unloading the shared IP from the network card from the CPU is:

[0023] ip addr del shared IP / subnet mask dev eth0, network card eth0.

[0024] As a preferred solution, the first parameter of the socket function is specified as PF_PACKET.

[0025] Beneficial effect: The present invention provides a method for quickly making the shared IP of a dual-CPU redundant PLC effective after a master-slave switch. After the master-slave switch occurs in the PLC, the method constructs an ARP simulation message by itself and actively pushes it to the device in the shared IP network segment, so that it immediately updates its own ARP list. Compared with the existing solution of only unloading and rebinding the shared IP, the link interruption recovery time between the PLC and the touch screen using the shared IP communication can be shortened from tens of seconds to less than 20ms, ensuring that the touch screen can promptly display possible abnormal conditions of the PLC monitoring object after the master-slave switch, respond to the control orders issued by the operation and maintenance personnel, and avoid accidents caused by the failure to handle the abnormalities in time. BRIEF DESCRIPTION OF THE DRAWINGS

[0026] Figure 1 It is a system architecture of dual CPU redundant PLC including touch screen. DETAILED DESCRIPTION

[0027] The present invention will be further described below in conjunction with specific embodiments.

[0028] The PLC system architecture using dual CPU hot standby redundancy is generally as follows Figure 1 As shown:

[0029] The CPU card is the main controller of the PLC, and is also the most core component with the most complex structure and program. It is responsible for communicating with various IO cards through the field bus, collecting data, outputting control commands, and performing a large number of arithmetic and logical operations in a certain period. Compared with other components of the PLC, the probability of abnormalities occurring in the CPU card during operation is relatively higher. Therefore, in important process control occasions, dual CPU hot standby redundancy solutions are used to improve the overall reliability of the PLC.

[0030] During operation, there are two CPUs, one is the master and the other is the slave. The master CPU is responsible for communicating with the IO module, collecting data, issuing control commands and logical operations, while the slave CPU is only responsible for monitoring the operating status of the master CPU and does not respond to any external control commands. The master CPU regularly sends the collected data and intermediate calculation results to the slave CPU. When the master CPU fails, the slave CPU immediately takes over the work of the master CPU.

[0031] When the ARP list of the IP protocol stack embedded in the touch screen fails to be updated in time with the switch between the master and slave CPUs of the PLC, the touch screen still believes that the shared IP belongs to the CPU before the switch, so it keeps trying to communicate with the master CPU before the switch. Until the ARP list reaches the update timeout, the IP protocol stack will resend the ARP broadcast to request the network card MAC address corresponding to the shared IP. When the existing master CPU responds to the ARP broadcast sent by the touch screen, the communication between the touch screen and the new master CPU can be established.

[0032] Under normal circumstances, the ARP list of the touch screen always stores the mapping relationship between the IP address and MAC address of the main CPU. When the PLC switches between the master and slave CPUs, although the original slave CPU is bound to a shared IP, for the touch screen, the mapping relationship between the master CPU IP and MAC in the local ARP list has not changed. This MAC is still the MAC of the original master CPU and has not been updated due to the master-slave switch. Therefore, when the touch screen sends a message to the master CPU, the message is still sent to the original master CPU, not the current master CPU. The IP protocol stack will not re-broadcast ARP until the fixed update cycle of the ARP list is reached, and the MAC address of the existing master CPU can be added to the ARP list of the touch screen, and communication can be restored. The update cycle of this ARP is related to the IP protocol stack itself, which is generally not less than 30 seconds and can be up to several minutes.

[0033] Although the PLC's operating status monitoring and control mainly rely on the host computer software, once the host computer system fails or the communication network between the local PLC and the host computer system is attacked, the local touch screen will be the last remaining monitoring and control method. Therefore, it is necessary to ensure that the touch screen can accurately display the PLC's operating status under any circumstances and issue control commands to the PLC in certain critical situations.

[0034] A method for quickly taking effect of a shared IP of a dual-CPU redundant PLC after master-slave switching, comprising the following steps:

[0035] 1) During operation, the main CPU of the PLC periodically queries the ARP information of the local machine that belongs to the same network segment as the shared IP in order to obtain the MAC address and IP address of all devices that communicate with the PLC sharing the IP.

[0036] 2) The master CPU sends the MAC address of the device that belongs to the same network segment as the shared IP and its corresponding IP address to the slave CPU through the redundant network port. The slave CPU receives the information and saves it in the local memory.

[0037] 3) When the PLC switches from master to slave, after the switched master CPU binds the network card to the shared IP, the master CPU bypasses the local IP protocol stack and constructs an ARP simulation reply message based on the MAC address and IP address of the device in the same network segment as the shared IP received before the switch, and actively sends it to the device accessing the PLC through the shared IP. The device immediately updates its own ARP list, thereby immediately restoring the communication between the device and the PLC.

[0038] The following describes a specific implementation of the present invention by taking a dual-CPU redundant PLC system including three touch screens as an example and combining with the accompanying drawings.

[0039] Step 1: Assume that the shared IP of the PLC is set to 192.168.2.100, and the IP addresses of the three touch screens are 192.168.2.1, 192.168.2.2, and 192.168.2.3. The CPU operating system of the PLC is Linux.

[0040] Step 2: The main CPU of the PLC queries the ARP information of the local machine every 1 minute. For the Linux operating system, call the system command arp-H ether-i eth0, where eth0 is the name of the network card where the shared IP is located. arp-H ether-i eth0 means querying the ARP information of the network card where the main CPU shared IP is located.

[0041] The information returned by the system is as follows:

[0042] 192.168.0.10 00:11:13:fb:53:0a

[0043] 192.168.0.11 00:32:14:f9:13:0b

[0044] 192.168.1.22 01:03:98:e9:05:03

[0045] 192.168.2.1 02:05:fc:01:09:46

[0046] 192.168.2.2 02:05:fc:01:0a:10

[0047] 192.168.2.3 02:05:fc:01:0a:20

[0048] The main CPU needs to parse the returned information and record the three pieces of information in the network segment 192.168.2.x. These three pieces of information are the IP and MAC addresses of the touch screen that are in the same IP segment as the shared IP.

[0049] Step 3: The master CPU transmits the IP and MAC information of the device in the shared IP network segment parsed in step 2 to the slave CPU through the redundant network port, and the slave CPU receives the information and saves it in its own memory.

[0050] Step 4: When the CPU of the PLC switches from master to slave, the CPU that was originally a slave and is now a master binds its own network card to the shared IP by calling a system command (for example, in a Linux system, calling the ifconfig eth0 192.168.2.100 command, where eth0 is the network card descriptor and 192.168.2.100 is the shared IP); and the CPU that was originally the master and is now a slave uninstalls the shared IP from its own network card (for example, in a Linux system, calling the ip addr del 192.168.2.100 / 24dev eth0 command to uninstall the shared IP, where 192.168.2.100 is the shared IP, 24 represents the subnet mask, and eth0 is the network card descriptor).

[0051] Step 5: The CPU, which was originally a slave and is now a master, constructs ARP simulation reply messages according to the device IP and MAC information received in step 3. Taking the touch screen with an IP address of 192.168.2.1 and a MAC address of 02:05:fc:01:09:46 as an example, the structure of the constructed ARP simulation reply message is shown in Table 1:

[0052]

[0053] Step 6: The main CPU program uses the socket function to create a link layer raw socket. Note that the first parameter of the function is specified as PF_PACKET. In this way, using this socket for network data transmission and reception can bypass the local IP protocol stack and avoid the IP protocol stack from modifying the data. Next, the sendto function is used to submit the constructed three messages directly to the local network card driver layer based on the raw socket created above, and the network card sends them to the three touch screens. After the touch screen receives the message, its own IP protocol stack compares the destination MAC address in the message to see if the destination IP address is the same as its own MAC address and IP address. If the same, the source MAC address and source IP address in the message are further parsed, and then the ARP list of the touch screen is queried to see if there is an IP that is the same as the source IP in the message. If so, the source MAC in the message is used to replace the MAC corresponding to the existing IP, and the ARP list is updated. If not, the IP and source MAC are added to the ARP list. In this way, when the touch screen communicates with the current main CPU and organizes Ethernet frame message encapsulation, the MAC address of the current main CPU is used instead of the MAC address of the original main CPU.

[0054] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principle of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.

Claims

1. A method for quickly taking effect of a shared IP of a dual-CPU redundant PLC after master-slave switching, characterized in that: The steps include: The main CPU of the PLC queries the ARP information of the main CPU shared IP at intervals t, and obtains the IP and MAC addresses of the devices in the network segment where the shared IP is located from the ARP information; The master CPU transmits the IP and MAC addresses of the device in the network segment where the shared IP is located to the slave CPU, which receives the IP and MAC addresses and saves them in its own memory. When the PLC CPU switches from master to slave, the switched master CPU binds its own network card to the shared IP; the switched slave CPU uninstalls the shared IP from its own network card; After the switch, the main CPU creates a link layer raw socket including the ARP simulation reply message through the socket function according to the IP and MAC address of the device in the network segment where the shared IP is located in the memory. The link layer raw socket is submitted to the local network card driver layer through the sendto function, and then sent to the device by the network card. After the device receives the link layer raw socket, its own IP protocol stack compares the destination MAC address in the link layer raw socket to see if the destination IP address is the same as its own MAC address and IP address. If they are the same, it further parses the source MAC address and source IP address in the link layer raw socket, and then queries its own ARP list to determine whether there is an IP that is the same as the source IP in the link layer raw socket. If so, use the source MAC in the link layer raw socket to replace the MAC corresponding to the existing IP and update the ARP list; if not, add the source MAC address and source IP address in the link layer raw socket to the ARP list.

2. According to claim 1, a method for quickly taking effect after master-slave switching of a shared IP of a dual-CPU redundant PLC, characterized in that: The ARP simulation reply message includes: destination MAC address, source MAC address, Ethernet frame type, hardware type, protocol type, MAC address length, IP address length, ARP type, source MAC address, source IP address, destination MAC address, and destination IP address.

3. The method for quickly taking effect after master-slave switching of a shared IP of a dual-CPU redundant PLC according to claim 1 is characterized in that: The time t is set to 1 minute.

4. The method for quickly taking effect after master-slave switching of a shared IP of a dual-CPU redundant PLC according to claim 1 is characterized in that: The device is a touch screen.

5. The method for quickly taking effect of a shared IP of a dual-CPU redundant PLC after master-slave switching according to claim 1, characterized in that: The system command to query the ARP information of the main CPU shared IP is: arp –H ether –i eth0 means querying the ARP information of the network card eth0 where the main CPU shared IP is located.

6. The method for quickly taking effect after master-slave switching of a shared IP of a dual-CPU redundant PLC according to claim 1 is characterized in that: After the switch, the main CPU calls the system command to bind its own network card and the shared IP: ifconfig eth0 shared IP, network card eth0.

7. The method for quickly taking effect of a shared IP of a dual-CPU redundant PLC after master-slave switching according to claim 1, characterized in that: After the switch, the slave CPU unloads the shared IP from its own network card by calling the following system command: ip addr del shared IP / subnet mask dev eth0, network card eth0.

8. The method for quickly taking effect of a shared IP of a dual-CPU redundant PLC after master-slave switching according to claim 1, characterized in that: The first argument to the socket function is specified as PF_PACKET.

Citation Information

Patent Citations

  • Automatic configuration method for network appliance IP address

    CN101500023A

  • PLC (programmable logic control) redundancy switching method

    CN107463148A

Cited By

  • Method and device for quickly recovering communication after master-slave switching of double-CPU redundant PLC (Programmable Logic Controller)

    CN120956604A