Main Site Documentation

Hydra SD GetStorageDevice() failing


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)
		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?



GetStorageDevice() returns private member _device.
The _device is created when Insert handler is called. So my guess is that the Insert handler has not been called for some reason.

Check driver’s code on codeplex:


Yep, or possibly the RemovableMedia.Insert handler is called but this check is failing and therefore _device isn’t being created.

if (e.Volume.Name.Length >= 2 && e.Volume.Name.Substring(0, 2) == "SD")

Given the storage cards being used are on the order of 2-8GB is there any advantage to formatting them with FAT32 as opposed to FAT16?



I recommend installing Portin Kit from codeplex. I remember looking at file system handling code long time ago.


Sorry, disregard previous post,
Success is gained by:

rootDirectory = LatSDCard.GetStorageDevice().RootDirectory;