Industrial Automation
Industrial Automation | Europe


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


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

To explain the function and usage of the File Memory Instruction FWRIT(701). 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 FWRIT instruction can be used to create a data file containing specified I/O memory data in a Memory Card or EM file memory. It can also add to or overwrite from any point in an existing file. This file can be used to store data in formats such as .TXT, .CSV and .IOM(binary) and later retrieved using FREAD/CMND instructions, a personal computer or possibly via an FTP connection in some cases.
These instructions do not transfer a specified file, but rather a specified amount of data beginning at the specified start position in a file. File operations such as formatting, deletion, copying and renaming can be performed using the CMND(490) Deliver Command.
The FWRIT instruction transfers between I/O memory (internal PLC areas) and file memory. 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. D1 - Number of write words and writing position to start from
  3. D2 - Filename
  4. S - First source word
The Control word (C) is used to determine how the file is created. Data type, carriage return, append/overwrite and storage location can all be set here.

The number of write words (D1 and D1+1) is used to control how much data will be written. The writing position (D1+2 and D1+3) is only used when overwriting data and determines where in the file to begin writing the data (number of words/half-words from the beginning).
The filename (D2) 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 source word (S) specifies the starting address containing the data that will be written to the file memory.
The attached example illustrates an FWRIT operation for the following conditions:
  • - Writing to a Memory Card installed in a CJ2M-CPU33
  • - Comma-delimited words with a .CSV extension
  • - Carriage returns every 1 field
  • - Append data to the existing file
  • - Write 10 words every FWRIT execution
  • - Create the data file in the directory /LINE1/CELL5/VALUES with the filename DIAMETER.CSV
  • - The data being written can be found in the PLC at D0000 to D0009. 
Some important factors to understand when using FWRIT (see Cat. No. W474 for more details):
  • - FWRIT will create a new file if the specified file in D2 does not exist, regardless of overwriting or appending data.
  • - Files created will be dated using the PLC clock. 
  • - The specified file path must exist when writing a file to that directory in a Memory Card. This is not created by the FWRIT instruction and must be done manually, prior to the FWRIT instruction execution.
  • - You cannot execute more than one file memory instruction at a time. Utilize the file memory operation flag to determine when it is acceptable to execute this instruction. Actions such as program replacement and simple backup also cannot be executed while file memory operations are occurring. See W474 for more info.
  • - 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 FWRIT instruction is used to only start writing data. The writing process is executed using the peripheral servicing of the PLC. The time required to write the file depends on the amount of data being written, 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 FWRIT operation. 
The FWRIT instruction provides easy and flexible functionality to store large amounts of data from internal PLC memory to a file on the CF Memory Card or EM memory areas. Understanding the operand configuration of the FWRIT 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 FREAD (Read Data File) Instruction - CS/CJ

Sysmac CS/CJ Series Programmable Controllers Instruction Reference Manual (W474)




Comments (View All Comments / Add Comment)

Related Articles
No related articles found.
Created 2013-11-24
Modified 2014-02-25
Views 19238


You are not logged in.