FB_FileRead
![FB_FileRead 1:](Images/png/9007199285969163__Web.png)
With the function block FB_FileRead the contents of an already opened file can be read. Before a read access, the file must have been opened in the corresponding mode. In addition to the FOPEN_MODEREAD
, the appropriate format (FOPEN_MODEBINARY
or FOPEN_MODETEXT
) is also important to achieve the desired result.
![]() | This function block is only suitable for logging in real-time to a limited extent. |
Inputs
VAR_INPUT
sNetId : T_AmsNetId;
hFile : UINT;
pReadBuff : PVOID;
cbReadLen : UDINT;
bExecute : BOOL;
tTimeout : TIME := DEFAULT_ADS_TIMEOUT;
END_VAR
Name | Type | Description |
---|---|---|
sNetId | T_AmsNetId | String containing the AMS network ID of the target device to which the ADS command is addressed (type: T_AmsNetId). |
hFile | UINT | File handle, which was generated when the function block FB_FileOpen was created. |
pReadBuff | PVOID | Address of the buffer into which the data are to be read. The buffer can be a single variable, an array or a structure, whose address can be found with the ADR operator. |
cbReadLen | UDINT | Number of bytes to be read |
bExecute | BOOL | The function block is activated by a rising edge at this input. |
tTimeout | TIME | States the length of the timeout that may not be exceeded by execution of the ADS command. |
Outputs
VAR_OUTPUT
bBusy : BOOL;
bError : BOOL;
nErrId : UDINT;
cbRead : UDINT;
bEOF : BOOL;
END_VAR
Name | Type | Description |
---|---|---|
bBusy | BOOL | When the function block is activated, this output is set to TRUE and remains set until feedback is received. As long as bBusy is TRUE, no new command can be executed. |
bError | BOOL | If an error occurs during command execution, this output is set, once the bBusy output has been reset. |
nErrId | UDINT | Returns the ADS error code or the command-specific error code when the bError output is set. |
cbRead | UDINT | Number of currently read bytes |
bEOF | BOOL | This output is set if the end of the file was reached and no further data bytes could be read (cbRead=0). This output is not set if further data bytes could be read (cbRead>0). |
Command-specific error code | Possible cause |
---|---|
0x703 | Invalid or unknown file handle. |
0x70A | No memory for read buffer. |
0x70E | File was opened with wrong method (e.g. with obsolete FILEOPEN function block). |
Example of calling the function block in FBD:
PROGRAM Test
VAR
fbFileRead : FB_FileRead;
hFile : UINT;
bFileRead : BOOL;
bFileReadBusy : BOOL;
bFileReadError : BOOL;
nFileReadErrorId : UDINT;
nFileReadCount : UDINT;
bFileReadEOF : BOOL;
fileData : ARRAY[0..9] OF BYTE;
END_VAR
![FB_FileRead 5:](Images/png/31231371__en-US__Web.png)
After a rising edge at bExecute and successful execution of the read instruction the currently read bytes from the file are found in FILEDATA. The parameter cbRead can be used to determine how many bytes were actually read during the last read operation.
Requirements
Development environment |
Target system type |
PLC libraries to include (Category group) |
---|---|---|
TwinCAT v3.1.0 |
PC or CX (x86, x64, ARM) |
Tc2_System (System) |