Notes on the documentation

This description is only intended for the use of trained specialists in control and automation engineering who are familiar with the applicable national standards.
It is essential that the following notes and explanations are followed when installing and commissioning these components.

The responsible staff must ensure that the application or use of the products described satisfy all the requirements for safety, including all the relevant laws, regulations, guidelines and standards.

Disclaimer

The documentation has been prepared with care. The products described are, however, constantly under development.
For that reason the documentation is not in every case checked for consistency with performance data, standards or other characteristics.
In the event that it contains technical or editorial errors, we retain the right to make alterations at any time and without warning.
No claims for the modification of products that have already been supplied may be made on the basis of the data, diagrams and descriptions in this documentation.

Trademarks

Beckhoff®, TwinCAT®, EtherCAT®, Safety over EtherCAT®, TwinSAFE®, XFC®and XTS® are registered trademarks of and licensed by Beckhoff Automation GmbH.
Other designations used in this publication may be trademarks whose use by third parties for their own purposes could violate the rights of the owners.

Patent Pending

The EtherCAT Technology is covered, including but not limited to the following patent applications and patents:
EP1590927, EP1789857, DE102004044764, DE102007017835
with corresponding applications or registrations in various other countries.

The TwinCAT Technology is covered, including but not limited to the following patent applications and patents:
EP0851348, US6167425 with corresponding applications or registrations in various other countries.

Copyright

© Beckhoff Automation GmbH, Germany.
The reproduction, distribution and utilization of this document as well as the communication of its contents to others without express authorization are prohibited.
Offenders will be held liable for the payment of damages. All rights reserved in the event of the grant of a patent, utility model or design.


Introduction

The present function blocks simplify event-driven data exchange between the TwinCAT PLC runtime system and/or other ADS devices (TwinCAT NC, Bus Terminal Controller, ...).
The FB_WriteXXXOnDelta() function blocks implement a write procedure when the input signal rises above or falls below a specified limit value. The frequency with which the input signal is examined can be set. Event-driven data writing minimises the loading on the fieldbus. If an error occurs during transmission, the process is repeated until the connection is established once more. All data types supported in the TwinCAT PLC are permitted as source and destination variables. Symbol names are also supported.
Watchdog blocks are available to monitor individual communication partners. The device that is to be monitored cyclically transmits an incrementing counter. A check is made at the receiver to see that the counter state changes within a specific time.

Write/Read Blocks

Name | Description
FB_WriteBoolOnDelta | Writes a variable of type BOOLEAN in response to an event.
FB_WriteByteOnDelta | Writes a variable of type BYTE in response to an event.
FB_WriteWordOnDelta | Writes a variable of type WORD in response to an event.
FB_WriteDWordOnDelta | Writes a variable of type DWORD in response to an event.
FB_WriteRealOnDelta | Writes a variable of type REAL in response to an event.
FB_WriteLRealOnDelta | Writes a variable of type LREAL in response to an event.

Monitoring Blocks

Name | Description
FB_WriteWatchdog | Writes a watchdog signal (an incrementing counter) cyclically
FB_CheckWatchdog | Monitors the received watchdog signal


FB_WriteBoolOnDelta

TwinCAT PLC Library: Data exchange PLC <-> ADS device

FUNCTION_BLOCK FB_WriteBoolOnDelta

Event-driven writing of a variable of type BOOLEAN.

Interface

VAR_INPUT
    bEnable          :  BOOL := FALSE;
    sNetId           :  T_AmsNetId;
    nPort            :  T_AmsPort;
    nIdxGrp          :  UDINT;
    nIdxOffs         :  UDINT;
    sVarName         :  STRING;
    bSignal          :  BOOL;
    tCycleTime       :  TIME := t#0s;
    bSendNow         :  BOOL;
END_VAR

VAR_OUTPUT
    bBusy            :  BOOL := FALSE;
    bLastSignal      :  BOOL;
    bError           :  BOOL := FALSE;
    nErrorId         :  UDINT := 0;
    nErrorCnt        :  UDINT := 0;
