Component: File (SD/SDHC Card) (File)

From Flowcode Help
Jump to navigationJump to search
Author Matrix Ltd.
Version 3.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.

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

Detailed description

No detailed description exists yet for this component

Examples

No additional examples







Macro reference

AppendByteArrayToFile

Fc9-comp-macro.png AppendByteArrayToFile
Adds a binary byte array to the end of the file. Returns 0 for success. 
Fc9-u8-icon.png - BYTE Data
Binary data array to append to the file 
Fc9-u16-icon.png - UINT Length
Number of values to append 
Fc9-u8-icon.png - BYTE Return


AppendByteToFile

Fc9-comp-macro.png AppendByteToFile
Adds a single byte to the end of the currently open file, useful for inserting the value 0 into binary file types. Returns 0 for success. 
Fc9-u8-icon.png - BYTE Data
Data to append to the end of the file 
Fc9-u8-icon.png - BYTE Return


AppendFloatArrayToFile

Fc9-comp-macro.png AppendFloatArrayToFile
Adds a binary float array to the end of the file. Returns 0 for success. 
Fc9-f32-icon.png - FLOAT Data
Binary data array to append to the file 
Fc9-u16-icon.png - UINT Length
Number of values to append 
Fc9-u8-icon.png - BYTE Return


AppendINTArrayToFile

Fc9-comp-macro.png AppendINTArrayToFile
Adds a binary INT array to the end of the file. Returns 0 for success. 
Fc9-u16-icon.png - UINT Data
Binary data array to append to the file 
Fc9-u16-icon.png - UINT Length
Number of values to append 
Fc9-bool-icon.png - BOOL MSBFirst
0=LSB then MSB, 1=MSB then LSB 
Fc9-u8-icon.png - BYTE Return


AppendLongArrayToFile

Fc9-comp-macro.png AppendLongArrayToFile
Adds a binary Long array to the end of the file. Returns 0 for success. 
Fc9-u32-icon.png - ULONG Data
Binary data array to append to the file 
Fc9-u16-icon.png - UINT Length
Number of values to append 
Fc9-bool-icon.png - BOOL MSBFirst
0=LSB then MSB, 1=MSB then LSB 
Fc9-u8-icon.png - BYTE Return


AppendStringToFile

Fc9-comp-macro.png AppendStringToFile
Adds the contents of the data string parameter to the end of the currently open file. Returns 0 for success. 
Fc9-string-icon.png - STRING Data_String
Data to append to the end of the file 
Fc9-u8-icon.png - BYTE Return


CloseFile

Fc9-comp-macro.png CloseFile
Closes the current open file 
Fc9-void-icon.png - VOID Return


CreateFile

Fc9-comp-macro.png CreateFile
Creates a file in the current folder location on the card. Default = Root Returns 0 for success File must be opened using "Open_File" after creation before writing any data. 
Fc9-string-icon.png - STRING Filename
8.3 format filename e.g."file.txt" 
Fc9-u8-icon.png - BYTE Return


DeleteFile

Fc9-comp-macro.png DeleteFile
Searches for and deletes a file in the current folder location on the card. Default = Root Returns 0 for success. 
Fc9-string-icon.png - STRING Filename
8.3 format filename e.g."file.txt" 
Fc9-u8-icon.png - BYTE Return


Initialise

Fc9-comp-macro.png 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 
Fc9-u8-icon.png - BYTE Return


MoveToNextFileSector

Fc9-comp-macro.png MoveToNextFileSector
Attempts to move to the next sector in the file. When reading a file you would leave force next sector set to 0. When writing a file you would leave force next sector set to 1 to allow new sectors to be created as the file grows. Returns 0 for success 
Fc9-u8-icon.png - BYTE Force_Next_Sector
0 = Don't add new sector, 1 = Add new sector if we are at the end of the file 
Fc9-u8-icon.png - BYTE Return


OpenFile

Fc9-comp-macro.png OpenFile
Searches for and opens a file for reading or writing from within the current directory on the disk. Returns 0 for success. 
Fc9-string-icon.png - STRING Filename
8.3 filename of the file we are trying to open e.g. "file.txt" 
Fc9-u8-icon.png - BYTE Return


OpenFolder

Fc9-comp-macro.png OpenFolder
".." - Jumps up a directory, if at root then remains in root "root" - Jumps directly back to the root directory "foldername" - Opens folder named foldername 
Fc9-string-icon.png - STRING Folder_Name
 
