SD_READ

../_images/a28f7f77e38aab520a33139000eba54e1

The Function Block SD_READ reads a data set from a file on the SD Card and stores the read data set beginning at the start flag defined by ADRVAR.

In this context it has to be observed that the Function Blocks are mutually interlocked, i.e. it must be ensured that only one Function Block is active at the same time.

The Function Block reads a data set in the file on the SD card:

…\UserData\PM5x1\UserDat\USRDATxx.DAT Structure of the File USRDATXX.DAT on the SD Card

Access to the SD Card is only possible by using the Function Blocks SD_WRITE and SD_READ.

The inputs ATTRIB, FILENO, FORMAT, ADRVAR and NVAR determine how many values should be read from which file and in which format on the SD card as well as to which target address they should be stored. Always a complete data set must be read.

Reading a data set from the SD Card can take several PLC cycles.

With a FALSE/TRUE edge at input EN, the data set reading is triggered once. Input EN is not evaluated again until the ready message DONE = TRUE is available, i.e. the state of EN is ignored during reading.

After the read operation is completed, the Function Block outputs DONE, ERR and ERNO are updated. Reading was successful, if DONE = TRUE and ERR = FALSE. If DONE = TRUE and ERR = TRUE, an error occurred. The error type is signalized at output ERNO.

After reading a data set from the SD Card, the Function Block outputs are valid for one cycle. In the next cycle, the outputs DONE, ERR and ERNO are reset to zero. A new FALSE/TRUE edge at input EN starts a new read operation.

Reading example 1:

To read user data from a data file without sectors from the SD card and write them to the PLC, proceed as follows:

  1. Insert the SD card.

  2. Read a data set by calling the Function Block SD_READ with the following settings: EN := TRUE (* FALSE/TRUE edge triggers reading *) ATTRIB := 2 (* open / read *) FILENO := 0..99 (* number of file to be read *) SEG := address of the variable sector name FORMAT := data format NVAR := number of data in the data set ADRVAR := address of the first variable to which data are to be stored.

  3. 3. Further data sets can be read with the following settings after the completion message (DONE=TRUE) is displayed. This process is started with a FALSE/TRUE edge at input EN: EN := TRUE (* FALSE/TRUE edge triggers reading*) ATTRIB := 3 (* continue read *) FILENO := 0..99 (* number of file to be read *) SEG := address of the variable sector name FORMAT := data format NVAR := number of data in the data set ADRVAR := address of the first variable to which data are to be stored If an unexpected sector name or the end of file (EOF) is detected during reading, an appropriate error message is generated.

  4. To read a further data set and to close the file afterwards, call the Function Block SD_READ with the following settings after the completion message (output DONE=TRUE) is displayed and start the process with a FALSE/TRUE edge at input EN: EN := TRUE (* FALSE/TRUE edge triggers reading*) ATTRIB := 4 (* read / close *) FILENO := 0…99 (* number of file to be read *) SEG := address of the variable sector name FORMAT := data format NVAR := number of data in the data set ADRVAR := address of the first variable to which data are to be stored If an unexpected sector name or the end of file (EOF) is detected during reading, an appropriate error message is generated.

  5. To close the file without reading it, call the Function Block SD_READ with the following settings after the completion message (DONE=TRUE) and start the process with a FALSE/TRUE edge at input EN: EN := TRUE (* FALSE/TRUE edge closes the file *) ATTRIB := 5 (* close *) FILENO := 0..99 (* number of file to be closed *)

Reading example 2:

To read user data from a data file with sectors from the SD card and write them to the PLC, proceed as follows:

  1. Insert the SD card.

  2. Seek a sector label and read a data set by calling the Function Block SD_READ with the following settings: EN := TRUE (* FALSE/TRUE edge triggers reading *) ATTRIB := 1 (* open / seek / read *) FILENO := 0..99 (* number of the file to be read *) SEG := address of the variable sector name FORMAT := data format NVAR := number of data in the data set ADRVAR := address of the first variable to which data should be written The read operation is finished successfully if output DONE = TRUE and output ERR = FALSE. A seek error is indicated with ERR = TRUE and ERNO <> 0.

  3. Further data sets can be read with the following settings after the completion message (DONE=TRUE) is displayed. This process is started with a FALSE/TRUE edge at input EN: EN := TRUE (* FALSE/TRUE edge triggers reading*) ATTRIB := 3 (* continue read *) FILENO := 0..99 (* number of file to be read *) SEG := address of the variable sector name FORMAT := data format NVAR := number of data in the data set ADRVAR := address of the first variable to which data are to be stored If an unexpected sector name or the end of file (EOF) is detected during reading, an appropriate error message is generated.

  4. If you want to read further sectors / data sets, repeat steps 2 and 3.

  5. To read a further data set and to close the file afterwards, call the Function Block SD_READ with the following settings after the completion message (output DONE=TRUE) is displayed and start the process with a FALSE/TRUE edge at input EN: EN := TRUE (* FALSE/TRUE edge triggers reading*) ATTRIB := 4 (* read / close *) FILENO := 0..99 (* number of file to be read *) SEG := address of the variable sector name FORMAT := data format NVAR := number of data in the data set ADRVAR := address of the first variable to which data are to be written If an unexpected sector name or the end of file (EOF) is detected during reading, an appropriate error message is generated.

  6. To close the file without reading it, call the Function Block SD_READ with the following settings after the completion message (DONE=TRUE) and start the process with a FALSE/TRUE edge at input EN: EN := TRUE (* FALSE/TRUE edge closes the file *) ATTRIB := 5 (* close *) FILENO := 0..99 (* number of file to be closed *)

Available as of PLC runtime system: V1.0
Included in library: SysInt_AC500_V10.lib
Type Function Block with historical values