END_VAR

Parameters

Inputs

bEnable
Enable block.
sNetId
AMS-NetId of the ADS device to which the value is to be transmitted.
nPort
AMS- port number of the ADS device to which the value is to be transmitted.
nIdxGrp
Index group within the ADS device into which the value is to be transmitted.
nIdxOffs
Index offset within the ADS device into which the value is to be transmitted.
sVarName
Symbol name within the ADS device into which the value is to be transmitted.
bSignal
Variable whose value is to be transmitted.
tCycleTime
Cycle period in which the input signal is examined to see that it has changed.
bSendNow
The value is transmitted immediately in response to a rising edge.

Outputs

bBusy
Transmission is active.
bLastSignal
Most recently transmitted value.
bError
An error occurred during the transmission.
nErrorId
Error number if an error has occurred.
nErrorCnt
Number of transmission attempts that have returned faults.

Description

The FB_WriteBoolOnDelta() function block checks cyclically whether the value at the bSignal input has changed. The cycle time within which the check is carried out is specified by the parameter tCycleTime. If 0 seconds is given for tCycleTime, the input signal is examined during every PLC cycle. If a change is detected, the value of the signal is sent to the ADS device that is to be specified. The receiver is addressed by means of the AMS-NetId and the port number (see also ADS Device Identification). The position within the receiver is specified by the index group/index offset or by the symbol name. Usually this is the input image or the flags area.
If the bEnable input is set to FALSE, no further signal transmission is carried out.

Development environment | Target system type | PLC libraries to be linked
TwinCAT v2.8.0 Build > 733 | BC9000 (165) | TcDataExchangeBC.Lb6


FB_WriteByteOnDelta

FUNCTION_BLOCK FB_WriteByteOnDelta

Event-driven writing of a variable of type BYTE.

Interface

VAR_INPUT
    bEnable          :  BOOL := FALSE;
    sNetId           :  T_AmsNetId;
    nPort            :  T_AmsPort;
    nIdxGrp          :  UDINT;
    nIdxOffs         :  UDINT;
    sVarName         :  STRING;
    nSignal          :  BYTE;
    nLowerLimit      :  BYTE;
    nUpperLimit      :  BYTE;
    tCycleTime       :  TIME := t#0s;
    bSendNow         :  BOOL;
END_VAR

VAR_OUTPUT
    bBusy            :  BOOL := FALSE;
    nLastSignal      :  BYTE;
    bError           :  BOOL := FALSE;
    nErrorId         :  UDINT := 0;
    nErrorCnt        :  UDINT := 0;
END_VAR

Parameters

Inputs

bEnable
Enable block.
sNetId
AMS-NetId of the ADS device to which the value is to be transmitted.
nPort
AMS- port number of the ADS device to which the value is to be transmitted.
nIdxGrp
Index group within the ADS device into which the value is to be transmitted.
nIdxOffs
Index offset within the ADS device into which the value is to be transmitted.
sVarName
Symbol name within the ADS device into which the value is to be transmitted.
nSignal
Variable whose value is to be transmitted.
nLowerLimit
Lower limit value.
nUpperLimit
Upper limit value.
tCycleTime
Cycle period in which the input signal is examined to see whether it has exceeded the limit values.
bSendNow
The value is transmitted immediately in response to a rising edge.

Outputs

bBusy
Transmission is active.
nLastSignal
Most recently transmitted value.
bError
An error occurred during the transmission.
nErrorId
Error number if an error has occurred.
nErrorCnt
Number of transmission attempts that have returned faults.

Description

The FB_WriteByteOnDelta() function block checks cyclically whether the value at the nSignal input has changed. The cycle time within which the check is carried out is specified by the parameter tCycleTime. If 0 seconds is given for tCycleTime, the input signal is examined during every PLC cycle. If the comparison establishes that the current value is greater than nUpperLimit or lower than the value nLowerLimit, then the value is sent to the ADS device that is to be specified. The receiver is addressed by means of the AMS-NetId and the port number (see also ADS Device Identification). The position within the receiver is specified by the index group/index offset or by the symbol name. Usually this is the input image or the flags area.
If the bEnable input is set to FALSE, no further signal transmission is carried out.

