chStatus (Function)

Top  Previous  Next

Architecture:

X32 / NX32 / NX32L

Firmware version:

1.00 / 1.00.00


The "chStatus()" function will return the status of the specified channel.

If the specified channel has been initialized, the chStatus() function will return the current number of messages.

 

 

Input:

ch : CHANNEL

The channel to query.

 

Returns: INT

-1

Channel is not initialized.

>0

Number of messages in the channel.

 

Declaration:

FUNCTION chStatus : INT;
VAR_INPUT
   ch : CHANNEL;
END_VAR;

 

 

Example:

THREAD_BLOCK Thread;
VAR_INPUT
   ch : CHANNEL;
   id : SINT;
   ...
END_VAR;
VAR
   buf : ARRAY[1..30] OF SINT;
   len : INT;
   ...
END_VAR;
   ...
   // Do while channel initialized
   WHILE chStatus(ch:=ch) > -1 DO
      // peek at data
      len := chPeek(ch:=ch,msg:=ADDR(buf),lenmax:=SIZEOF(buf));
      IF len > 0 THEN
         // Is package sent to me?
         IF buf[1] = id THEN
            // Read data
            chRead(ch:=ch,msg:=ADDR(buf),lenmax:=SIZEOF(buf));
            // Act on data
            ...
         END_IF;
      END_IF;
      ...
   END_WHILE;
END_THREAD_BLOCK;