Main Site Documentation

Hydra SD GetStorageDevice() failing


#1

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


#2

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:


#3

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?

Thanks


#4

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


#5

Sorry, disregard previous post,
Success is gained by:

LatSDCard.MountSDCard();
System.Threading.Thread.Sleep(500);
rootDirectory = LatSDCard.GetStorageDevice().RootDirectory;