semValue (Function)

Top  Previous  Next

Architecture:

X32 / NX32 / NX32L

Device support:

ALL

Firmware version:

1.00 / 1.00.00


The semValue() function will return the current value of the specified semaphore.

 

 

Input:

sem : SEMAPHORE

The semaphore to query.                

 

Returns: INT

-1

Semaphore not initialized.

>=0

Value of the semaphore.

 

Declaration:

FUNCTION semValue : INT;
VAR_INPUT
  sem : SEMAPHORE;
END_VAR;

 

 

Example:

INCLUDE rtcu.inc
 
VAR
  sem : SEMAPHORE;
END_VAR;
 
PROGRAM test;
  ...
  // Initialize Semaphore
  sem := semInit(initval:=3);
  IF semValue(sem:=sem) = -1 THEN DebugMsg(message:="sem failed to init!"); END_IF;
  ...
BEGIN
  ...
  // Wait until resource is free or timeout
  IF semWait(sem:=sem,timeout:=1000) = 0 THEN
    // Only do these actions if we have access to the resource
     ...
    // Free the resource after use
    semSignal(sem:=sem);
  END_IF;
  ...
END;
 
END_PROGRAM;