Industrial Automation
Industrial Automation | Europe


Main > Product Type > Automation Systems > PLCs
Minimize Text   Default    Enlarge Text


Using FREAD (Read Data File) Instruction - CS/CJ

To explain the function and usage of the File Memory Instruction FREAD(700). This article details the configuration of the instruction through operand settings and provides an example for trial operation. See the Sysmac CS/CJ Series Programmable Controllers Instruction Reference Manual (Cat. No. W474) for additional details.

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. 

The FREAD instruction transfers from from file memory to I/O memory (internal PLC areas). File memory is considered either PLC EM memory or Compact Flash (CF) card memory. The four operands used to configure this instruction are:
  1. C - Control
  2. S1 - Number of read words and reading position to start from
  3. S2 - Filename
  4. 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

  • 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.
The FREAD instruction provides easy and flexible functionality to read large amounts of data from a file on the CF Memory Card or EM memory areas to internal memory areas in the PLC. Understanding the operand configuration of the FREAD instruction provided in this document and referenced in the Sysmac CS/CJ Series Programmable Controllers Instruction Reference Manual allows simple execution of this powerful instruction.

See also Using FWRITE (Write Data File) Instruction - CS/CJ



DIAMETER.txt - Size: 60

Comments (View All Comments / Add Comment)

Related Articles
No related articles found.
Created 2008-10-31
Modified 2014-02-25
Views 9634


You are not logged in.