This function reads a block of data from a FILE and returns the number of bytes read. All data is addressed as 8 bit, and after each successful read operation, the file data pointer is automatically incremented.
Please see fsFileReadString for string read.
Input:
fd : FILE
FILE descriptor for the file retrieved from fsFileOpen or fsFileCreate.
buffer : PTR
Address of the buffer to receive the data in.
length : INT
Number of bytes to read.
Returns: INT
Number of bytes read from file.
Declaration:
FUNCTION fsFileRead : INT;
VAR_INPUT
fd : FILE;
buffer : PTR;
length : INT;
END_VAR;
Example:
IF fsFileExists(name := "\gpslog.dat") THEN
fdGpslog := fsFileOpen(name := "\gpslog.dat");
IF fsFileStatus(fd := fdGpslog) = 0 THEN
IF fsFilePosition(fd := fdGpslog) > 0 THEN
rc := fsFileSeek(fd := fsGpslog, offset := 0);
IF rc = 0 THEN
REPEAT
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));
IF len1 = SIZEOF(linsec) AND len2 = SIZEOF(lat) AND len3 = SIZEOF(lon) THEN
...
END_IF;
UNTIL len1 <> SIZEOF(linsec) OR len2 <> SIZEOF(lat) OR len3 <> SIZEOF(lon)
END_REPEAT;
ELSE
END_IF;
ELSE
END_IF;
fsFileClose(fd := fdGpslog);
ELSE
END_IF;
ELSE
END_IF;
...
|