pmWaitEvent (Function)

Top  Previous  Next

Architecture:

X32 / NX32 / NX32L

Device support:

All

Firmware version:

1.00 / 1.00.00


 
This function enters power-saving mode and effectively freezes program execution and waits for one or several of the following events:
 

Change on digital input 1..4.

Change on ignition (please refer to the technical manual of the RTCU).

External power fail.

External power apply.

Vibration sensor.

Timer.

CAN reception.

Serial 0 activity.

Serial 1 activity.

GSM activity.

GPS 2D/3D fix (RTCU SX1 series only).

Intrusion detection (RTCU AX9 turbo only).

Key pressed (RTCU DX4 series and RTCU NX-400 only)

RF activity.

 

When the event(s) happens, the program will continue operation from the location it was called. The polarity (rising or falling edge) of a digital input to wake up from can be set individually for each input. If the vibration sensor is activated, a vibration larger than the threshold set by the pmSetVibrationSensivity will also wake up the RTCU.
 
Like the pmPowerDown function, a timer can be set to wake up the RTCU - the main difference between the pmPowerDown and the pmWaitEvent is that a power down will restart program execution from the start (as a reset) and the WaitForEvent will proceed program execution from where it was called.

 
Please note that the pmWaitEvent does not affect the digital outputs. The user must, if desired, deactivate the outputs before calling pmWaitEvent to reduce the power consumed by the outputs.

 

If the ignition input is selected for wake-up and the input is logical low, a power apply will also wake the RTCU up even if power apply is not selected for wake-up. The return code will be the ignition wake-up code.

 

If the serial port baud rate is higher than 9,600, the RTCU will not be able to receive the transmitted data. However, the RTCU will wake up if there is any activity on the connection, and as soon as the function has returned, the serial functions are operational again.

 

It is not possible to use pmWaitEvent while the on-board battery is fast-charging, and therefore it may be necessary to disable the charger by using batChargerEnable.

 

The pmWaitEvent function will exclude any selected events that are not supported by the RTCU device. If all the selected events are discounted, pmWaitEvent will fail with the error "no events selected". An example could be waiting for a vibration event on a RTCU-DX4 device which does not have vibration detection.

 

On NX32L devices it is also possible to use the pmSuspend function, which supports additional events and low power modes.

 

Note when using GSM event:

Using pmWaitEvent with the GSM event enabled implies that the GSM module must be operating in low power mode. See gsmPowerLP.

When the GSM module is on, the GSM event must be selected when calling pmWaitEvent.

pmWaitEvent with GSM event enabled cannot be used when the GSM module is busy with an active voice or CSD session.

Any GSM event, including minor events such as base station changes, will trigger the wake-up, and it is therefore the responsibility of the application to detect and handle any relevant event at wake-up time.

After handling of the event, or if no relevant event was found, pmWaitEvent can be called again while awaiting the next GSM event.

There is an interval of 15 seconds before pmWaitEvent can be called again while awaiting the next GSM event.

 

 

Input:

Ignition : BOOL (default: FALSE)

The device waits until the ignition input is activated.

 

The actual input depends on the device in question. For example on the RTCU MX2i series it is input 5, and on the RTCU CX1 series it is input 1. Please refer to the technical manual of the RTCU for details.

 

Also note that waiting on an input which is also used for ignition will return the input event and not the ignition event as these are the same.

 

IgnitionFalling : BOOL (default: FALSE)

If TRUE the ignition is activated with a falling edge. If FALSE the ignition is activated with a rising edge.

 

DI1 : BOOL (default: FALSE)

The device waits until digital input 1 is activated.

 

DI1Falling : BOOL (default: FALSE)

If TRUE digital input 1 is activated with a falling edge. If FALSE digital input 1 is activated with a rising edge.

 

DI2 : BOOL (default: FALSE)

The device waits until digital input 2 is activated.

 

DI2Falling : BOOL (default: FALSE)

If TRUE digital input 2 is activated with a falling edge. If FALSE digital input 2 is activated with a rising edge.

 

DI3 : BOOL (default: FALSE)

The device waits until digital input 3 is activated.

 

DI3Falling : BOOL (default: FALSE)

If TRUE digital input 3 is activated with a falling edge. If FALSE digital input 3 is activated with a rising edge.

 

DI4 : BOOL (default: FALSE)

The device waits until digital input 4 is activated.

Note: On the MX2 turbo either DI4 or SER1 must be selected. Both at the same time is unsupported.

 

DI4Falling : BOOL (default: FALSE)

If TRUE digital input 4 is activated with a falling edge. If FALSE digital input 4 is activated with a rising edge.

 

Vibration : BOOL (default: FALSE)

The device waits until vibration is detected (see pmSetVibrationSensivity for adjusting sensitivity).

 

PowerFail : BOOL (default: FALSE)

The device waits until external power is removed.

 

PowerApply : BOOL (default: FALSE)

The device waits until external power is applied.

 

GSM : BOOL (default: FALSE)

The device waits until activity is detected on the GSM modem.

Note: Not supported on the RTCU NX-400.

 

CAN : BOOL (default: FALSE)

The device waits until a message has arrived on the first CAN bus.

The reception of a CAN message is subject to the filtering mechanism. See canFilterCreate().

 

CAN2 : BOOL (default: FALSE)

The device waits until a message has arrived on the second CAN bus.

The reception of a CAN message is subject to the filtering mechanism. See canFilterCreate().

 

Note:

Operating at a CAN speed of 1000 Kbps is not supported on X32/NX32. Failing to observe this will result in a return-code of -3.

