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;
...
WHILE chStatus(ch:=ch) > -1 DO
len := chPeek(ch:=ch,msg:=ADDR(buf),lenmax:=SIZEOF(buf));
IF len > 0 THEN
IF buf[1] = id THEN
chRead(ch:=ch,msg:=ADDR(buf),lenmax:=SIZEOF(buf));
...
END_IF;
END_IF;
...
END_WHILE;
END_THREAD_BLOCK;
|