fsFileSeek (Function)

Top  Previous  Next

Architecture:

X32 / NX32 / NX32L

Device support:

All

Firmware version:

1.00 / 1.00.00


fsFileSeek will move the FILE data pointer to an address offset. The function is used for data addressing in the file before read or write operations. All data is addressed as 8 bit, and after each successful read or write operation, the file data pointer is automatically incremented.

 

 

Input:                

fd : FILE

FILE descriptor for the file retrieved from fsFileOpen or fsFileCreate.

 

offset : DINT

Offset from start of file to move the data  pointer to.

>= 1

- Offset value.

0

- Start of file.

-1

- End of file.

 

Returns: INT

0

- File pointer moved.

-8

- File not open.

-17

- Media communication error (card not supported).

-22

- Media is busy.

-34

- Offset value too large.

-38

- File is no longer accessible and must be closed.

 

Declaration:

FUNCTION fsFileSeek : INT;
VAR_INPUT
  fd     : FILE;
  offset : DINT;
END_VAR;

 

 

Example:

...
IF fsFileExists(name := "\gpslog.dat") THEN
  fdGpslog := fsFileOpen(name := "\gpslog.dat");
  IF fsFileStatus(fd := fdGpslog) = 0 THEN
    // Is file empty?
    IF fsFilePosition(fd := fdGpslog) > 0 THEN
        rc := fsFileSeek(fd := fsGpslog, offset := 0);
        IF rc = 0 THEN
          // Iterate file
          REPEAT
              // Read data fields
              len1 := fsFileRead(fd := fdGpslog, buffer := ADDR(linsec), length := SIZEOF(linsec));
              len2 := fsFileRead(fd := fdGpslog, buffer := ADDR(lat), length := SIZEOF(lat));
              len3 := fsFileRead(fd := fdGpslog, buffer := ADDR(lon), length := SIZEOF(lon));
              // Is data valid?
              IF len1 = SIZEOF(linsec) AND len2 = SIZEOF(lat) AND len3 = SIZEOF(lon) THEN
                // Data is read
                 ...
              END_IF;
          UNTIL len1 <> SIZEOF(linsec) OR len2 <> SIZEOF(lat) OR len3 <> SIZEOF(lon)
          END_REPEAT;
        ELSE
          // Error
        END_IF;
    ELSE
        // No data
    END_IF;
    fsFileClose(fd := fdGpslog);
  ELSE
    // Could not open file
  END_IF;
ELSE
  // File dont exist
END_IF;
...