Create file system

The DAQ module embeds a lightweight FAT file system supporting SDHC cards up to 16GB on a single partition. Up to 5 files and 5 directories can be open concurrently. File and directory names are limited to 8 characters with a 3 characters extension (8.3 short file names) in this release. There are no other restrictions other than the limits imposed by the FAT file system used to format the SD card: FAT12, FAT16 and FAT32 are supported file formats. Because the file system is entirely hosted on the DAQ module, there's no impact to the application resources other than the C# interface of the DAQ.

Volume functions

void Mount(): initializes the SD card in SPI mode so that it can be used as a file system.

void UnMount(): closes any open files, frees all file system resources, and resets the SD card interface.

File functions

UInt16 OpenFile(string filename, FileMode mode): opens or creates a file and returns a file Id to be used in subsequent file operations.

void CloseFile(UInt16 fileId): flushes the file content to disk and closes the file. The file Id becomes invalid and must not be used for further file operations.

UInt16 ReadFile(UInt16 fileId, byte[] buffer, int bytesToRead): read data from a file and returns the actual byte count read.

UInt16 WriteFile(UInt16 fileId, byte[] buffer, int bytesToWrite): write data to a file and returns the actual number of bytes written.

void SeekFile(UInt16 fileId, UInt32 offset): move the file pointer to the specified offset in the file. The file will grow when seeking past the end of file.

void TruncateFile(UInt16 fileId): truncate the file at the current location of the file pointer.

void SyncFile(UInt16 fileId): forces the file content to be flushed to disk.

string ReadString(UInt16 fileId): reads a carriage-return terminated string from the file.

Int32 WriteString(UInt16 fileId, string str): writes a carriage-return terminated string to the file.

UInt32 GetFilePosition(UInt16 fileId): returns the current position of the file pointer.

bool GetEndOfFile(UInt16 fileId): returns 'true' if the end of the file has been reached.

UInt32 GetFileSize(UInt16 fileId): returns the file size in bytes.

bool GetFileError(UInt16 fileId): returns 'true' if an I/O error took place while attempting to access the file.

Directory functions

UInt16 OpenDir(string directoryName): just like files, directories must be opened before they can be used. Opening a directory returns an Id which can be used in subsequent directory operations.

void CloseDir(UInt16 dirId): frees up the resources allocated for working with the directory. The Id becomes invalid and must not be used for further directory operations.

FileInfo ReadDir(UInt16 dirId): used to enumerate files and directories on the file system. Returns a FileInfo object describing the properties of a file or a directory. '/' refers to the root directory. '0:/' is equivalent to the root directory and includes the partition number. Only partition '0' is currently supported. File and directory names longer than 8.3 will have a 'tilde' character in their name, such as: 'STM32F~1.PDF'

void MakeDir(string directoryName): creates a directory on the file system. When creating nested directories, the parent directory must exist.

MakeDir("dir0");
MakeDir("dir0/sub0");
MakeDir("dir0/sub0/sub1");
void ChangeDir(string path): changes the current working directory.

ChangeDir("/dir0/sub0/sub1");
string GetCurrentDir(): returns the path to the current working directory.

Disk space functions

DiskSpaceInfo GetFreeSpace(): returns the total disk capacity and the remaining disk space in KB.

File and directory functions

void Unlink(string objectName): removes a file or a directory from the file system.

void ChangeAttribute(string objectName, byte attribute, byte attributeMask): sets the 'Archive, 'System', 'Hidden', 'Read-Only' attributes of a file or a directory. The mask specifies which attribute bits are being set while the attributes excluded from the mask are reset.

ChangeAttribute(
      filename,
      FileAttribute.Archive | FileAttribute.Hidden,
      FileAttribute.Archive | FileAttribute.Hidden);
void ChangeTime(string objectName, DateTime dt): sets an arbitrary creation time on a file or a directory.

void Rename(string OldObjectName, string NewObjectName): changes the name of a file or a directory.

Sample Output

The SD card already contained a few files and directories.

Total disk space: 15541728 KB
Total free space: 15540024 KB
Attributes: 48
Dir: DIR0
Attributes: 34
File: STRINGIO.TXT, bytes: 104
Attributes: 32
File: FILE.TXT, bytes: 104
Attributes: 32
File: COPY.TXT, bytes: 104
Attributes: 32
File: IMAGE.JPG, bytes: 59660
Attributes: 32
File: STM32F~1.PDF, bytes: 1610122