Objectives
Introduction
File memory instructions such as FWRIT, TWRIT and FREAD provide storage and retrieval mechanisms for large amounts of data. The FREAD instruction can be used to read entire or partial contents of a specified data file to PLC I/O memory.
This instruction can be used to read data that is in .TXT, .CSV or .IOM(binary) formats. FREAD can also be used to read data from a specified position in a file.
Content
- C - Control
- S1 - Number of read words and reading position to start from
- S2 - Filename
- D - First destination word
The Control word (C) is used to determine how the file is read. Data type, carriage returns, entire/partial data reading, and file location can all be set here.
The number of read words (S1 and S1+1) are used to control how much data will be read. The starting read position (S1+2 and S1+3) are only used when the data being read has no carriage returns or is binary type. Set S1+2 and S1+3 to 0000hex when reading data with carriage returns.
The filename (S2) is used to store a string of characters that represent the full path name to the directory, including the filename where the data is stored in ASCII.
The first desitanation word (D) specifies the starting address where the data being read from file memory will be stored.
Some important factors to understand when using FWRIT (see Cat. No. W474 for more details):
- The specified file path must exist when reading a file from a directory in a Memory Card. If the specified file or directory does not exist, the File Missing Flag (A343.11) will be turned ON and the file data will not be read.
- There are several Auxiliary bits/words to indicate file memory operation status and conditions such as memory card detection flag, accessing file flag and error flags that should be utilized during program creation. See Cat. No. W474 for more info.
- The FREAD instruction is used to only start reading data. The reading process is executed using the peripheral servicing of the PLC. The time required to read the file depends on the amount of data being read, the peripheral servicing time setting, and other conditions. When the transfer is completed, the File Memory Operation Flag will turn OFF.
- A few seconds are required for the CPU unit to detect a Memory Card after power up or insertion. Utilize the Memory Card Detection Flag to determine when the CPU can begin a FREAD operation
Example
- The attached example illustrates an FREAD operation for the following conditions:
- - Reading from a Memory Card installed in a CJ2M-CPU33 with a file in the directory /LINE1/CELL5/VALUES called DIAMETER.TXT containing values.
- - Non-delimited words with a .TXT extension
- - Carriage returns every 1 field
- - Read 10 words every FREAD execution
- - Put the data being read in the PLC at D0000 to D0009.
Summary
References
See also Using FWRITE (Write Data File) Instruction - CS/CJ