Fc9-u8-icon.png - BYTE Return


ReadByteArrayFromFile

Fc9-comp-macro.png ReadByteArrayFromFile
Reads a binary byte array from the currently open file. Auto increments the position in the file. Returns the number of values read. 
Fc9-u8-icon.png - BYTE Data
Data variable to populate with data 
Fc9-u16-icon.png - UINT Length
Number of values to read 
Fc9-u16-icon.png - UINT Return


ReadByteFromBuffer

Fc9-comp-macro.png ReadByteFromBuffer
Reads a byte of data from the local sector buffer. Return = Data byte read from the local sector buffer.  
Fc9-u16-icon.png - UINT Address
0 - 511 - Contains the position of the byte to be read 
Fc9-u8-icon.png - BYTE Return


ReadByteFromFile

Fc9-comp-macro.png ReadByteFromFile
Reads a byte from the currently open file. Auto increments the position in the file. A return value of 0 may signify the end of the file has been reached (depending on the contents of the file). 
Fc9-u16-icon.png - UINT Return


ReadByteFromIndex

Fc9-comp-macro.png ReadByteFromIndex
Reads an arbitrary byte of data from the current open file. Return = Data byte read from the local sector buffer. Experimental and potentially slow if navigating backwards through the file. 
Fc9-u32-icon.png - ULONG Address
Contains the position of the byte to be read from the file 
Fc9-u8-icon.png - BYTE Return


ReadByteFromScan

Fc9-comp-macro.png ReadByteFromScan
Returns a byte of the name of the file or folder retreived from the Scan_Current_folder function. Return = ASCII byte at position Idx from the folder name or file name at position Current_Idx in the directory 
Fc9-u8-icon.png - BYTE idx
0 - 11 for a file, 0 - 7 for a folder 
Fc9-u8-icon.png - BYTE Return


ReadFileLength

Fc9-comp-macro.png ReadFileLength
Returns the number of bytes in the current sector that are used by the current open file. Return = 512 - Sector is filled with file data Return < 512 - Last sector of the file, Retval specifies how many bytes of data are remaining in the sector 
Fc9-s16-icon.png - INT Return


ReadFileSector

Fc9-comp-macro.png ReadFileSector
Overwrites local buffer with the current file sector from the disk. Used to restore the local sector buffer with the actual sector stored on the card. Return = 0 : Local buffer refreshed with current card sector Return > 0 : Error 
Fc9-u8-icon.png - BYTE Return


ReadFileSize

Fc9-comp-macro.png ReadFileSize
Reads the entire size of the current file in bytes. 
Fc9-u32-icon.png - ULONG Return


ReadFloatArrayFromFile

Fc9-comp-macro.png ReadFloatArrayFromFile
Reads a binary Float array from the currently open file. Auto increments the position in the file. Returns the number of values read. 
Fc9-f32-icon.png - FLOAT Data
Data variable to populate with data 
Fc9-u16-icon.png - UINT Length
Number of values to read 
Fc9-bool-icon.png - BOOL MSBFirst
0=LSB then MSB, 1=MSB then LSB 
Fc9-u16-icon.png - UINT Return


ReadINTArrayFromFile

Fc9-comp-macro.png ReadINTArrayFromFile
Reads a binary INT array from the currently open file. Auto increments the position in the file. Returns the number of values read. 
Fc9-u16-icon.png - UINT Data
Data variable to populate with data 
Fc9-u16-icon.png - UINT Length
Number of values to read 
Fc9-bool-icon.png - BOOL MSBFirst
0=LSB then MSB, 1=MSB then LSB 
Fc9-u16-icon.png - UINT Return


ReadLongArrayFromFile

Fc9-comp-macro.png ReadLongArrayFromFile
Reads a binary Long array from the currently open file. Auto increments the position in the file. Returns the number of values read. 
Fc9-u32-icon.png - ULONG Data
Data variable to populate with data 
Fc9-u16-icon.png - UINT Length
Number of values to read 
Fc9-bool-icon.png - BOOL MSBFirst
0=LSB then MSB, 1=MSB then LSB 
Fc9-u16-icon.png - UINT Return


ReadStringFromFile

Fc9-comp-macro.png ReadStringFromFile
Reads a string from the currently open file. Auto increments the position in the file. An empty string signifies the end of the file has been reached. 
Fc9-u16-icon.png - UINT NumBytes
Maximum number of bytes to attempt to read 
Fc9-u8-icon.png - BYTE EndChar
Ends the string if the value specified is found, default is 0 
Fc9-string-icon.png - STRING Return


