Event Detection FUNCTION_BLOCKS
This function blocks will be used to detect value changes at the variables of an IEC-server. Different events can be detected at a variable. The block can also be used to send a reporting frame to a client.
Therefore the corresponding variables in a Report Control Block need to be available as a reference.
This form of function blocks exists for every IEC-data type in the TcACSI.lib. As the function blocks only differ from this data type there is an overview of the function blocks on this page where some of them are described.
Every function block offers three actions:
- A_SetValue: Sets a value in the IEC data structure and informs the server-block that the value of a data attribute has been described with a new or the same value (UPDATE or CHANGE). That is the only way how the server block can detect that he needs to generate a reporting for this data attribute. A reporting only can be generated if this attribute has been configurated in the corresponding dataset of the Report-Control-Block.
- A_GetEvent: Identifies if a client has changed or read a data attribute in the IEC-data structure. Now these events can be detected: ACSI_EVENT_WRITE, ACSI_EVENT_READ, ACSI_EVENT_UPDATE, ACSI_EVENT_CHANGE. A_GetEvent is used in combination with A_ClearEvent.
- A_ClearEvent: Sets back a detected event, so that the next change can be detected.
| A_SetValue | A_GetEvent | A_ClearEvent |
---|---|---|---|
value, bits, or octets | The new attribute value that should be written | Is not used | Is not used |
event_ctrl | Reserved for future applications and should be zero (0) | Is not used | Defines which event should be resetted/accepted. Multiple events can be resetted with one call. The following values can be "wired-OR": ACSI_EVENT_WRITE, ACSI_EVENT_READ, ACSI_EVENT_UPDATE, ACSI_EVENT_CHANGE. To set back all the values at the same time you can use the value 0xFFFFFFFF. |
event_ind | This variable is a bitmask. Every bit is equivalent to an event. An event applies when the corresponding bit will be set. | This variable is a bitmask. Every bit is equivalent to an event. An event applies when the corresponding bit will be set. | This variable is a bitmask. Every bit is equivalent to an event. An event applies when the corresponding bit will be set. |
event_cnf | Reserved for future applications and is not used now | Reserved for future applications and is not used now | Reserved for future applications and is not used now |
Function blocks with interface "value":
FB_ACSI_BOOLEAN ⇒ BOOLEAN
FB_ACSI_INT8 ⇒ INT8
FB_ACSI_INT16 ⇒ INT16
FB_ACSI_INT32 ⇒ INT32
FB_ACSI_INT64 ⇒ INT64
FB_ACSI_INT128 ⇒ INT128
FB_ACSI_UINT8 ⇒ UINT8
FB_ACSI_UINT16 ⇒ UINT16
FB_ACSI_UINT32 ⇒ UINT32
FB_ACSI_UINT64 ⇒ UINT64
FB_ACSI_UINT128 ⇒ UINT128
FB_ACSI_FLOAT32 ⇒ FLOAT32
FB_ACSI_FLOAT64 ⇒ FLOAT64
FB_ACSI_ENUMERATED ⇒ ENUMERATED
FB_ACSI_VISIBLESTRING255 ⇒ VISIBLESTRING255
FB_ACSI_UNICODESTRING255 ⇒ UNICODESTRING64
FB_ACSI_ENTRYTIME ⇒ ENTRYTIME
FB_ACSI_TIMESTAMP ⇒ TIMESTAMP
FB_ACSI_ENTRYID ⇒ ENTRYID
FB_ACSI_QUALITY ⇒ QUALITY
FB_ACSI_TRIGGERCON ⇒ TRIGGERCON
FB_ACSI_OPTIONFLDS ⇒ OPTIONFLDS
Function block FB_ACSI_BOOLEAN:
VAR_IN_OUT
VAR_IN_OUT
attr : T_ACSI_BOOLEAN; (* ACSI attribute; It depends on the data type *)END_VAR
attr: Is the attribute of the IEC-standard from the corresponding data type.
VAR_INPUT
VAR_INPUT
event_ctrl : DWORD := 16#FFFFFFFF;(* Event control mask (used by A_ClearEvent), default: clear all events *)
value : BOOL;(* New value to set; The data type depends on the Function Block *)
END_VAR
event_ctrl: See chart above.
value: See chart above.
VAR_OUTPUT
VAR_OUTPUT
bOk : BOOL;(* TRUE = Success, FALSE = Access failed *)
event_ind : DWORD := 16#00000000;(* Event indication bits, bit set => event indication, bit reset => no event indication *)
event_cnf : DWORD := 16#FFFFFFFF;(* Event confirmation bits, bit set => event confirmed, bit reset => waiting for event confirmation *)
END_VAR
bOk: If this value is TRUE, no errors appeared, and the editing can go on. If it is FALSE an error exists.
event_ind: See chart above.
event_cnf: See chart above.
Example:
In the following example the use of A_SetValue, A_GetEvent and A_ClearEvent will be shown.
PROGRAM MAIN
VAR
dataCtrl : ST_ACSI_DATACTRL; bValue : T_ACSI_BOOLEAN; (* Value from the data type BOOLEAN *)
END_VAR
---------------------(* Read Value *)
ctrl.BOOLEAN.A_GetEvent(attr := IEDRelay.XCBR1.BlkCls.stVal, event_ctrl := 0);
IF ctrl.BOOLEAN.bOk THEN (* Detect when value is written (check the event_ind bits )*)IF (ctrl.BOOLEAN.event_ind AND ACSI_EVENT_WRITE) = ACSI_EVENT_WRITE THEN
write_bool_counter := write_bool_counter + 1;
END_IF(* Detect when value is read (check the event_ind bits) *)IF (ctrl.BOOLEAN.event_ind AND ACSI_EVENT_READ) = ACSI_EVENT_READ THEN
read_bool_counter := read_bool_counter + 1;
END_IF(* clear events (is necessary to detect the next event)*)
ctrl.BOOLEAN.A_ClearEvent(attr := IEDRelay.XCBR1.BlkCls.stVal, event_ctrl := ACSI_EVENT_WRITE OR ACSI_EVENT_READ);(* clear read and write events *)END_IF
---------------------(* Write value *)
dataCtrl.BOOLEAN.A_SetValue(attr :=IEDDevice.XCBR1.SumSwARs.actVal, value := bValue.value, event_ctrl := 0);
Function block with Interface "bits":
FB_ACSI_CODEDENUM8 ⇒ CODEDENUM8
FB_ACSI_CODEDENUM16 ⇒ CODEDENUM16
FB_ACSI_CODEDENUM32 ⇒ CODEDENUM32
FB_ACSI_CODEDENUM64 ⇒ CODEDENUM64
FB_ACSI_CODEDENUM128 ⇒ CODEDENUM128
Function block FB_ACSI_CODEDENUM8:
VAR_IN_OUT
VAR_IN_OUT
attr : T_ACSI_CODEDENUM8; (* ACSI attribute; It depends on the data type *)END_VAR
attr: Is the attribute of the IEC-standard from the corresponding data type.
VAR_INPUT
VAR_INPUT
event_ctrl : DWORD := 16#FFFFFFFF;(* Event control mask (used by A_ClearEvent), default: clear all events *)
bits : ARRAY[0..0] OF BYTE := 1(0); (* New value to set; The data type depends on the Function Block *)
END_VAR
event_ctrl: See chart above.
bits: See chart above.
VAR_OUTPUT
VAR_OUTPUT
bOk : BOOL;(* TRUE = Success, FALSE = Access failed *)
event_ind : DWORD := 16#00000000;(* Event indication bits, bit set => event indication, bit reset => no event indication *)
event_cnf : DWORD := 16#FFFFFFFF;(* Event confirmation bits, bit set => event confirmed, bit reset => waiting for event confirmation *)
END_VAR
bOk: If this value is TRUE, no errors appeared, and the editing can go on. If it is FALSE an error exists.
event_ind: See chart above.
event_cnf: See chart above.
Function block with Interface "octets":
FB_ACSI_OCTETSTRING8 ⇒ OCTETSTRING8
FB_ACSI_OCTETSTRING16 ⇒ OCTETSTRING16
FB_ACSI_OCTETSTRING32 ⇒ OCTETSTRING32
FB_ACSI_OCTETSTRING64 ⇒ OCTETSTRING64
Function block FB_ACSI_OCTETSTRING8:
VAR_IN_OUT
VAR_IN_OUT
attr : T_ACSI_OCTETSTRING8; (* ACSI attribute; It depends on the data type *)END_VAR
attr: Is the attribute of the IEC-standard from the corresponding data type.
VAR_INPUT
VAR_INPUT
event_ctrl : DWORD := 16#FFFFFFFF;(* Event control mask (used by A_ClearEvent), default: clear all events *)
octets : ARRAY[0..7] OF BYTE := 8(0);(* OCTETS: 8 byte; New value to set; The data type depends on the Function Block *)
END_VAR
event_ctrl: See chart above.
bits: See chart above.
VAR_OUTPUT
VAR_OUTPUT
bOk : BOOL;(* TRUE = Success, FALSE = Access failed *)
event_ind : DWORD := 16#00000000;(* Event indication bits, bit set => event indication, bit reset => no event indication *)
event_cnf : DWORD := 16#FFFFFFFF;(* Event confirmation bits, bit set => event confirmed, bit reset => waiting for event confirmation *)
END_VAR
bOk: If this value is TRUE, no errors appeared, and the editing can go on. If it is FALSE an error exists.
event_ind: See chart above.
event_cnf: See chart above.
Requirements
Development environment | Target system | PLC libraries to be included |
---|---|---|
TwinCAT v2.10.0 Build >= 1340 | PC or CX (x86, ARM) | TcACSI.Lib |