SD File Functions

You can use Windows Explorer to store any type of file onto an SD card, such as .html or .jpg. The SD File Functions enable your Ladder application to read and write these files in 'chunks' of 512 bytes.

Note

These functions can only run on files that observe the 8.3 naming convention; the file name cannot exceed 8 characters, and the file extension cannot exceed three.

 

Using SD File Functions

Each read or write operation requires three functions: Open File, Read or Write, and Close File. The functions are located on SD>SD File Utilities.

The examples below show the functions and the System operands required to run read and write operations.

Read File: Example

Note the use of SBs 324, 325, and 326. These enable the Read Next Chunk function to continue reading data chunks until it has completed reading the entire file.

 

Write File: Example

Functions

Read From SD File: Open

Parameter

Purpose

Select Folder

Select the folder, or use an operand to assign a number at run time using the following values:

Alarms: 0 DT main folder: 1 DT1–4: 101 to 103 Log: 3 System: 4 User_app: 5 Trends main folder - 600 Trends1-4: 600 to 603 SdBLocks: 9 Excel main folder: 100 Excel1-4: 1000 to 1003 Web: 11

File name

Either enter the file name, or provide it via operand.

File size

When the function runs, this reports the size of the file, in bytes.

 

Read File: Get Next Chunk

 

Parameter

Purpose

Read: File Chunk Buffer

This the start of the vector that holds the data read from the file. This vector is 512 bytes long.

Read: File Chunk Length

This shows the length of the chunk that is currently read. Note that the final chunk, containing the last of the file data, will generally be LESS than 512 bytes.

 

Read File: Close

Run this when entire files has been read.

 

Write From SD File: Open

Parameter

Purpose

Select Folder

Select the folder, or use an operand to assign a number at run time using the following values:

Alarms: 0 DT main folder: 1 DT1–4: 101 to 103 Log: 3 System: 4 User_app: 5 Trends main folder - 600 Trends1-4: 600 to 603 SdBLocks: 9 Excel main folder: 100 Excel1-4: 1000 to 1003 Web: 11

File name

Either enter the file name, or provide it via operand.

Note that:

 -If the file does not exist on the SD

 -and the SD card is Write-enabled

the function will create the file.

File size

When the function runs, this reports the size of the file, in bytes.

 

Write File: Get Next Chunk

 

Parameter

Purpose

Write: File Chunk Buffer

This the start of the vector that holds the data that will be written to the file. The function takes 512 bytes of data.

Write: File Chunk Length

Enter the number of bytes to be written to the SD file.

 

Write File: Close

Run this when entire files has been written.

 

 

Delete File

Use this to delete any file on the SD card

Note

These functions can only run on files that observe the 8.3 naming convention; the file name cannot exceed 8 characters, and the file extension cannot exceed three.

Use SB 358, Delete File in Progress, as a condition to running the function

 

 

Parameter

Purpose

Select Folder

Select the folder, or use an operand to assign a number at run time using the following values:

Alarms: 0 DT main folder: 1 DT1–4: 101 to 103 Log: 3 System: 4 User_app: 5 Trends main folder - 600 Trends1-4: 600 to 603 SdBLocks: 9 Excel main folder: 100 Excel1-4: 1000 to 1003 Web: 11

File name

Either enter the file name, or provide it via operand.

Status Messages

This MI is a bitmap; a bit turns ON to indicate status.

The MI is initialized when the function starts.

 

  • All bits OFF – No errors, and the SD card is idle

  • Bit 1 – SD Card internal error.

  • Bit 2 – Delete Failed

  • Bit 3 - No SD card found, or the card is locked (Write-enable OFF)

  • Bit 5– Path not found

  • Bit 7 - The SD card has failed (Check SI 66)

Success Bit

 

Turns ON when the file is deleted. It remains ON until it is reset by the application,.

 

SD File Information

Use this function to check if a specific file is located in a specific SD folder, and get specific file details.

Note

Use SB 359, File Info function in Progress, as a condition to running the function

 

Parameter

Purpose

Select Folder

Select the folder, or use an operand to assign a number at run time using the following values:

Alarms: 0 DT main folder: 1 DT1–4: 101 to 103 Log: 3 System: 4 User_app: 5 Trends main folder - 600 Trends1-4: 600 to 603 SdBLocks: 9 Excel main folder: 100 Excel1-4: 1000 to 1003 Web: 11

File name

Either enter the file name, or provide it via operand.

Status Messages

This MI is a bitmap; a bit turns ON to indicate status.

The MI is initialized when the function starts.

 

  • All bits OFF – No errors, and the SD card is idle

  • Bit 1 – SD Card internal error.

  • Bit 2 – Cannot read file

  • Bit 3 - No SD card found, or the card is locked (Write-enable OFF)

  • Bit 4– The SD card has failed (Check SI 66)

  • Bit 5 - Path not found

Success Bit

Turns ON when the data is successfully written to the Block. It remains ON until it is reset by the application, or until the application calls the function.

Exists

0= File was not found

1= File was found

 

Size

Size of the found file

Create Date

Date the file was created

Modified Date

Date of last file change

Attribute

This are the attribute codes:

ATTR_FILE                                      = 0x00

ATTR_READ_ONLY                        = 0x01

ATTR_HIDDEN                                = 0x02

ATTR_SYSTEM                               = 0x04

ATTR_VOLUME_LABEL                 = 0x08

ATTR_LONG_NAME                       = 0x0F

ATTR_SUB_DIR                              = 0x10

ATTR_ARCIVE                                = 0x20,

ATTR_DEVICE                                = 0x40

ATTR_UNUSED                              = 0x80

 

Rename SD File

Use this to rename any file on the SD card.

 

 

Parameter

Purpose

Select Folder

Select the folder, or use an operand to assign a number at run time using the following values:

Alarms: 0 DT main folder: 1 DT1–4: 101 to 103 Log: 3 System: 4 User_app: 5 Trends main folder - 600 Trends1-4: 600 to 603 SdBLocks: 9 Excel main folder: 100 Excel1-4: 1000 to 1003 Web: 11

Old/New File name

Either enter the file name, or provide it via operand.

Status Messages

This MI is a bitmap; a bit turns ON to indicate status.

The MI is initialized when the function starts.

 

  • All bits OFF – No errors, and the SD card is idle

  • Bit 1 – SD Card internal error.

  • Bit 2 – Rename Failed

  • Bit 3 - No SD card found, or the card is locked (Write-enable OFF)

  • Bit 5 - Path not found

  • Bit 7 - The SD card has failed (Check SI 66)

Success Bit

 

Turns ON when the file is successfully renamed . It remains ON until it is reset by the application, or until the application calls the function.

 

System Operands