Component: File (SD/SDHC Card) (File)
| Author | Matrix Ltd. |
| Version | 4.0 |
| Category | File |
File (SD/SDHC Card) component
File component allowing access to read and write files on a SD/SDHC card. Also compatible with micro SD/SDHC cards, please note the pin layout is subtely different for these.
The component automatically detects the filesystem on the card on initialise so FAT16 and FAT32 are fully supported.
When used in simulation provides read/write access to files on the local windows file system.
Detailed description
No detailed description exists yet for this component
Examples
Read a File
Initialises the FAT filesystem then checks for a file named test.txt in the root of the SD card or in the project directory for the simulation. Streams the contents of the text file to an alphanumeric display.
Write a File
Initialises the FAT filesystem then creates and opens a file before looping 20 times taking a reading from an ADC channel and writing the value to the file. The file name is log1.txt on the root of the SD card or in the project directory for the simulation.
Write a File using sectors
Not as flexible as the previous example but faster when speed is critical. Initialises the FAT filesystem then creates and opens a file before looping 5 * 128 times taking a reading from an ADC channel and writing the value to the file. The file name is log2.txt on the root of the SD card or in the project directory for the simulation. This example demonstrates high speed data logging where we place exactly 512 bytes of data (1 sector) and then call the WriteFileSector function to append the data onto file. The resulting file will have exactly 5 sectors worth of data (5 x 512 = 2560 bytes).
Macro reference
AppendByteArrayToFile
AppendByteToFile
AppendFloatArrayToFile
AppendINTArrayToFile
AppendLongArrayToFile
AppendStringToFile
CloseFile
| CloseFile | |
| Closes the current open file | |
| Return | |
CreateFile
DeleteFile
| DeleteFile | |
| Searches for and deletes a file in the current folder location on the card. Default = Root
Returns 0 for success. | |
| Filename | |
| 8.3 format filename e.g."file.txt" | |
| Return | |
Initialise
| Initialise | |
| Attempts to communicate with the SD card and if successful sets up the file system.
Returns: 0=OK / 236 = MBR Invalid / 237 = MBR Fail / 254=No Response / 255=No Card | |
| Return | |
MoveToNextFileSector
OpenFile
OpenFolder
ReadByteArrayFromFile
ReadByteFromBuffer
ReadByteFromFile
ReadByteFromIndex
ReadByteFromScan
ReadFileLength
ReadFileSector
ReadFileSize
| ReadFileSize | |
| Reads the entire size of the current file in bytes. | |
| Return | |
ReadFloatArrayFromFile
ReadINTArrayFromFile
ReadLongArrayFromFile
ReadStringFromFile
ScanCurrentFolder
SetFileIndex
| SetFileIndex | |
| Sets the current file index and used to switch between several open file streams.
Default = 0. | |
| File_Index | |
| File index ranges from 0 to (Max Concurrent Files - 1) | |
| Return | |
SetTimeAndDate
| SetTimeAndDate | |
| Sets the current time and date.
Time = (Hour << 11) + (Min << 5) + (Sec >> 1) Date = (YearFrom1980 << 9) + (Month << 5) + (Day) Additional details can be found here: http://www.maverick-os.dk/FileSystemFormats/FAT16_FileSystem.html#TimeFormat | |
| Time | |
| Sets the current Time in FAT Time format hhhhhmmmmmmsssss - S=Secs/2 | |
| Date | |
| Sets the current Date in FAT Date format yyyyyyymmmmddddd - Y=Years since 1980 | |
| Return | |
UpdateFileSector
| UpdateFileSector | |
| Updates a file sector with new data set from using WriteByteToBuffer.
Note this cannot alter the size of the file. | |
| Return | |
WriteByteToBuffer
| WriteByteToBuffer | |
| Writes a single byte to the current 512 byte local sector buffer. | |
| Address | |
| Address Range 0 - 511 | |
| Data | |
| Data Byte to write to the buffer | |
| Return | |
WriteFileSector
Property reference
Component Source Code
Please click here to download the component source project: FC_Comp_Source_File_SD_FAT.fcfx
Please click here to view the component source code (Beta): FC_Comp_Source_File_SD_FAT.fcfx