FILEREAD
With this function block the contents of an already opened file can be read. The file must have been opened for read access in the ”FILE_OPENREAD" mode.
VAR_INPUT
VAR_INPUT
NETID : T_AmsNetId; (* ams net id *)
HFILE : UINT; (* file handle *)
BUFADDR : DWORD; (* buffer address for read *)
COUNT : UDINT; (* count of bytes for read *)
READ : BOOL; (* read control input *)
TMOUT : TIME;
END_VAR
NETID : is a string containing the AMS network identifier of the target device to which the ADS command is directed.
HFILE : is occupied by the file handle already created by FILEOPEN.
BUFADDR : contains the address of the buffer into which the data are to be read. The programmer is responsible for dimensioning the buffer such that it can accommodate WRITELEN bytes.
COUNT : contains the number of bytes to be read.
READ : the ADS command is triggered by a rising edge at this input.
TMOUT : specifies the time until the abortion of the function.
VAR_OUTPUT
VAR_OUTPUT
BUSY : BOOL;
ERR : BOOL;
ERRID : UDINT;
COUNT_R : UDINT; (* count of bytes actually read *)
END_VAR
BUSY : this output remains TRUE until the function block has executed a command, but at the longest for the duration supplied to the 'Timeout' input. While Busy = TRUE, no new command will be accepted at the inputs. Please note that it is not the execution of the service but its acceptance whose time is monitored.
ERR : this output is switched to TRUE if an error occurs during the execution of a command. The command-specific error code is contained in ‘ErrorId’. If the function block has a timeout error, 'Error' is TRUE and 'ErrorId' is 1861 (hexadecimal 0x745). Is reset to FALSE by the execution of a command at the inputs.
ERRID : contains the instruction-specific error code of the most recently executed command. Is reset to 0 by the execution of a command at the inputs. If the error code is -1 (16#FFFF), the write operation cannot be performed because, for example, the file was not opened correctly.
COUNT_R : contains the number of currently read bytes.
Sample of calling the function block in FBD:

After a rising edge at ”bReadTrig" and successful execution of the read instruction the currently read bytes from the file are found in ”byArrReadData". The number of bytes actually read in the previous read procedure can be determined from the parameter ”COUNT_R". The sample shows that nine bytes were read.
Requirements
Development environment | Target platform | PLC libraries to include |
---|---|---|
TwinCAT v2.7.0 | PC or CX (x86) | PLCSystem.Lib |
TwinCAT v2.8.0 | PC or CX (x86) | TcSystem.Lib |
TwinCAT v2.10.0 Build >= 1301 | CX (ARM) | TcSystem.Lib |