fsFileReadString (Function)

Top  Previous  Next

Architecture:

X32 / NX32 / NX32L

Device support:

All

Firmware version:

1.00 / 1.00.00


This reads a string from a FILE - starting from the location set by the data pointer (fsFileSeek). The length of the string will either be the maximum string length as defined by the STRING variable or a carriage return value (0D hex or 13 decimal) followed by a new line value (0A hex or 10 decimal). After each successful read operation, the file data pointer is automatically incremented

 

 

Input:                

fd : FILE

FILE descriptor for the file retrieved from fsFileOpen or fsFileCreate.

 

Returns: STRING

The string read. Or an empty string if none is present.

 

Declaration:

FUNCTION fsFileReadString : STRING;
VAR_INPUT
  fd : FILE;
END_VAR;

 

 

Example:

...
IF fsFileExists(name := "\prg1.log") THEN
  fdLog := fsFileOpen(name := "\prg1.log");
  IF fsFileStatus(fd := fdLog) = 0 THEN
    // Is file empty?
    IF fsFilePosition(fd := fdLog) > 0 THEN
        rc := fsFileSeek(fd := fdLog, offset := 0);
        IF rc = 0 THEN
          // Iterate file
          REPEAT
              str := fsFileReadString(fd := fdLog);
              IF strLen(str := str) > 0 THEN
                // Data is read
                 ...
              END_IF;
          UNTIL strLen(str := str) = 0
          END_REPEAT;
        ELSE
          // Error
        END_IF;
    ELSE
        // No data
    END_IF;
    fsFileClose(fd := fdLog);
  ELSE
    // Could not open file
  END_IF;
ELSE
  // File dont exist
END_IF;
...