Heartbeat
In this chapter you will find a description of the VIs with which you can create a Heartbeat connection monitoring between LabVIEWTM and TwinCAT. Further information on the parameters can be found in the Heartbeat Connection Monitoring section in the technical introduction. Connection monitoring can be created from the following Low-Level VIs:
- Init Heartbeat
- Run Heartbeat
- Stop Heartbeat
- Release Hearbeat
- Get RTD Estimate
The folder also contains the Heartbeat basic VI, in which the connection monitoring is summarized in a VI.
![]() | System requirements The Heartbeat function is available from TwinCAT 3.1 Build 4026. |
Init Heartbeat
The "Init Heartbeat" block creates a Heartbeat instance. Based on the client handle (see Init), a scan is performed for each registered target to determine whether an instance of FB_Heartbeat exists. If this is the case, connection monitoring is prepared for each heartbeat found. If no instance of FB_Heartbeat is found at any target, the VI returns the error -8114.
![]() | FB_Heartbeat The FB_Heartbeat function block can be found in the Tc3_HeartbeatConnectionMonitoring library and must be created and called in the project for which connection monitoring is being set up. |
The block also creates a Heartbeat event. This can then be used to query the status of the connection. As soon as the status of the connection changes, a Heartbeat event is generated. The Heartbeat event has the following event dates:
- HeartbeatHandle: Handle to the Heartbeat instance from which the event was generated.
- TargetAddr: String containing the AMS address (NetId:Port) of the target from which the Heartbeat event was triggered.
- Connection State: Enum that specifies the reason for triggering the Heartbeat event.
- Waiting: Heartbeat initialized, connection monitoring not (yet) started.
- Connected: Connection monitoring started.
- Timeout detected: Connection monitoring has detected an interruption.
- Stopped: Connection monitoring has been stopped.
- Error: An error has occurred during connection monitoring (error code is provided at the Heartbeat output. If more than one target is monitored, only the connection monitoring for the corresponding target is stopped; the others continue to run).
- Reserved: reserved (ignore)

Input/output | Meaning |
---|---|
[0][4] Handle | Handle to the ADS client |
[5] PollingTime in ms | Parameter Polling time in ms |
[6] HeartbeatHandle | Handle to the Heartbeat instance |
[7] UseRtdEstimation? | Parameter UseRtdEstimation |
[9] Offset in ms | Parameter offset |
[10] HeartbeatEvent | User Event Refnum on the generated Heartbeat event |
Run Heartbeat
The Run Heartbeat block is used to start and continuously execute connection monitoring. This block is executed until the connection monitoring is stopped with the Stop Heartbeat.

Input/output | Meaning |
---|---|
[0][4] Handle | Handle to the ADS client |
[5][6] HeartbeatHandle | Handle to the Heartbeat instance |
Stop Heartbeat
The Stop Heartbeat block is used to stop connection monitoring.

Input/output | Meaning |
---|---|
[0][4] HeartbeatHandle | Handle to the Heartbeat instance |
Release Heartbeat
The Release Heartbeat block releases the handle to the Heartbeat connection monitoring from the memory.

Input/output | Meaning |
---|---|
[0][4] Handle | Handle to the ADS client |
[5] HeartbeatHandle | Handle to the Heartbeat instance |
Get RTD Estimate
The Get RTD Estimate block returns the current (maximum) roundtrip delay (RTD) estimate for the selected target. The target can be selected via the "TargetAddr" string. If the string is empty, the target found first is automatically selected. To use this block, it is necessary to execute the Heartbeat connection monitoring (see VIs described above).

Input/output | Meaning |
---|---|
[0][4] Handle | Handle to the ADS client |
[5][6] HeartbeatHandle | Handle to the Heartbeat instance |
[7][8] TargetAddr | String with the address of the target |
[10] RTDEstimate | Estimation of the maximum RTD in ms |
Heartbeat
The Heartbeat block uses the Init Heartbeat, Run Heartbeat, Stop Heartbeat and Release Heartbeat blocks internally to enable the use of Heartbeat connection monitoring with just one block. The Heartbeat block also serves as an illustration of how Heartbeat connection monitoring can be used and edited.
Heartbeat connection monitoring is carried out continuously until it is stopped via a control. If the connection monitoring detects an interruption (timeout), an attempt is made to call up a VI (vi path timeout detected). If it is not possible to call the VI, the block and Heartbeat connection monitoring are stopped. At the output of the VI, the target for which an interruption was detected is then displayed via Timeout detected and the TargetAddr. If there are several interruptions, only the first interruption is displayed.

Input/output | Meaning |
---|---|
[0][4] Handle | Handle to the ADS client |
[1] Stop Heartbeat | Reference to a Boolean control that is used to end the execution of the Heartbeat VI. |
[2] vi path timeout detected | Path to a VI that is to be called if a connection interruption is detected. |
[5] PollingTime in ms | Parameter Polling time in ms |
[6] TargetAddr | String that specifies the target to which the possible timeout belongs. |
[7] UseRtdEstimation? | Parameter UseRtdEstimation |
[9] Offset in ms | Parameter offset |
[10] Timeout detected | Indicates whether a connection interruption was detected. |