Summary
Reads the specified number of bytes of data in the file after the specified offset and writes it in the destination address.
Format
_CF_read/_SD_read/_USB_read (folder name, file name,
save in address, offset, number of bytes)
Parameter 1
Folder name: Fixed string (maximum 32 single-byte characters)
Parameter 2
File name: Fixed string (maximum 32 single-byte characters), Internal
Device (maximum 14 single-byte characters), Device with Offset Specification
(Internal Device) (Internal Device + Temporary address, maximum 14
single-byte characters)
Parameter 3
Write-To Address: Device address, Device with Offset Specification
(Internal Device)
Parameter 4
Offset: Numeric value, device address, temporary address (maximum 65535
for 16-bits and 4294967295 for 32-bits)
Parameter 5
Number of bytes: Numeric value, device address, temporary address (maximum
1280)
Example expression:
Defining text for the file name, and reading 16 bytes from offset 16
_CF_read ("\DATA", "DATA0001.BIN", [w:[#INTERNAL]LS0100], 16, 16)
In the example above, 16 bytes of data starting from the 17th byte in the "\DATA\DATA0001.BIN" file are written to the area starting from LS0100.
Defining an internal device for the file name, and reading 10 bytes from offset 0
_CF_read ("\DATA", [w:[#INTERNAL]LS0100], [w:[#INTERNAL]LS0200], 0, 10)
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
In the example above, 10 bytes of data at the beginning of the "\DATA\DATA0001.BIN"
file are read and written to the area starting from LS0200.
The error status
is stored for any error that occurs at the time of access to external
storage or during file operation. Even when errors occur, the
process continues. Therefore, when using the file operation function,
always write a script that checks for errors.
22.11.7.7 Label Settings
For information
about data storage order, please refer to the following.
22.10.7 Data
Storage Mode
Only the 8.3 format (a maximum of 12 characters, with 8 characters for the file name, the period, and 3 characters for the extension) can be used for the file name. You cannot use file names longer than 12 characters.
To set the root folder, specify "" (empty string) as the folder name.
Maximum length of parameter 1 folder name is 32 single-byte characters.
The folder name
can be appended to the parameter 2 file name. The maximum length
of parameter 2's folder name and file name is 32 single-byte characters.
For example, \DATA\01\DATA.bin
An Internal Device can be specified for the second parameter (File name). Specifying Internal Device allows indirect addressing of a file name. Also, when using internal devices the maximum folder name + file name length is 14 single-byte characters.
When you specify
an internal device as the file name, the file name storage order
is defined in the Text Data Mode.
7.9.1 System
Settings [Device/PLC] Settings Guide
The number of bytes that are successfully read is written in Read Bytes [s:CF_READ_NUM]/[s:SD_READ_NUM]/[s:USB_READ_NUM]. For details, see 22.11.7.7 Label Settings.
The internal device designated in "File Name" and the "Write-To Address" are not counted as D-Script Addresses.
When a PLC device is specified as the Write-To Address, more time is required for writing data to the PLC as the number of words (bytes) increases. Several seconds may be required, depending on the number of words.
If the data read out from the file exceeds the designated address range of the PLC, a communication error occurs. In this case, you must turn the power to the PLC OFF and ON once to reset the PLC from the error.
When a PLC device
is specified as the destination, values are not written immediately
due to the transmission time between the display unit and PLC.
For example, in the script below, statement (1) reads 10 bytes
of data from the file and writes the data to [w:D0100]. When statement
(2) executes and reads the data, [w:[PLC1]D0100] is not updated
yet due to the transmission time required.
_CF_read ("\DATA",
"DATA0001.BIN", [w:[PLC1]D0100], 0, 10) // (1)
[w:[PLC1]D0200] = [w:[PLC1]D0100] + 1 // (2)
In this case, as shown below, first store to internal device and then execute.
_CF_read
("\DATA", "DATA0001.BIN", [w:[PLC1]D0100],
0, 10)
memcpy ([w:[#INTERNAL]LS0100], [w:[PLC1]D0100], 10)
[w:[PLC1]D0200] = [w:[#INTERNAL]LS0100] + 1