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;
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;
logFirst();
LogReader();
col := logValuesPerRecord();
WHILE LogReader.status = 0 DO
str := strFormat(format := "\1-\2-\3,", v1 := LogReader.day, v2 := LogReader.month, v3 := LogReader.year);
fsFileWriteString(fd := fd, str := str);
str := strFormat(format := "\1:\2:\3,", v1 := LogReader.hour, v2 := LogReader.minute, v3 := LogReader.second);
fsFileWriteString(fd := fd, str := str);
str := sintToStr(v := LogReader.tag);
fsFileWriteString(fd := fd, str := str);
FOR i := 1 TO col DO
str := strFormat(format := ",\4", v4 := LogReader.value[i]);
fsFileWriteString(fd := fd, str := str);
END_FOR;
fsFileWriteString(fd := fd, str := "$N");
IF NOT logNext() THEN EXIT; END_IF;
LogReader();
END_WHILE;
fsFileClose(fd := fd);
END_FUNCTION;
|