Development environment | Target system type | PLC libraries to be linked
TwinCAT v2.8.0 Build > 733 | BC9000 (165) | TcDataExchangeBC.Lb6


FB_WriteWordOnDelta

FUNCTION_BLOCK FB_WriteWordOnDelta

Event-driven writing of a variable of type WORD.

Interface

VAR_INPUT
    bEnable          :  BOOL := FALSE;
    sNetId           :  T_AmsNetId;
    nPort            :  T_AmsPort;
    nIdxGrp          :  UDINT;
    nIdxOffs         :  UDINT;
    sVarName         :  STRING;
    nSignal          :  WORD;
    nLowerLimit      :  WORD;
    nUpperLimit      :  WORD;
    tCycleTime       :  TIME := t#0s;
    bSendNow         :  BOOL;
END_VAR

VAR_OUTPUT
    bBusy            :  BOOL := FALSE;
    nLastSignal      :  WORD;
    bError           :  BOOL := FALSE;
    nErrorId         :  UDINT := 0;
    nErrorCnt        :  UDINT := 0;
END_VAR

Parameters

Inputs

bEnable
Enable block.
sNetId
AMS-NetId of the ADS device to which the value is to be transmitted.
nPort
AMS- port number of the ADS device to which the value is to be transmitted.
nIdxGrp
Index group within the ADS device into which the value is to be transmitted.
nIdxOffs
Index offset within the ADS device into which the value is to be transmitted.
sVarName
Symbol name within the ADS device into which the value is to be transmitted.
nSignal
Variable whose value is to be transmitted.
nLowerLimit
Lower limit value.
nUpperLimit
Upper limit value.
tCycleTime
Cycle period in which the input signal is examined to see whether it has exceeded the limit values.
bSendNow
The value is transmitted immediately in response to a rising edge.

Outputs

bBusy
Transmission is active.
nLastSignal
Most recently transmitted value.
bError
An error occurred during the transmission.
nErrorId
Error number if an error has occurred.
nErrorCnt
Number of transmission attempts that have returned faults.

Description

The FB_WriteWordOnDelta() function block checks cyclically whether the value at the nSignal input has changed. The cycle time within which the check is carried out is specified by the parameter tCycleTime. If 0 seconds is given for tCycleTime, the input signal is examined during every PLC cycle. If the comparison establishes that the current value is greater than nUpperLimit or lower than the value nLowerLimit, then the value is sent to the ADS device that is to be specified. The receiver is addressed by means of the AMS-NetId and the port number (see also ADS Device Identification). The position within the receiver is specified by the index group/index offset or by the symbol name. Usually this is the input image or the flags area.
If the bEnable input is set to FALSE, no further signal transmission is carried out.

Development environment | Target system type | PLC libraries to be linked
TwinCAT v2.8.0 Build > 733 | BC9000 (165) | TcDataExchange.Lib


FB_WriteDWordOnDelta

FUNCTION_BLOCK FB_WriteDWordOnDelta

Event-driven writing of a variable of type DWORD.

Interface

VAR_INPUT
    bEnable          :  BOOL := FALSE;
    sNetId           :  T_AmsNetId;
    nPort            :  T_AmsPort;
    nIdxGrp          :  UDINT;
    nIdxOffs         :  UDINT;
    sVarName         :  STRING;
    nSignal          :  DWORD;
    nLowerLimit      :  DWORD;
    nUpperLimit      :  DWORD;
    tCycleTime       :  TIME := t#0s;
    bSendNow         :  BOOL;
END_VAR

VAR_OUTPUT
    bBusy            :  BOOL := FALSE;
    nLastSignal      :  DWORD;
    bError           :  BOOL := FALSE;
    nErrorId         :  UDINT := 0;
    nErrorCnt        :  UDINT := 0;
