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 names, file names, save in addresses, offset, the number of bytes)
Parameter 1
Folder name: Fixed string (Maximum length is 32 single-byte characters)
Parameter 2
File name: Fixed string (Maximum length is 32 single-byte characters), Internal Device (Maximum length is 14 single-byte characters), Internal Device designated with offset (Internal Device + Temporary address, Maximum length is 14 single-byte characters)
Parameter 3
Write-To Address: Device address, Internal Device designated with offset
Parameter 4
Offset: Numeric Value, Device address, Temporary address (Maximum number that can be specified is 65535 for 16-bit length, 4294967295 for 32-bit length)
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:LS0100], [w: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, the 10 bytes of data at the beginning of the "\DATA\DATA0001.BIN" file are read and written into 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 a 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. Maximum length of parameter 2 folder name + 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 for the file name, the file name storage order is defined by 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 for 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 a destination, the values are not written immediately due to the display unit to PLC transmission time.
For example,
in the script below, statement (1) reads 10 bytes of data from the file and writes the data into [w:D0100]. The data, however, has not yet been written into [w:[PLC1]D0100] at the execution of statement (2) due to the transmission time.
_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