NX-400 only supports waiting for CAN messages at a CAN speed of 500 Kbps or 1000 Kbps.

 

SER0 : BOOL (default: FALSE)

The device waits until a byte is received on serial port 0.

 

SER1 : BOOL (default: FALSE)

The device waits until a byte is received on serial port 1.

Note: On the MX2 turbo either DI4 or SER1 must be selected. Both at the same time is unsupported.

 

Time : DINT (default: -1)

The device waits a number of seconds.

If Time is -1 or 0, the event will be disabled.

 

GPS : BOOL (default: FALSE)

The device waits until a 2D or 3D fix has been reported by the GPS module.

This is only supported by the RTCU SX1 series.

 

Intrusion : BOOL (default: FALSE)

The device waits until an intrusion has been detected.

This is only supported by the RTCU AX9 turbo.

 

Key : BOOL (default: FALSE)

The device waits until a key has been pressed on the keypad or touchscreen.

This is only supported by the RTCU DX4 series and the RTCU NX-400.

 

RF : BOOL (default: FALSE)

The device waits until an RF packet has been received.

This is only supported by devices that has on-board ISM RF.

 

 

Returns: INT

18

CAN activity on the second CAN bus.

17

RF activity.

16

Key press detected.

15

Intrusion detected.

14

GPS 2D/3D fix.

13

PowerApply.

12

Serial 1 activity.

11

Serial 0 activity.

10

CAN activity on the first CAN bus.

9

GSM activity.

8

Timeout.

7

PowerFail.

6

Vibration detected.

5

Ignition detected.

4

DI4 detected.

3

DI3 detected.

2

DI2 detected.

1

DI1 detected.

0

Error (no event enabled).

-1

Unspecified error.

-2

Specified event is not available due to the feature not being enabled.

-3

Event not legal due to illegal CAN communication speed.

-4

GSM module is OFF but the GSM event has been selected.

-5

GSM module is ON but the GSM event has not been selected.

-6

GSM module is not operating in low power mode (see gsmPowerLP) .

-7

GSM module is busy with an active Voice or CSD session.

-8

GSM module is busy from last call to pmWaitEvent.

-9

The on-board battery is fast-charging

-10

The RF module is open (see rfClose).

-11

GPS module is OFF but the GPS event has been selected.

-12

Serial port 1 and digital input 4 is both selected (MX2 turbo)

-13

External power is disabled. Can not wait for PowerApply or PowerFail.

-14

Ethernet network interface is open.

-15

RF is not open, and RF event is selected.

-16

WiFi network interface is open.

-17

S0 is enabled but there is no external power.

-18

Bluetooth is ON.

-19

Waiting for GSM activity is not supported

-20

CAN is ON but CAN event has not been selected.

 

Declaration:

FUNCTION pmWaitEvent : INT;
VAR_INPUT
  Ignition       : BOOL := FALSE;
  IgnitionFalling : BOOL := FALSE; // FALSE => Rising edge, TRUE => Falling edge
  DI1             : BOOL := FALSE;
  DI1Falling     : BOOL := FALSE;
  DI2             : BOOL := FALSE;
  DI2Falling     : BOOL := FALSE;
  DI3             : BOOL := FALSE;
  DI3Falling     : BOOL := FALSE;
  DI4             : BOOL := FALSE;
  DI4Falling     : BOOL := FALSE;
  Vibration       : BOOL := FALSE;
  PowerFail       : BOOL := FALSE;
  GSM             : BOOL := FALSE;
  CAN             : BOOL := FALSE;
  CAN2           : BOOL := FALSE;
  SER0           : BOOL := FALSE;
  SER1           : BOOL := FALSE;
  TIME           : DINT := -1;
  PowerApply     : BOOL := FALSE;
  GPS             : BOOL := FALSE;
  Intrusion       : BOOL := FALSE;
  Key             : BOOL := FALSE;
  RF              : BOOL := FALSE;
END_VAR;

 

 

Example:

INCLUDE rtcu.inc
 
VAR_INPUT
  sw : BOOL;
END_VAR;
 
PROGRAM test;
VAR
  sms   : gsmIncomingSMS;
  writer : logWrite;
  tmp   : INT;
  sen   : INT := 50;
END_VAR;
 
pmSetVibrationSensivity(sen:=100);
 
IF NOT logIsInitialized(key:=4711) THEN
  logInitialize(key:=4711, numlogvalues:=2, numlogrecords:=3000);
END_IF;
DebugMsg(message:="Running...");
 
BEGIN
  IF sw THEN
     sms();
    IF sms.status > 0 THEN
        tmp := strToInt(str:=sms.message);
        IF tmp > 0 AND tmp < 101 THEN
          IF pmSetVibrationSensivity(sen:=SINT(tmp)) = 0 THEN
              sen := tmp;
              DebugFmt(message:="Vibration sensivity changed to: \1",v1:=sen);
          END_IF;
        END_IF;
    END_IF;
  ELSE
     // stop execution and wait for one of the following events - All events except timeout is logged:
     //Ignition rising edge,
     //Digital Input 1 falling edge,
     //Vibration
     //or timeout on 10 seconds.
     tmp := pmWaitEvent(Ignition:=TRUE, DI1:=TRUE, DI1Falling:=TRUE, Vibration:=TRUE, time:=10);
    IF tmp <> 8 THEN
        writer(tag:=1, value[1]:=sen, value[2]:=tmp);
    END_IF;
  END_IF;
END;
 
END_PROGRAM;