Difference between revisions of "Component: File (SD/SDHC Card) (File)"
From Flowcode Help
Jump to navigationJump to search(2 intermediate revisions by the same user not shown) | |||
Line 14: | Line 14: | ||
==File (SD/SDHC Card) component== | ==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. | 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== | ==Detailed description== | ||
Line 48: | Line 42: | ||
''<span style="color:red;">No additional examples</span>'' | ''<span style="color:red;">No additional examples</span>'' | ||
+ | |||
+ | |||
+ | |||
+ | |||
Line 58: | Line 56: | ||
==Macro reference== | ==Macro reference== | ||
+ | |||
+ | ===AppendByteArrayToFile=== | ||
+ | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
+ | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''AppendByteArrayToFile''' | ||
+ | |- | ||
+ | | colspan="2" | Adds a binary byte array to the end of the file. Returns 0 for success. | ||
+ | |- | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE | ||
+ | | width="90%" | Data | ||
+ | |- | ||
+ | | colspan="2" | Binary data array to append to the file | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT | ||
+ | | width="90%" | Length | ||
+ | |- | ||
+ | | colspan="2" | Number of values to append | ||
+ | |- | ||
+ | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE | ||
+ | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
+ | |} | ||
+ | |||
===AppendByteToFile=== | ===AppendByteToFile=== | ||
Line 72: | Line 94: | ||
|- | |- | ||
| colspan="2" | Data to append to the end of the file | | colspan="2" | Data to append to the end of the file | ||
+ | |- | ||
+ | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE | ||
+ | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
+ | |} | ||
+ | |||
+ | |||
+ | ===AppendFloatArrayToFile=== | ||
+ | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
+ | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''AppendFloatArrayToFile''' | ||
+ | |- | ||
+ | | colspan="2" | Adds a binary float array to the end of the file. Returns 0 for success. | ||
+ | |- | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-f32-icon.png]] - FLOAT | ||
+ | | width="90%" | Data | ||
+ | |- | ||
+ | | colspan="2" | Binary data array to append to the file | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT | ||
+ | | width="90%" | Length | ||
+ | |- | ||
+ | | colspan="2" | Number of values to append | ||
+ | |- | ||
+ | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE | ||
+ | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
+ | |} | ||
+ | |||
+ | |||
+ | ===AppendINTArrayToFile=== | ||
+ | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
+ | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''AppendINTArrayToFile''' | ||
+ | |- | ||
+ | | colspan="2" | Adds a binary INT array to the end of the file. Returns 0 for success. | ||
+ | |- | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT | ||
+ | | width="90%" | Data | ||
+ | |- | ||
+ | | colspan="2" | Binary data array to append to the file | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT | ||
+ | | width="90%" | Length | ||
+ | |- | ||
+ | | colspan="2" | Number of values to append | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-bool-icon.png]] - BOOL | ||
+ | | width="90%" | MSBFirst | ||
+ | |- | ||
+ | | colspan="2" | 0=LSB then MSB, 1=MSB then LSB | ||
+ | |- | ||
+ | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE | ||
+ | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
+ | |} | ||
+ | |||
+ | |||
+ | ===AppendLongArrayToFile=== | ||
+ | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
+ | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''AppendLongArrayToFile''' | ||
+ | |- | ||
+ | | colspan="2" | Adds a binary Long array to the end of the file. Returns 0 for success. | ||
+ | |- | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-u32-icon.png]] - ULONG | ||
+ | | width="90%" | Data | ||
+ | |- | ||
+ | | colspan="2" | Binary data array to append to the file | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT | ||
+ | | width="90%" | Length | ||
+ | |- | ||
+ | | colspan="2" | Number of values to append | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-bool-icon.png]] - BOOL | ||
+ | | width="90%" | MSBFirst | ||
+ | |- | ||
+ | | colspan="2" | 0=LSB then MSB, 1=MSB then LSB | ||
|- | |- | ||
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE | ||
Line 155: | Line 259: | ||
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Initialise''' | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Initialise''' | ||
|- | |- | ||
− | | colspan="2" | Attempts to communicate with the SD card and if successful sets up the file system. Returns 0 | + | | colspan="2" | 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 |
|- | |- | ||
|- | |- | ||
Line 216: | Line 320: | ||
|- | |- | ||
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u8-icon.png]] - BYTE | ||
+ | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
+ | |} | ||
+ | |||
+ | |||
+ | ===ReadByteArrayFromFile=== | ||
+ | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
+ | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''ReadByteArrayFromFile''' | ||
+ | |- | ||
+ | | colspan="2" | Reads a binary byte array from the currently open file. Auto increments the position in the file. Returns the number of values read. | ||
+ | |- | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-u8-icon.png]] - BYTE | ||
+ | | width="90%" | Data | ||
+ | |- | ||
+ | | colspan="2" | Data variable to populate with data | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT | ||
+ | | width="90%" | Length | ||
+ | |- | ||
+ | | colspan="2" | Number of values to read | ||
+ | |- | ||
+ | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u16-icon.png]] - UINT | ||
| width="90%" style="border-top: 2px solid #000;" | ''Return'' | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
|} | |} | ||
Line 329: | Line 457: | ||
|- | |- | ||
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u32-icon.png]] - ULONG | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u32-icon.png]] - ULONG | ||
+ | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
+ | |} | ||
+ | |||
+ | |||
+ | ===ReadFloatArrayFromFile=== | ||
+ | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
+ | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''ReadFloatArrayFromFile''' | ||
+ | |- | ||
+ | | colspan="2" | Reads a binary Float array from the currently open file. Auto increments the position in the file. Returns the number of values read. | ||
+ | |- | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-f32-icon.png]] - FLOAT | ||
+ | | width="90%" | Data | ||
+ | |- | ||
+ | | colspan="2" | Data variable to populate with data | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT | ||
+ | | width="90%" | Length | ||
+ | |- | ||
+ | | colspan="2" | Number of values to read | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-bool-icon.png]] - BOOL | ||
+ | | width="90%" | MSBFirst | ||
+ | |- | ||
+ | | colspan="2" | 0=LSB then MSB, 1=MSB then LSB | ||
+ | |- | ||
+ | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u16-icon.png]] - UINT | ||
+ | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
+ | |} | ||
+ | |||
+ | |||
+ | ===ReadINTArrayFromFile=== | ||
+ | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
+ | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''ReadINTArrayFromFile''' | ||
+ | |- | ||
+ | | colspan="2" | Reads a binary INT array from the currently open file. Auto increments the position in the file. Returns the number of values read. | ||
+ | |- | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT | ||
+ | | width="90%" | Data | ||
+ | |- | ||
+ | | colspan="2" | Data variable to populate with data | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT | ||
+ | | width="90%" | Length | ||
+ | |- | ||
+ | | colspan="2" | Number of values to read | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-bool-icon.png]] - BOOL | ||
+ | | width="90%" | MSBFirst | ||
+ | |- | ||
+ | | colspan="2" | 0=LSB then MSB, 1=MSB then LSB | ||
+ | |- | ||
+ | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u16-icon.png]] - UINT | ||
+ | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
+ | |} | ||
+ | |||
+ | |||
+ | ===ReadLongArrayFromFile=== | ||
+ | {| class="wikitable" style="width:60%; background-color:#FFFFFF;" | ||
+ | |- | ||
+ | | width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]] | ||
+ | | width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''ReadLongArrayFromFile''' | ||
+ | |- | ||
+ | | colspan="2" | Reads a binary Long array from the currently open file. Auto increments the position in the file. Returns the number of values read. | ||
+ | |- | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-u32-icon.png]] - ULONG | ||
+ | | width="90%" | Data | ||
+ | |- | ||
+ | | colspan="2" | Data variable to populate with data | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-u16-icon.png]] - UINT | ||
+ | | width="90%" | Length | ||
+ | |- | ||
+ | | colspan="2" | Number of values to read | ||
+ | |- | ||
+ | | width="10%" align="center" | [[File:Fc9-bool-icon.png]] - BOOL | ||
+ | | width="90%" | MSBFirst | ||
+ | |- | ||
+ | | colspan="2" | 0=LSB then MSB, 1=MSB then LSB | ||
+ | |- | ||
+ | | width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u16-icon.png]] - UINT | ||
| width="90%" style="border-top: 2px solid #000;" | ''Return'' | | width="90%" style="border-top: 2px solid #000;" | ''Return'' | ||
|} | |} | ||
Line 555: | Line 770: | ||
| colspan="2" | Directory flagged as root for simulation Default: $(srcdir) is the current project source directory. Modern windows systems do not like you writing files to a hard drive root directory so a directory off the root is advised. | | colspan="2" | Directory flagged as root for simulation Default: $(srcdir) is the current project source directory. Modern windows systems do not like you writing files to a hard drive root directory so a directory off the root is advised. | ||
|} | |} | ||
+ | |||
+ | ==Component Source Code== | ||
+ | |||
+ | Please click here to download the component source project: [https://www.flowcode.co.uk/wiki/componentsource/FC_Comp_Source_File_SD_FAT.fcfx FC_Comp_Source_File_SD_FAT.fcfx] | ||
+ | |||
+ | Please click here to view the component source code (Beta): [https://www.flowcode.co.uk/FlowchartView/?wfile=componentsource/FC_Comp_Source_File_SD_FAT.fcfx FC_Comp_Source_File_SD_FAT.fcfx] |
Latest revision as of 14:32, 26 July 2024
Author | Matrix Ltd. |
Version | 3.0 |
Category | File |
Contents
- 1 File (SD/SDHC Card) component
- 2 Detailed description
- 3 Examples
- 4 Macro reference
- 4.1 AppendByteArrayToFile
- 4.2 AppendByteToFile
- 4.3 AppendFloatArrayToFile
- 4.4 AppendINTArrayToFile
- 4.5 AppendLongArrayToFile
- 4.6 AppendStringToFile
- 4.7 CloseFile
- 4.8 CreateFile
- 4.9 DeleteFile
- 4.10 Initialise
- 4.11 MoveToNextFileSector
- 4.12 OpenFile
- 4.13 OpenFolder
- 4.14 ReadByteArrayFromFile
- 4.15 ReadByteFromBuffer
- 4.16 ReadByteFromFile
- 4.17 ReadByteFromIndex
- 4.18 ReadByteFromScan
- 4.19 ReadFileLength
- 4.20 ReadFileSector
- 4.21 ReadFileSize
- 4.22 ReadFloatArrayFromFile
- 4.23 ReadINTArrayFromFile
- 4.24 ReadLongArrayFromFile
- 4.25 ReadStringFromFile
- 4.26 ScanCurrentFolder
- 4.27 SetFileIndex
- 4.28 SetTimeAndDate
- 4.29 UpdateFileSector
- 4.30 WriteByteToBuffer
- 4.31 WriteFileSector
- 5 Property reference
- 6 Component Source Code
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
No additional examples
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