ScanCurrentFolder

Fc9-comp-macro.png ScanCurrentFolder
Method for retreiving file or folder names for the card to allow for dynamic file opening or playback. Does not currently simulate. 0 - Filetype found and stored into string array, 1 - End of folder reached, 2 - Filetype mismatch 3 - Empty 
Fc9-u16-icon.png - UINT Current_Idx
Contains the current pointer in the directory table. Values from 0 to 511 to completley search the current folder for a files or folders 
Fc9-u8-icon.png - BYTE Scan_Type
Sets the scan to search for Files or Folders. 0 = Scan for files, 1 = Scan for folders 
Fc9-u8-icon.png - BYTE Return


SetFileIndex

Fc9-comp-macro.png SetFileIndex
Sets the current file index and used to switch between several open file streams. Default = 0.  
Fc9-u8-icon.png - BYTE File_Index
File index ranges from 0 to (Max Concurrent Files - 1) 
Fc9-void-icon.png - VOID Return


SetTimeAndDate

Fc9-comp-macro.png 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 
Fc9-u16-icon.png - UINT Time
Sets the current Time in FAT Time format hhhhhmmmmmmsssss - S=Secs/2 
Fc9-u16-icon.png - UINT Date
Sets the current Date in FAT Date format yyyyyyymmmmddddd - Y=Years since 1980 
Fc9-void-icon.png - VOID Return


UpdateFileSector

Fc9-comp-macro.png UpdateFileSector
Updates a file sector with new data set from using WriteByteToBuffer. Note this cannot alter the size of the file. 
Fc9-void-icon.png - VOID Return


WriteByteToBuffer

Fc9-comp-macro.png WriteByteToBuffer
Writes a single byte to the current 512 byte local sector buffer. 
Fc9-u16-icon.png - UINT Address
Address Range 0 - 511 
Fc9-u8-icon.png - BYTE Data
Data Byte to write to the buffer 
Fc9-void-icon.png - VOID Return


WriteFileSector

Fc9-comp-macro.png WriteFileSector
Overwrites the current sector on the memory card with the contents of the local sector buffer. See write_byte_to_buffer function. Return = 0 - File sector written successfully. Return > 0 - File sector write error 
Fc9-u8-icon.png - BYTE Return


Property reference

Fc9-prop-icon.png Properties
Fc9-conn-icon.png Connections
Fc9-type-16-icon.png Channel
SPI Channel selector 
Fc9-type-5-icon.png MOSI
SPI Data Out Pin SDO - Also Known as Master Out Slave In (MOSI) when used in Master mode. 
Fc9-type-5-icon.png MISO
SPI Data In Pin SDI - Also Known as Master In Slave Out (MISO) when used in Master mode. 
Fc9-type-5-icon.png CLK
SPI Clock Pin CLK - The Clock signal is driven by the SPI master. 
Fc9-type-5-icon.png CS / SS
Chip Select / Slave Select Pin Master Mode: General purpose output pin used to select the remote SPI device. Slave Mode: Hardware chip select pin input used to select the SPI device.  
Fc9-type-16-icon.png Initial Prescaler
SPI initial clock divider - Frequency should be under 400khz to allow startup to work correctly.  
Fc9-type-16-icon.png High Speed Prescaler
SPI high speed clock divider - Once startup is complete this is the rate that will be used to transfer data 
Fc9-conn-icon.png File System
Fc9-type-14-icon.png Max Concurrent Files
Specifies how many concurrent files can be opened at any one time. Use the SetFileIndex macro to switch between concurrent files. 
Fc9-type-16-icon.png End Of File
Specifies the way the ReadByteFromFile function indicates the end of a file. 8 Bit mode - End of the file is represented by the value 0, read multiple times to confirm that the 0 is not simply data. 16 Bit mode - End of file is represented by the value 512 allowing the values 0 - 255 to represent valid data. 
Fc9-conn-icon.png Simulation
Fc9-type-16-icon.png Sim Type
Defines the simulation type. The default is to use the Windows file system to allow for reading and writing files. The alternative is to use the CAL functionality to allow the SPI transactions to be passed onto a seperate handler e.g. for logging or debugging purposes. 
Fc9-conn-icon.png File System
Fc9-type-20-icon.png Root Directory
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.