chInit (Function)

Top  Previous  Next

Architecture:

X32 / NX32 / NX32L

Firmware version:

1.00 / 1.00.00


The" chInit()" function will initialize a CHANNEL variable with the specified maximum number of messages.

The chInit() function must be called before any other operation on the channel can be performed.

 

Input:

msgmax : INT

Maximum number of messages that can be present in the channel before the chWrite() function will block.

 

Returns: CHANNEL

The initialized channel.

 

Declaration:

FUNCTION chInit : CHANNEL;
VAR_INPUT
   msgmax : INT;
END_VAR;

 

 

Example:

INCLUDE rtcu.inc
 
VAR_INPUT
   al_1 : BOOL R_EDGE;
   al_2 : BOOL R_EDGE;
END_VAR;
 
VAR
   chalarm : CHANNEL;
END_VAR;
 
// SMS thread 
THREAD_BLOCK smsalarm;
VAR
   alarmno : SINT;
END_VAR;
 
WHILE TRUE DO
   chRead(ch:=chalarm,msg:=ADDR(alarmno),lenmax:=SIZEOF(alarmno));
   gsmSendSMS(phonenumber := "22448899", message := strFormat(format:="Alarm. Door \1", v1:=alarmno));
END_WHILE;
 
END_THREAD_BLOCK;
 
 
PROGRAM test;
VAR
   smshandler : smsalarm;
   alarm      : sint;
END_VAR;
 
//main thread
chalarm := chInit(msgMax:=10);
smshandler();
gsmPower(power := TRUE);
BEGIN
   IF al_1 THEN
      alarm:=1;
      chWrite(ch:=chalarm,msg:=ADDR(alarm),len:=SIZEOF(alarm));
   END_IF;
   IF al_2 THEN
      alarm:=2;
      chWrite(ch:=chalarm,msg:=ADDR(alarm),len:=SIZEOF(alarm));
   END_IF;
END;
 
END_PROGRAM;