END_VAR

Parameters

Inputs

bEnable
Enable block.
sNetId
AMS-NetId of the ADS device to which the value is to be transmitted.
nPort
AMS- port number of the ADS device to which the value is to be transmitted.
nIdxGrp
Index group within the ADS device into which the value is to be transmitted.
nIdxOffs
Index offset within the ADS device into which the value is to be transmitted.
sVarName
Symbol name within the ADS device into which the value is to be transmitted.
nSignal
Variable whose value is to be transmitted.
nLowerLimit
Lower limit value.
nUpperLimit
Upper limit value.
tCycleTime
Cycle period in which the input signal is examined to see whether it has exceeded the limit values.
bSendNow
The value is transmitted immediately in response to a rising edge.

Outputs

bBusy
Transmission is active.
nLastSignal
Most recently transmitted value.
bError
An error occurred during the transmission.
nErrorId
Error number if an error has occurred.
nErrorCnt
Number of transmission attempts that have returned faults.

Description

The FB_WriteDWordOnDelta() function block checks cyclically whether the value at the nSignal input has changed. The cycle time within which the check is carried out is specified by the parameter tCycleTime. If 0 seconds is given for tCycleTime, the input signal is examined during every PLC cycle. If the comparison establishes that the current value is greater than nUpperLimit or lower than the value nLowerLimit, then the value is sent to the ADS device that is to be specified. The receiver is addressed by means of the AMS-NetId and the port number (see also ADS Device Identification). The position within the receiver is specified by the index group/index offset or by the symbol name. Usually this is the input image or the flags area.
If the bEnable input is set to FALSE, no further signal transmission is carried out.

Development environment | Target system type | PLC libraries to be linked
TwinCAT v2.8.0 Build > 733 | BC9000 (165) | TcDataExchangeBC.Lb6


FB_WriteRealOnDelta

FUNCTION_BLOCK FB_WriteRealOnDelta

Event-driven writing of a variable of type REAL.

Interface

VAR_INPUT
    bEnable          :  BOOL := FALSE;
    sNetId           :  T_AmsNetId;
    nPort            :  T_AmsPort;
    nIdxGrp          :  UDINT;
    nIdxOffs         :  UDINT;
    sVarName         :  STRING;
    fSignal          :  REAL;
    fLowerLimit      :  REAL;
    fUpperLimit      :  REAL;
    tCycleTime       :  TIME := t#0s;
    bSendNow         :  BOOL;
    bSwapLowHighWord :  BOOL := FALSE;
END_VAR

VAR_OUTPUT
    bBusy            :  BOOL := FALSE;
    fLastSignal      :  REAL;
    bError           :  BOOL := FALSE;
    nErrorId         :  UDINT := 0;
    nErrorCnt        :  UDINT := 0;
END_VAR

Parameters

Inputs

bEnable
Enable block.
sNetId
AMS-NetId of the ADS device to which the value is to be transmitted.
nPort
AMS- port number of the ADS device to which the value is to be transmitted.
nIdxGrp
Index group within the ADS device into which the value is to be transmitted.
nIdxOffs
Index offset within the ADS device into which the value is to be transmitted.
sVarName
Symbol name within the ADS device into which the value is to be transmitted.
fSignal
Variable whose value is to be transmitted.
fLowerLimit
Lower limit value.
fUpperLimit
Upper limit value.
tCycleTime
Cycle period in which the input signal is examined to see whether it has exceeded the limit values.
bSendNow
The value is transmitted immediately in response to a rising edge.
bSwapLowHighWord
The least significant WORD and the most significant WORD are swapped.

Outputs

bBusy
Transmission is active.
fLastSignal
Most recently transmitted value.
bError
An error occurred during the transmission.
nErrorId
Error number if an error has occurred.
nErrorCnt
Number of transmission attempts that have returned faults.

Description

