22.11.7.6 Write File

Reads the defined number of bytes from an address and writes the data to the defined file. Data storage modes include "New", "Append" or "Overwrite" as shown in the Storage Format Overview table.

_CF_write/_SD_write/_USB_write (folder names, file names, read from addresses, offset, number of bytes, mode)

Storage Format Overview

Mode

Name

Description

0

New

Create a new file. If a file with the same name exists, it is deleted.

1

Add

Add the data to a specified file. If the specified file does not exist, a new file is created.

2

Overwrite

Overwrite part of the file. If the specified offset is larger than the file size, the surplus area is filled with 0s and the data is written after the area. If the offset is specified at the end of the file data, the operation is equivalent to adding the data to the file. If the file does not exist, an error occurs. For more information about this error, please see 22.11.7.7 Label Settings.

Example expression:

[w:[#INTERNAL]LS0200] = 0   //Offset (0 when the mode is New)
[w:[#INTERNAL]LS0202] = 100 // Number of bytes (100 bytes).
[w:[#INTERNAL]LS0204] = 0   // Mode (new)
_CF_write ("\DATA", "DATA0001.BIN", [w:[#INTERNAL]LS0100], [w:[#INTERNAL]LS0200], [w:[#INTERNAL]LS0202], [w:[#INTERNAL]:LS0204])

In the previous example, 100 bytes of data is read from LS0100 and stored in the \DATA folder as DATA0001.BIN. You can indirectly define the byte count and mode by defining the offset, byte count, and mode with internal devices.

Defining the file name with an internal device

_CF_write ("\DATA", [w:[#INTERNAL]LS0100], [w:[#INTERNAL]LS0200], 0, 100, 0)

By storing the file name in LS0100, you can indirectly specify the file name. In this example, a file name is stored in LS0100 through LS0106 as follows.

For example, when Text Data Mode = 1

The above expression reads 100 bytes of data from LS0200 and creates a new file ("\DATA\DATA0001.BIN") to store the data.

Storage format example expression

In the example above, 100 bytes of data are read from LS0100 and the DATA0001.BIN file is newly created in the \DATA folder.

If the specified file (DATA0001.BIN in the example) already exists and the statement above is executed, 100 bytes of data are read from LS0100 and following areas and added to the DATA0001.BIN file in the \DATA folder.

If the specified file (DATA0001.BIN in the example) already exists and the above statement is executed, 10 bytes of data stored in LS0100 and following areas are read and overwritten over the 10 bytes of data stored in the 17th and following bytes after the offset in the DATA0001.BIN file in the \DATA folder.

(The file to be overwritten is less than the sum of the offset value and number of added bytes.)

The specified file (DATA0001.BIN in the example) already exists and the file size is 100 bytes. When the offset is set to 96 bytes and the number of bytes is set to 10 bytes for the overwrite operation, 10 bytes of data stored in LS0100 and following areas are read. Then, the first 4 bytes of read data overwrite the 4 bytes of data stored in the 97th and following bytes in the file, and the remaining 6 bytes of data are added to the end of the file data. The resulting file contains 106 bytes of data.

(The file to be overwritten is smaller than the offset value)

The specified file (DATA0001.BIN in the example) already exists and the file size is 100 bytes. When the offset is set to 110 bytes and the number of bytes is set to 10 bytes for the overwrite operation, the area between the 101st byte and 110th bytes is filled with 0s and the 10 bytes of data read from LS0100 and following areas are written in the 111th and following bytes. The resulting file contains 120 bytes of data.