msRead (Function)

Top  Previous  Next

Architecture:

NX32L

Device support:

NX-200, LX2

Firmware version:

1.50.00


Acquire a set of simultaneous data from the motion sensor devices.

Sensors that are not enabled will return 'not a number' NaN for their readings.

 

 

Input:

Data : msDataSet

The variable to receive the data through. See msDataSet.

 

Returns: INT

1

- Data available.

0

- This function is not supported.

-1

- Interface is not open. Call msOpen first.

-2

- Generic error.

-4

- Invalid input type.

-15

- No sensors are on. Use some of the functions: msAccEnable, msGyrEnable and msMagEnable.

 

Declaration

FUNCTION msRead : INT;
VAR_INPUT
  Data : ACCESS msDataSet;
END_VAR;
 

Example:

INCLUDE rtcu.inc
VAR
  msd : msDataSet;
END_VAR;
 
THREAD_BLOCK Reader
VAR
  rc : INT;
END_VAR;
WHILE TRUE DO
  rc := msRead(data:=msd);
  IF rc = 1 THEN
    DebugMsg(Message:="ACC >>> X: "+floatToStr(v:=(msd.AccX*1000.0))+" mg  Y: "+
                          floatToStr(v:=(msd.AccY*1000.0))+" mg  Z: "+
                          floatToStr(v:=(msd.AccZ*1000.0))+" mg");
    DebugMsg(Message:="GYR >>> X: "+floatToStr(v:=(msd.GyrX))+" dps  Y: "+
                          floatToStr(v:=(msd.GyrY))+" dps  Z: "+
                          floatToStr(v:=(msd.GyrZ))+" dps");
    DebugMsg(Message:="MAG >>> X: "+floatToStr(v:=(msd.MagX))+" gauss  Y: "+
                          floatToStr(v:=(msd.MagY))+" gauss  Z: "+
                          floatToStr(v:=(msd.MagZ))+" gauss");
    DebugFmt(Message:=" Time : \4", v4:=(msd.time/100));
  END_IF;
  Sleep(Delay:=500); // print a sample twice a second
END_WHILE;
END_THREAD_BLOCK;
 
PROGRAM example;
VAR
  ms_read : Reader;
  rc : INT;
END_VAR;
// Open interface
rc := msOpen();
DebugFmt(Message:="msOpen (rc=\1)", v1:=rc);
// enable accelerometer
rc := msAccEnable(enable:=TRUE, mode:=2, resolution:=16);
DebugFmt(Message:="accEnable ON (rc=\1)", v1:=rc);
// enable gyroscope
rc := msGyrEnable(enable:=TRUE, resolution:=125);
DebugFmt(Message:="gyrEnable ON (rc=\1)", v1:=rc);
// enable magnetometer
rc := msMagEnable(enable:=TRUE);
DebugFmt(Message:="magEnable ON (rc=\1)", v1:=rc);
// start reader thread
ms_read();
BEGIN
  ...
END;
END_PROGRAM;