Location>code7788 >text

C# upper computer and PLC communication heartbeat realization method

Popularity:457 ℃/2024-09-23 16:00:57

-Begin-

Hello, everyone! I am Fu Gong. As we all know, in the industrial automation control system, the communication between the upper computer and the lower computer is one of the key links to realize automated production. In order to ensure the stability and reliability of communication, we commonly use a method called [heartbeat mechanism], which plays an important role in monitoring and maintaining the connection status during the communication process.

The Heartbeat Principle

The principle of heartbeat is very simple, the key point of heartbeat is the change, because only when the change is produced, we can know whether the other person is alive [Alive], this is somewhat similar to the human body's electrocardiogram. The heartbeat mechanism detects the health of the communication link by sending packets or signals at regular intervals. Here comes a concept calledHeartbeat AddressThe heartbeat address is a variable, generally we use Boolean type or integer type mostly. If the host computer or PLC does not detect a change in the heartbeat address within a specified period of time, it can be determined that the communication link is faulty or disconnected, and then take appropriate countermeasures, such as re-establishing the connection or send an alarm message. When we realize the heartbeat, we must first understand who is the protagonist, we are to let the host computer know whether the PLC is online or let the PLC know whether the host computer is online.

If we want the host computer to know the connection status, then the PLC needs to give the heartbeat address a changing value at regular intervals, and the host computer can determine whether the PLC is online or not by detecting whether the value of the heartbeat address has changed.

Here to clarify, in practice, we write the host computer many times do not need to do so, because the host computer itself is real-time communication, that is to say, it will constantly send request commands to the PLC, so the host computer is very easy to respond to the message to know whether the connection is normal or not, because the heartbeat of the nature of the heartbeat is still data interaction.

If we want the PLC to know the status of the connection, then the host computer must write different values to the heartbeat address at regular intervals, so that the PLC can determine whether the connection is normal or not by detecting whether this address value has changed.

Implementation steps

1、Define heartbeat address format: Both engineers need to define a specific data type as heartbeat address.

  • Heartbeat address as integer: Write a changing value to the heartbeat address at regular intervals, such as seconds of the current time.

  • Heartbeat address is Boolean: write inverse to heartbeat address at regular intervals and then detect the change.

2, set the heartbeat period: the choice of heartbeat period depends on the actual needs and performance requirements of the system, in general, a shorter period can detect failures in a more timely manner, but it will also increase the communication burden.

3, heartbeat program writing: heartbeat address data changes only need to write the value at regular intervals, heartbeat detection program, can be used to turn on the delay timer to detect the value of the change, if the heartbeat signal is not received in the specified time, the system should issue a timely warning or take measures.