The FB_WriteRealOnDelta() function block checks cyclically whether the value at the fSignal input has changed. The cycle time within which the check is carried out is specified by the parameter tCycleTime. If 0 seconds is given for tCycleTime, the input signal is examined during every PLC cycle. If the comparison establishes that the current value is greater than fUpperLimit or lower than the value fLowerLimit, then the value is sent to the ADS device that is to be specified. The receiver is addressed by means of the AMS-NetId and the port number (see also ADS Device Identification). The position within the receiver is specified by the index group/index offset or by the symbol name. Usually this is the input image or the flags area.
The internal representation of floating point numbers differs according to the hardware being used. Whereas Intel use the "little-endian" format, Motorola-based hardware employs the "big-endian" format. The input variable bSwapLowHighWord can be used to make the necessary adjustment in order to be able to exchange floating point numbers. This is necessary, for instance, if floating point numbers need to be exchanged between the TwinCAT PLC running on a PC and a BC9000.
If the bEnable input is set to FALSE, no further signal transmission is carried out.

Development environment | Target system type | PLC libraries to be linked
TwinCAT v2.8.0 Build > 733 | BC9000 (165) | TcDataExchangeBC.Lb6


FB_CheckWatchdog

FUNCTION_BLOCK FB_CheckWatchdog

Monitoring a watchdog signal transmitted by the FB_WriteWatchdog() block.

Interface

VAR_INPUT
    bEnable          :  BOOL := FALSE;
    tWatchdogTime    :  TIME := t#0s;
    nCnt             :  UDINT;
END_VAR

VAR_OUTPUT
    bWatchdog        :  BOOL := FALSE;
    nLastCnt         :  UDINT;
END_VAR

Parameters

Inputs

bEnable
Enable block.
tWatchdogTime
Period of time within which nCnt should change.
nCnt
Current counter state of the watchdog signal

Outputs

bWatchdog
FALSE indicates a valid monitoring signal. The output will become TRUE if no change is detected in nCnt during the period of time specified by tWatchdogTime.
nLastCnt
Most recent successfully transmitted counter state of the monitoring signal.

Description

The device to be monitored regularly transmits a changing counter state to the device that is to check the transmission. The function block FB_CheckWatchdog() is used there to monitor the state of the counter. If this does not change within a specific period, the bWatchdog output is set to TRUE. If a value of 0 seconds is specified for tWatchdogTime, the bWatchdog signal is set to FALSE. The period specified by tWachtdogTime should be a multiple (5-10 times) of the time in which the monitoring signal is transmitted.

Development environment | Target system type | PLC libraries to be linked
TwinCAT v2.8.0 Build > 733 | BC9000 (165) | TcDataExchangeBC.Lb6


FB_WriteWatchdog

FUNCTION_BLOCK FB_WriteWatchdog

Writing a watchdog signal to another ADS device (TwinCAT PLC, Bus Terminal Controller, ...).

Interface

VAR_INPUT
    bEnable          :  BOOL := FALSE;
    sNetId           :  T_AmsNetId;
    nPort            :  T_AmsPort;
    nIdxGrp          :  UDINT;
    nIdxOffs         :  UDINT;
    sVarName         :  STRING;
    tWatchdogTime    :  TIME := t#0s;
    bSendNow         :  BOOL;
END_VAR

VAR_OUTPUT
    bBusy            :  BOOL := FALSE;
    nLastCnt         :  UDINT := 0;
    bError           :  BOOL := FALSE;
    nErrorId         :  UDINT := 0;
END_VAR

Parameters

Inputs

bEnable
Enable block.
sNetId
AMS-NetId of the ADS device to which the watchdog signal is to be transmitted.
nPort
AMS port number of the ADS device to which the watchdog signal is to be transmitted.
nIdxGrp
Index group within the ADS device into which the watchdog signal is to be transmitted.
nIdxOffs
Index offset within the ADS device into which the watchdog signal is to be transmitted.
sVarName
Symbol name within the ADS device into which the watchdog signal is to be transmitted.
tWatchdogTime
Cycle time with which the watchdog signal is to be transmitted.
bSendNow
The watchdog signal is transmitted immediately in response to a rising edge.

