Summary
Reads the specified number of bytes of data in the file after the specified offset and writes it in the destination address. See the "Data Storage Mode" section below for more details about data storage order.
Format
_CF_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:
To read 16 bytes of data in the specified file when the offset is 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.
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.
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.
For example,
to read 10 bytes of data stored in a file when the file is specified in LS0100 and later and the offset is 0.
_CF_read ("\DATA", [w:LS0100], [w:LS0200], 0, 10)
Storing a file name in LS0100 allows indirect addressing of the file name. In this example, a file name is stored in LS0100 through LS0106 as follows.
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 number of bytes that are successfully read is written in CF Card/USB storage Readout Bytes [s:CF_READ_NUM]/[s:USB_READ_NUM]. For more details, see 21.11.5.1 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 such a case, store the data once in the internal device and then execute the second statement as follows.
_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