Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

SEMA function in standard.lib

foby
2016-01-10
2016-01-11
  • foby - 2016-01-10

    Hey,

    I have a questing concerning the SEMA function in Standard.lib

    SemaInstance.BUSY becomes true when the SEMA function is called with CLAIM := true, but this only after the second cycle. Not the first.

    Does anybody knows if this is normal?

    Declarations:

    PROGRAM PLC_PRG
    VAR
    Β  Β SemaInstance : SEMA; Β  Β Β  Β (* instance van SEMA in standard.lid *)
    Β  Β xVar1: BOOL;
    Β  Β xVar2: BOOL;
    Β  Β xVar3: BOOL;
    END_VAR
    

    Program:

    SemaInstance(CLAIM := xVar1, RELEASE := xVar2);
    xVar3 := SemaInstance.BUSY;
    
     
  • shooter - 2016-01-11

    BUSY = SEMA(CLAIM, RELEASE) means:

    BUSY := X;

    IF CLAIM THEN X:=TRUE;

    ELSE IF RELEASE THEN BUSY := FALSE; X:= FALSE;

    END_IF

    (from manual)
    meaning the busy output is starting with FALSE (normal as default of all bools is false.
    now when claim gets TRUE the busy stays FALSE, as it is defined above the claim.
    the next round it sees x TRUE so busy gets also TRUE.

    think of a semaphore, the signal only gets red after the train is passed, if you would arrive at the signal and claim it the signal would change from green to red immediately, so the driver has no time to pass the signal.
    as the block is public you can change it to what you like, or try the oscat.lib as it has many FBC for all types of functions.

     
  • foby - 2016-01-11

    Thanks

     

Log in to post a comment.