Outputs

bBusy
Transmission is active.
nLastCnt
Most recently transmitted counter state.
bError
An error occurred during the transmission.
nErrorId
Error number if an error has occurred.

Description

The FB_WriteWatchdog() function block cyclically writes the contents of a 32-bit counter into another ADS device. The counter is incremented every time the transmission is successful. The FB_CheckWatchdog() function block can be used at the receiver to evaluate this signal. The receiver is addressed by means of the AMS-NetId and the port number (see also ADS Device Identification). The position within the receiver is specified by the index group/index offset or by the symbol name. Usually this is the input image or the flags area.
The period for tWachtdogTime should not be shorter than 1 second, to avoid transmitting the counter state too frequently. If 0 seconds is given for tWatchdogTime, the signal is not transmitted. Please also note the description of the FB_CheckWatchdog() block. If the bEnable input is set to FALSE, no further transmission of the watchdog signal is carried out.

Development environment | Target system type | PLC libraries to be linked
TwinCAT v2.8.0 Build > 733 | BC9000 (165) | TcDataExchangeBC.Lb6


FB_WriteLRealOnDelta

FUNCTION_BLOCK FB_WriteLRealOnDelta

Event-driven writing of a variable of type LREAL.

Interface

VAR_INPUT
    bEnable          :  BOOL := FALSE;
    sNetId           :  T_AmsNetId;
    nPort            :  T_AmsPort;
    nIdxGrp          :  UDINT;
    nIdxOffs         :  UDINT;
    sVarName         :  STRING;
    fSignal          :  LREAL;
    fLowerLimit      :  LREAL;
    fUpperLimit      :  LREAL;
    tCycleTime       :  TIME := t#0s;
    bSendNow         :  BOOL;
END_VAR

VAR_OUTPUT
    bBusy            :  BOOL := FALSE;
    fLastSignal      :  LREAL;
    bError           :  BOOL := FALSE;
    nErrorId         :  UDINT := 0;
    nErrorCnt        :  UDINT := 0;
END_VAR

Parameters

Inputs

bEnable
Enable block.
sNetId
AMS-NetId of the ADS device to which the value is to be transmitted.
nPort
AMS- port number of the ADS device to which the value is to be transmitted.
nIdxGrp
Index group within the ADS device into which the value is to be transmitted.
nIdxOffs
Index offset within the ADS device into which the value is to be transmitted.
sVarName
Symbol name within the ADS device into which the value is to be transmitted.
fSignal
Variable whose value is to be transmitted.
fLowerLimit
Lower limit value.
fUpperLimit
Upper limit value.
tCycleTime
Cycle period in which the input signal is examined to see whether it has exceeded the limit values.
bSendNow
The value is transmitted immediately in response to a rising edge.

Outputs

bBusy
Transmission is active.
fLastSignal
Most recently transmitted value.
bError
An error occurred during the transmission.
nErrorId
Error number if an error has occurred.
nErrorCnt
Number of transmission attempts that have returned faults.

Description

The FB_WriteLRealOnDelta() function block checks cyclically whether the value at the fSignal input has changed. The cycle time within which the check is carried out is specified by the parameter tCycleTime. If 0 seconds is given for tCycleTime, the input signal is examined during every PLC cycle. If the comparison establishes that the current value is greater than fUpperLimit or lower than the value fLowerLimit, then the value is sent to the ADS device that is to be specified. The receiver is addressed by means of the AMS-NetId and the port number (see also ADS Device Identification). The position within the receiver is specified by the index group/index offset or by the symbol name. Usually this is the input image or the flags area.
If the bEnable input is set to FALSE, no further signal transmission is carried out.

Development environment | Target system type | PLC libraries to be linked
TwinCAT v2.8.0 Build > 733 | BC9000 (165) | TcDataExchangeBC.Lb6