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® and XFC® 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 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 & Co. KG, 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.


Tc PLC Library: TestAndSet

Overview

This library contains a function that can be used to check and set a boolean flag, without being interrupted by other tasks.

Function

Name | Description
TestAndSet | This function can be used to check and set a boolean flag, without being interrupted by other tasks.

Requirements

Component | Version
TwinCAT on the development PC | 2.10 Build 1335 or higher
TwinCAT on the Windows CE-Image | 2.10 Build 1333 or higher
TwinCAT on the Windows XP-Image | 2.10 Build 1333 or higher


TestAndSet

Tc PLC Library: TestAndSet

FUNCTION TestAndSet : BOOL

The function TestAndSet can be used to check and set a flag, without the possibility to be interrupted by other tasks.

VAR_IN_OUT

VAR_IN_OUT
    Flag : BOOL; (* Flag to check if TRUE or FALSE *)
END_VAR

Flag: Is a boolean flag, tha is being checked
- if it was FALSE, then the flag was available and is being set (to block other tasks), the function returns TRUE
- if it was TRUE, then the flag was blocked, the function returns FALSE

Sample

VAR_GLOBAL
bGlobalTestFlag : BOOL;
END_VAR

VAR
iLocalBlockedCounter : DINT;
END_VAR

IF TestAndSet(bGlobalTestFlag) THEN
(* bGlobalTestFlag was FALSE, nobody was blocking, NOW bGlobalTestFlag is set to TRUE and blocking others *)
(* ... *)
;

(* remove blocking by resetting the flag *)
bGlobalTestFlag := FALSE;
ELSE
(* bGlobalTestFlag was TRUE, somebody is blocking *)
iLocalBlockedCounter := iLocalBlockedCounter + 1;

(* ... *)
;
END_IF