Has anyone gotten the SD Card on the Cerberus working?
Justin,
I tried your code several times and unfortunately it didnt work no matter how I tweaked it.
Sometimes it wont mount the SD card – (SDCard ERROR : Unable to mount SD card. Is card formatted as FAT32?)
Sometimes it throws exceptions during StreamWriter – (System.IO.Exception is System I.O.dll –System.IO.Exception in Microsoft.SPOT.IO…)
I have several different brands / sizes of SD cards (Scandisk, PNY, Kingston… 2GB/8GB/16GB) and have formated them every which way several different times.
Ive switched out SD modules… Ive switched out Cerberus mainboards… Ive tried every every code example Ive found…
Its only worked three or four times… but never twice in a row with the same Code / SD Card / Module / Mainboard.
Any ideas?
what are you using to power the board?
Interesting…
You are using a Gadgeteer SD card module on port…?
Can you enumerate the files in the root?
How long is the Gadgeteer ribbon cable? Do you have a short one?
Try calling the mount method with a 400 for the parameter: MountSD(400)
-Valkyrie-MT
WouterH -
Im using the USBClientDP. Ive tried powering the board via the usb port… and then with a 12v power supply to the barrell plug (I was unable to watch the output window – but file.txt wasnt on the SD Card when I checked five minutes later).
Valkyrie-MT
The SD module is on number 7 (F – Y). The USBClientDP is the only other thing plugged into the board.
Ill see if I can dig up a shorter ribbon cable and give the .MountSD(400) a whirl.
@ globe engineering - sorry I misread it as cerb bee
Using code tags will make your post more readable. This can be done in two ways:[ol]
Click the “101010” icon and paste your code between the
tags or...
Select the code within your post and click the "101010" icon.[/ol]
(Generated by QuickReply)
Okay… I replaced the 10 cm cable with a 5 cm one out of the assorted cable pack. It made all the difference in the world!
The SD card mounts each and everytime.
I tweaked Justins code and added the .Mount(400) parameter. The Stream worked on all three cards two out of three times… which is way more consistant than before.
Unfortunately when Stream fails its catastophic (i.e. the board locks up – no debug – no reboot – no response from MFDeploy ping - I have to reload the firmware).
I added several Thead.Sleep(500)(s)and a Debug.Print(ex.StackTrace.ToString()) to each catch.
Now Stream fails only five out of six times with the following output:
Using mainboard GHI Electronics FEZCerberus version 1.1
Volume Is formated
A first chance exception of type ‘System.IO.IOException’ occurred in Microsoft.SPOT.IO.dll
A first chance exception of type ‘System.IO.IOException’ occurred in System.IO.dll
Error during File.Create
Microsoft.SPOT.IO.NativeFileStream::.ctor
System.IO.FileStream::.ctor
System.IO.File::Create
SD_Test.Program::writeFile
SD_Test.Program::ProgramStarted
SD_Test.Program::Main
Here is the code:
using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using System.IO;
using Microsoft.SPOT.IO;
namespace SD_Test
{
public partial class Program
{
public Stream stream;
private string _root;
void ProgramStarted()
{
Thread.Sleep(1000);
try
{
GHI.OSHW.Hardware.StorageDev.MountSD(400);
}
catch (Exception ex)
{
Debug.Print("StorageDev.MountSD() error");
Debug.Print(ex.StackTrace.ToString());
}
Thread.Sleep(500);
if (VolumeInfo.GetVolumes()[0].IsFormatted)
{
_root = VolumeInfo.GetVolumes()[0].RootDirectory;
Debug.Print("Volume Is formated");
Thread.Sleep(500);
writeFile();
}
}
void writeFile()
{
int i;
for (i = 0; i < 10; i++)
{
Thread.Sleep(500);
string nextFile = i.ToString();
string fileName = Path.Combine(_root, "file" + nextFile +@ ".txt");
if (File.Exists(fileName))
{
try
{
stream = File.OpenWrite(fileName);
stream.Position = stream.Length;
}
catch(Exception ex)
{
Debug.Print("Error during File.OpenWrite");
Debug.Print(ex.StackTrace.ToString());
}
}
else
{
Thread.Sleep(500);
try
{
stream = File.Create(fileName);
Debug.Print("file Created");
}
catch (Exception ex)
{
Debug.Print("Error during File.Create");
Debug.Print(ex.StackTrace.ToString());
}
}
using (var writer = new StreamWriter(stream))
{
try
{
Thread.Sleep(500);
writer.WriteLine("Test Worked");
writer.Close();
Debug.Print("Writer.WriteLine successful");
}
catch (Exception ex)
{
Debug.Print("Error during Writer.Writeline");
Debug.Print(ex.StackTrace.ToString());
}
}
Thread.Sleep(500);
stream.Dispose();
}
listFiles();
Thread.Sleep(1000);
closeSD();
}
void listFiles()
{
if (VolumeInfo.GetVolumes()[0].IsFormatted)
{
string rootDirectory = VolumeInfo.GetVolumes()[0].RootDirectory;
string[] files = Directory.GetFiles(rootDirectory);
string[] folders = Directory.GetDirectories(rootDirectory);
Debug.Print("Files available on " + rootDirectory + ":");
for (int i = 0; i < files.Length; i++)
Debug.Print(files[i]);
Debug.Print("Folders available on " + rootDirectory + ":");
for (int i = 0; i < folders.Length; i++)
Debug.Print(folders[i]);
}
}
void closeSD()
{
GHI.OSHW.Hardware.StorageDev.UnmountSD();
Debug.Print("SD Card Closed");
}
}
}
I could live with the 5/6 failure rate if I could trap the exception without locking up the board. What am I doing wrong?
Using code tags will make your post more readable. This can be done in two ways:[ol]
Click the “101010” icon and paste your code between the
tags or...
Select the code within your post and click the "101010" icon.[/ol]
(Generated by QuickReply)
Using code tags will make your post more readable. This can be done in two ways:[ol]
Click the “101010” icon and paste your code between the
tags or...
Select the code within your post and click the "101010" icon.[/ol]
(Generated by QuickReply)
@ globe engineering - edit your post, select the code and click the binary icon
Using code tags will make your post more readable. This can be done in two ways:[ol]
Click the “101010” icon and paste your code between the
tags or...
Select the code within your post and click the "101010" icon.[/ol]
(Generated by QuickReply)
- Go to the post with the code.
- Click “Modify this post” post button. It is a pencil button.
- Select all the code lines and click “Format as code” button. It is a button with 1s and 0s in it.
It should come as no surprise that I cant seem to get the code tag thingy working either…
All I get is /cmd ut…
Fixed