rfbcSwitchEventReceive (Function)

Top  Previous  Next

Architecture:

X32 / NX32L

Device support:

AX9 pro, CX1 pro/pro-c/warp/warp-c, SX1, AX9 turbo, NX-900, LX5

Firmware version:

2.60 / 1.51.00


This function will return details about the last switch notification event received.

To get the ID of the sender related to the event, please call rfbcWaitEvent before this function.

 

Note: many switches will send a notification with channel ID "0" when rebooted/powered on.

 

 

Input:

None.

 

Output:

ch : SINT

The channel on the switch which has been changed.

If the channel is "0" (zero), then it is a wake-up event notifying about the fact that the switch has been without power.

 

state : BOOL

TRUE/ON

-

On notification.

FALSE/OFF

-

Off notification.

 

Returns: INT

0

-

Ok. Event cleared.

-1

-

Interface is not open (see rfbcOpen).

-4

-

RF communication is not available.

-5

-

Event is not present.

 

Declaration:

FUNCTION rfbcSwitchEventReceive : INT;
VAR_INPUT
  ch   : ACCESS SINT;
  state : ACCESS BOOL;
END_VAR;

 

Example:

INCLUDE rtcu.inc
 
//-----------------------------------------------------------------------------
// FUNCTION GetSwitchEvent
//-----------------------------------------------------------------------------
FUNCTION GetSwitchEvent;
VAR_INPUT
  id     : DINT;
END_VAR;
VAR
  ch    : SINT;
  state : BOOL;
END_VAR;
rfbcSwitchEventReceive(ch := ch, state := state);
IF ch = 0 THEN
  DebugFmt(message := "Switch \4 is powered on.", v4 := id);
ELSIF state THEN
  DebugFmt(message := "Channel \1 on switch \4 is powered on.", v4 := id, v1 := ch);
ELSE
  DebugFmt(message := "Channel \1 on switch \4 is powered off.", v4 := id, v1 := ch);
END_IF;
END_FUNCTION;
 
//-----------------------------------------------------------------------------
// THREAD_BLOCK rfbcMonitor
//-----------------------------------------------------------------------------
THREAD_BLOCK rfbcMonitor;
VAR
  event       : INT := 0;
  hisId       : DINT;
  broadcast   : BOOL;
END_VAR;
 
WHILE event <> -1 DO
  event := rfbcWaitEvent(timeout := -1, id := hisId, broadcast := broadcast);
  CASE event OF
    ...
    6 : GetSwitchEvent(id := hisId);
    ...
  ELSE
    DebugFmt(message := "rfbcWaitEvent - event=\1", v1 := event);
  END_CASE;
END_WHILE;
END_THREAD_BLOCK;