SEMA

SEMA 1:

A Software Semaphore (Interruptible).

VAR_INPUT

VAR_INPUT
    CLAIM   : BOOL; 
    RELEASE : BOOL;
END_VAR

VAR_OUTPUT

VAR_OUTPUT
    BUSY    : BOOL;
END_VAR

If BUSY is TRUE when SEMA is called up, this means that a value has already been assigned to SEMA (SEMA was called up with CLAIM = TRUE). If BUSY is FALSE, SEMA has not yet been called up or it has been released (called up with RELEASE = TRUE).

Internal implementation of fb:

BUSY := X;

IF CLAIM THEN
    X:=TRUE;
ELSIF RELEASE
    THEN
        BUSY := FALSE;
        X:= FALSE;
END_IF

Requirements

Development environment

Target system type

PLC libraries to include

TwinCAT Version >= 2.6.0

PC or CX (x86)

Standard.Lib

TwinCAT Version >= 2.6.0

BC (165)

Standard.Lb6

TwinCAT Version >= 2.9.0

BCxx50 or BX

Standard.lbx

TwinCAT Version >= 2.10.0 Build >= 1301

CX (ARM)

Standard.lib