I call the following routine from my ProgramStarted method to initialise the SD card which I use for data logging purposes.
It’s been working fine for a couple of days but just recently it has started failing with GetStorageDevice() returning NULL.
I’ve reformatted the card in Windows as FAT with 32KB sectors (default value selected in format tool).
It’s a 2GB SanDisk microSD card in a SanDisk micro to SD card adapter.
Both _sdCard.IsCardInserted and _sdCard.IsCardMounted are true.
Under what sorts of conditions would GetStorageDevice() return null? Is it basically an error indicating it failed to mount the FAT file system?
void InitStorage()
{
_sdCard = new GTM.GHIElectronics.SDCard(8);
if (_sdCard.IsCardInserted)
{
_sdCard.MountSDCard();
GT.StorageDevice storage = _sdCard.GetStorageDevice();
_sdRootDirectory = storage.RootDirectory;
string fileName = _sdRootDirectory + @ "\Logs\" + _startupTime.Year + "-" + _startupTime.Month + "-" + _startupTime.Day + "--" + _startupTime.Hour + "-" + _startupTime.Minute + "-" + _startupTime.Second + ".ftilog";
_dataLogFile = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.Read);
}
}
Oh and are those the best/correct format options?
Thanks