rfbcWaitEvent (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 wait until an event is raised. It has an optional timeout.

 

An event is a notification that something has happened in the RFBC interface.

There are three types of events:

1.        Unknown: a message which could not be processed was received. No acknowledgment has been sent.

2.        Notification: a message broadcasted from another device. No acknowledgment has been sent.

3.        Requests/updates: a message addressed to this device. The device will process and acknowledge according to current configuration (see rfbcGetConfig/rfbcSetConfig).

 

The events are queued until appropriate action is taken as described in this table:

 

Event#

Event

Type

Action

1

An unknown message was received.

1

None.

2

A pair request was received.

3

Call rfbcPairRequestReceive.

4

A remote control event was received.

2/3

Call rfbcRemoteControlEventReceive.

5

A sensor notification was received.

2/3

Call rfbcSensorEventReceive.

6

A switch notification was received.

2/3

Call rfbcSwitchEventReceive.

7

A temperature notification was received.

2/3

Call rfbcTemperatureEventReceive.

100

A raw event notification was received.

2/3

Call rfbcRawEventReceive.

 

Only a single event of the type 2 and 3 can be handled at a time. This means that if the appropriate action is not taken, rfbcWaitEvent will continue to report the same event.

 

Note: waiting for an event using this function will block the calling thread.

 

 

Input:

timeout : INT (-1,0..32000) (default -1)

Timeout period in milliseconds to wait.

0

-

Disable timeout. The function will return immediately.

-1

-

Wait forever. The function will only return when data is received.

 

Output:

id : DINT

The ID of the sending device. This ID must be used when sending direct requests/notifications to a specific device.

 

broadcast : BOOL

If true, then this message was not sent to a specific device and was therefore not replied with an acknowledgment to confirm the reception.

 

Returns: INT

7

-

A temperature notification was received.

6

-

A switch notification was received.

5

-

A sensor notification was received.

4

-

A remote control event was received.

2

-

A pair request was received.

1

-

An unknown request was received.

0

-

Timeout.

-1

-

Interface is not open (see rfbcOpen).

-4

-

RF communication is not available.

-6

-

Invalid time.

 

Declaration:

FUNCTION rfbcWaitEvent : INT;
VAR_INPUT
  id       : ACCESS DINT;
  timeout  : DINT := -1;
  broadcast: ACCESS BOOL;
END_VAR;

 

Example:

INCLUDE rtcu.inc
 
//-----------------------------------------------------------------------------
// 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
    1   : DebugFmt(message := "Unknown message received from '\4'", v4 := hisId);
    2   : GetPairEvent(id := hisId);
    4   : GetRemoteEvent(id := hisId);
    5   : GetSensorEvent(id := hisId);
    6   : GetSwitchEvent(id := hisId);
    7   : GetTemperatureEvent(id := hisId);
     100 :
        IF NOT broadcast THEN rfbcSendAck(); END_IF;
        GetRawEvent(id := hisId);
  ELSE
    DebugFmt(message := "rfbcWaitEvent - event=\1", v1 := event);
  END_CASE;
END_WHILE;
END_THREAD_BLOCK;