Type
| Function block |
Description
| Reads data from a file that has been opened using the FILE_OPEN function block.Assign the valid handle for the file from which data is to be read to the Handle input.Create a data buffer of sufficient size for the Buffer output. The data buffer for the data to be read can be declared in a number of ways. The type of data buffer can be defined by the user, e.g., a byte array (see the following example). Strings cannot be used directly as data buffers. If the data read is to be processed further as a string, it must first be saved in an array and then converted into a string using the BUF_TO_STRING function block.
Example: Byte array used as data buffer type
TYPE FileBuffer : ARRAY [1..100] OF BYTE; END_TYPE In this example the data buffer length is 100 characters.
Enter the number of bytes to be read at the
MaxLength input.Activate the function block on a rising edge at the Execute input. Execution of the function block is complete when the Done output is set to 1. If an error occurred during execution,
the value at the Error output = 1. ErrorID indicates the number of the cause of the error.Following successful execution, the data is copied to the buffer and the number of characters read is indicated at the LengthRead output. The number of characters read may be smaller than MaxLength if the end of the file was reached before the number of characters indicated was processed. |
Notes
|
- The status of the outputs Done, LengthRead, Error, and ErrorID is maintained until a falling edge is detected at the Execute input.
- Function blocks have to be instantiated. The instance name of the function block has to be declared in the 'Variables' table of the POU where the FB is going to be used. The instance name must be unique within the POU.
|
Parameters
| Inputs
Execute
Data type: | BOOL |
Description: | Reads data from the file if a rising edge is detected. |
Handle
Data type: | UINT |
Description: | File handle of the file from which data is to read. |
MaxLength
Data type: | ANY_INT |
Description: | Number of characters to be read. The value must be greater than or equal to zero. |
Input/Output
Buffer
Data type: | ANY |
Description: | Data buffer for the data to be read. |
Outputs
Done
Data type: | BOOL |
Description: |
0 | The function block was not executed. |
1 | The function block was executed. |
|
LengthRead
Data type: | UDINT |
Description: | Number of characters read. |
Error
Data type: | BOOL |
Description: |
0 | No error occurred during reading. |
1 | An error occurred during reading. |
|
ErrorID
Data type: | UINT |
Description: | Error number of error that occurred when reading the file:
0 | No error information available. |
1 | Invalid file handle. |
10 | End of file reached. |
12 | The number of characters to be read is greater than the data buffer. |
14 | Invalid Length. The value must be >= 0. |
22 | No data could be read. |
|
|