logReadRaw (Function)

Top  Previous  Next

Architecture:

NX32L

Device support:

ALL

Firmware version:

1.50.00


logReadRaw reads raw data from an entry in the datalogger.

To read from the flash-based Datalogger, please use logRead.

 

 

 

Input:

 

handle : SYSHANDLE

A handle to the Datalogger to read from.

 

data : PTR

A buffer to read the data into.

 

size : DINT

The number of bytes of data to read.

 

Output:

 

tag : SINT

Tag value for the entry.

 

linsec : DINT

The timestamp in seconds since 1980-1-1 00:00:00.

 

Returns: INT

0

- Successful.

2

- Log empty (no records available).

4

- Log is not initialized.

6

- Failed to read entry.

7

- The log could not be found. This function is only supported on file- and memory-based Dataloggers.

8

- Invalid size.

 

 

Declaration:

FUNCTION logReadRaw : INT;
VAR_INPUT
  handle     : SYSHANDLE;
  data       : PTR;
  size       : INT;
  tag        : ACCESS SINT;
  linsec     : ACCESS DINT;
END_VAR;

 

 

Example:

//-----------------------------------------------------------------------------
// Datalogger example.
// Writes an entry to the datalogger on each boot.
//-----------------------------------------------------------------------------
INCLUDE rtcu.inc
INCLUDE math.inc
 
STRUCT_BLOCK data;
  temperature : INT;
  voltage     : INT;
  supply_type : SINT;
END_STRUCT_BLOCK;
 
//  These are the global variables of the program
VAR
  wrData : data;
  rdData : data;
END_VAR;
 
FUNCTION writeEntry;
VAR_INPUT
  handle : SYSHANDLE;
END_VAR;
VAR
  rc     : INT;
END_VAR;
  wrData.supply_type := SINT(boardSupplyType());
  wrData.voltage     := boardSupplyVoltage();
  wrData.temperature := boardTemperature();
 
  rc := logWriteRaw(handle := handle, tag := 0, data := ADDR(wrData), size := SIZEOF(wrData));
  DebugFmt(message := "logWriteRaw: \1", v1 := rc);
END_FUNCTION;
 
FUNCTION printLog;
VAR_INPUT
  handle   : SYSHANDLE;
END_VAR;
VAR
  rc       : INT;
  maxSize  : INT;
  status   : BOOL;
  i        : INT;
  t        : SINT;
  l        : DINT;
END_VAR;
  maxSize := INT(logGetMaxRecordSize(handle := handle));
  DebugFmt(message := "Log: \1 * \4", v1 := maxSize,
    v4 := logMaxNumOfRecords(handle := handle));
  IF maxSize > SIZEOF(rdData) THEN
    maxSize := SIZEOF(rdData);
  END_IF;
 
  status := logFirst(handle := handle);
  i := 0;
  WHILE status DO
    rc := logReadRaw(handle := handle, data := ADDR(rdData), tag := t, size := maxSize, linsec := l);
    IF rc <> 0 THEN
        DebugFmt(message := "logReadRaw: \1", v2 := rc);
        EXIT;
    END_IF;
    DebugFmt(message := "\1] time \4, temp: " + floatToStr(v := FLOAT(rddata.temperature)/100.0) +
        ", voltage: " + floatToStr(v := FLOAT(rddata.voltage)/10.0) + ", supply: \2",
        v1 := i, v2 := rddata.supply_type, v4 := l);
    i := i+1;
    status := logNext(handle := handle);
  END_WHILE;  
END_FUNCTION;
 
PROGRAM test;
// These are the local variables of the program block
VAR
  handle : SYSHANDLE;
  rc     : INT;
  name   : STRING := "B:\SYSTEM\DATALOGS\log.bin";
END_VAR;
// The next code will only be executed once after the program starts
  fsMediaOpen(media := 1);
  IF fsFileExists(name := name) THEN
    rc := logOpen(handle := handle, filename := name, key := 1234);
    DebugFmt(message := "logOpen: \1", v1 := rc);
  END_IF;
  IF NOT BOOL(handle) THEN
    // log is not open, it probably failed because of the wrong key, so create it.
    rc := logCreate(handle := handle, filename := name, key := 1234,
        rec_size := SIZEOF(data), rec_count := 1000);
    DebugFmt(message := "logCreate: \1", v1 := rc);
  END_IF;
 
  writeEntry(handle := handle);
 
  printLog(handle := handle);
BEGIN
// Code from this point until END will be executed repeatedly
 
 
END;
END_PROGRAM;