logWriteRaw (Function)

Top  Previous  Next

Architecture:

NX32L

Firmware version:

1.50.00


logWriteRaw writes raw data to an entry in the datalogger.

To write to the flash-based Datalogger, please use logWrite.

 

 

Input:

 

handle : SYSHANDLE

A handle to the Datalogger to write to.

 

tag : SINT

Tag value for the entry.

 

data : PTR

The data to write to the Datalogger.

 

size : DINT

The size of the data.

 

linsec : DINT default -1

Optional timestamp in seconds since 1980-1-1 00:00:00 to use (if -1, the current time is used).

Please note that the function LogGotoLinsec() function will not work correctly if log entries are not written with increasing timestamps.

 

Returns: INT

0

- Successful.

4

- Log is not initialized.

5

- The data is too large for the entry.

7

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

8

- The log is not writable.

10

- Failed to write to the log.

 

 

Declaration:

FUNCTION logWriteRaw : INT;
VAR_INPUT
   handle     : SYSHANDLE;
   tag        : SINT;
   data       : PTR;
   size       : INT;
   linsec     : DINT := -1;
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 := handletag := 0data := 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(rdDataTHEN
      maxSize := SIZEOF(rdData);
   END_IF;
   
   status  := logFirst(handle := handle);
   i := 0;
   WHILE status DO
      rc := logReadRaw(handle := handledata := ADDR(rdData), tag := tsize := maxSizelinsec := l);
      IF rc <> 0 THEN
         DebugFmt(message := "logReadRaw: \1", v2 := rc);
         EXIT;
      END_IF;
      DebugFmt(message := "\1] time \4, temp: " + floatToStr(:= FLOAT(rddata.temperature)/100.0) + 
         ", voltage: " + floatToStr(:= FLOAT(rddata.voltage)/10.0) + ", supply: \2", 
         v1 := iv2 := rddata.supply_typev4 := 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 := nameTHEN
      rc := logOpen(handle := handlefilename := namekey := 1234);
      DebugFmt(message := "logOpen: \1", v1 := rc);
   END_IF;
   IF NOT BOOL(handleTHEN
      // log is not open, it probably failed because of the wrong key, so create it.
      rc := logCreate(handle := handlefilename := namekey := 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;