fsFileWriteString (Function)

Top  Previous  Next

Architecture:

X32 / NX32 / NX32L

Device support:

All

Firmware version:

1.00 / 1.00.00


This will write a string to the FILE - starting from the location set by the file data pointer (changed with fsFileSeek). After each successful write operation, the file data pointer is automatically incremented.

 

For automatic insertion of new lines after each string write, see fsFileWriteStringNL.

 

Input:                

fd : FILE

FILE descriptor for the file retrieved from fsFileOpen or fsFileCreate.

 

str : STRING

The string to be written to the file.

 

Returns: INT

Number of bytes written to file.

 

Declaration:

FUNCTION fsFileWriteString : INT;
VAR_INPUT
  fd : FILE;
  str : STRING;
END_VAR;

 

 

Example:

INCLUDE rtcu.inc
 
VAR
  LogReader : logRead;
END_VAR;
 
FUNCTION logExport;
VAR_INPUT
  filename : STRING;
END_VAR;
VAR
  fd : FILE;
  str : STRING;
  i   : INT;
  col : INT;
END_VAR;
 
  // Create file
  fd := fsFileCreate(name := filename);
  IF fsFileStatus(fd := fd) <> 0 THEN
    DebugFmt(message := "Could not open file, error code=\1", v1 := fsFileStatus(fd := fd));
    RETURN;
  END_IF;
 
  // Goto first entry
  logFirst();
  LogReader();
  col := logValuesPerRecord();
 
  // Iterate log
  WHILE LogReader.status = 0 DO
    // Format Date
     str := strFormat(format := "\1-\2-\3,", v1 := LogReader.day, v2 := LogReader.month, v3 := LogReader.year);
    fsFileWriteString(fd := fd, str := str);
    // Format Time
     str := strFormat(format := "\1:\2:\3,", v1 := LogReader.hour, v2 := LogReader.minute, v3 := LogReader.second);
    fsFileWriteString(fd := fd, str := str);
    // Format Tag
     str := sintToStr(v := LogReader.tag);
    fsFileWriteString(fd := fd, str := str);
    // Iterate values
    FOR i := 1 TO col DO
        // Format value
        str := strFormat(format := ",\4", v4 := LogReader.value[i]);
        fsFileWriteString(fd := fd, str := str);
    END_FOR;
    // Terminate entry
    fsFileWriteString(fd := fd, str := "$N");
    // Next entry
    IF NOT logNext() THEN EXIT; END_IF;
     LogReader();
  END_WHILE;
 
  // Close file
  fsFileClose(fd := fd);
 
END_FUNCTION;