OnBoard MicroSD
#1
Posted 19 May 2012 - 08:06 AM
#2
Posted 19 May 2012 - 02:19 PM
#3
Posted 19 May 2012 - 05:20 PM
I have a logging application that writes to the SD card. Here is how I do that.
First, I create the file (Sorry still has my variables in there).
using (var filestream = new FileStream(@"SD\" + folder + SD_HEADER_LOG, FileMode.Create)) { StreamWriter streamWriter = new StreamWriter(filestream); streamWriter.WriteLine(APP_NAME + (char)32 + getVersion()); streamWriter.WriteLine("Device MAC ID: " + GetMAC()); streamWriter.WriteLine("Log Create Time: " + DateTime.Now.ToString()); streamWriter.WriteLine("------------------------------------------------------------"); streamWriter.Close(); }
Then when I want to write to the file:
using (var filestream = new FileStream(@"SD\" + folderName + SD_HEADER_LOG, FileMode.Append)) { StreamWriter sw = new StreamWriter(filestream); sw.WriteLine("Data: " + DateTime.Now.ToString() + " - " + myData.ToString()); sw.Close(); }
You should be able to use the filestream to also read the files. Most important is to use the "\SD" folder.
There are also some SD cards and some sizes of Cards that do not work. I have had the most success with 2GB cards that are not SDHC.
Hope this helps.
#4
Posted 19 May 2012 - 05:23 PM
Hi Christian,
What size is your MicroSD card? Does the "\SD" folder appear when you insert your card?
BTW, welcome to the Netduino community.
Chris
used 2go Micro SD (Not use SD HC
Example code:
using System; using System.IO; using System.Threading; using Microsoft.SPOT; using Microsoft.SPOT.Hardware; using Microsoft.SPOT.IO; using SecretLabs.NETMF.Hardware; using SecretLabs.NETMF.IO; #if(NETDUINO_MINI) using SecretLabs.NETMF.Hardware.NetduinoMini; #else using SecretLabs.NETMF.Hardware.NetduinoPlus; #endif namespace NetDuinoPlusMicroSd { /* DEBUG LOG */ // Insert card now - Inserer votre carte maintenant //Card Inserted //Volume found //#fichier de configuration //BUFFER_GPS=2048 //FORMAT_DATE=DD/MM/YYYY HH:MM:SS //Directory count: 1 //Directory: \SD //file count: 2 //filename: \SD\filename.txt //filename: \SD\CONFIG.TXT public class Program { static void SD_Insert(object sender, MediaEventArgs args) { Debug.Print("Card Inserted"); #if(NETDUINO_MINI) // Mount SD (for Mini - already present on Plus) StorageDevice.MountSD("SD", SPI_Devices.SPI1, Pins.GPIO_PIN_17); #endif } static void SD_Eject(object sender, MediaEventArgs args) { Debug.Print("Card Ejected"); } public static void Main() { RemovableMedia.Insert += new InsertEventHandler(SD_Insert); RemovableMedia.Eject += new EjectEventHandler(SD_Eject); ////OEM = 0x22, Model = 0xB1 (Secret Labs VID) and SKU = 0x1000 for Netduino, 0x1001 for Netduino Plus and 0x1002 for Netduino Mini respectively. //Debug.Print("SystemInfo.SystemID.Model :" + SystemInfo.SystemID.Model.ToString()); //Debug.Print("SystemInfo.SystemID.OEM :" + SystemInfo.SystemID.OEM.ToString()); //Debug.Print("SystemInfo.SystemID.SKU :" + SystemInfo.SystemID.SKU.ToString()); Debug.Print("Insert card now - Inserer votre carte maintenant"); Thread.Sleep(10000); // cette partie de code doit etre mis dans la procédure insert ... + Timeout infinit dans le sleep if (VolumeInfo.GetVolumes().Length > 0) { Debug.Print("Volume found"); VolumeInfo[] volumes = VolumeInfo.GetVolumes(); // Netduino PLUS: SD foreach (var volumeInfo in volumes) { Debug.Print(volumeInfo.Name + " " + volumeInfo.VolumeLabel); } try { // READ FILE FileStream filestream = new FileStream(@"\SD\config.txt", FileMode.Open); StreamReader reader = new StreamReader(filestream); Debug.Print(reader.ReadToEnd()); reader.Close(); } catch(Exception ex) { Debug.Print("Exeption Read fichier : " + ex.Message); } try { // WRITE FILE // FileStream filestream2 = new FileStream(@"\SD\test.txt", FileMode.Open); FileStream filestream2 = new FileStream(@"SD\filename.txt", FileMode.Append, FileAccess.Write, FileShare.None); StreamWriter streamWriter = new StreamWriter(filestream2); streamWriter.WriteLine("Test 123"); streamWriter.Close(); filestream2.Close(); } catch (Exception ex) { Debug.Print("Exeption Write file : " + ex.Message); } try { string[] directories = System.IO.Directory.GetDirectories(@"\"); Debug.Print("Directory count: " + directories.Length.ToString()); for (int i = 0; i < directories.Length; i++) { Debug.Print("Directory: " + directories[i]); } } catch (Exception ex) { Debug.Print("Exeption Read list Directory : " + ex.Message); } try { string[] files = System.IO.Directory.GetFiles(@"\SD"); Debug.Print("file count: " + files.Length.ToString()); for (int i = 0; i < files.Length; i++) { Debug.Print("filename: " + files[i]); //FileStream fs = new FileStream(files[i], FileMode.Open, FileAccess.Read, FileShare.None, 512); //StreamReader sr = new StreamReader(fs); //Debug.Print("contents: " + sr.ReadToEnd()); } } catch (Exception ex) { Debug.Print("Exeption Read list Files : " + ex.Message); } Thread.Sleep(Timeout.Infinite); } else Debug.Print("No volumes found"); Debug.Print("Exiting"); Thread.Sleep(Timeout.Infinite); } } }
And add référence:
Microsoft.SPOT.IO
SecreLabs.NETMF.IO
System.IO
Regards
Thierry
#5
Posted 19 May 2012 - 05:47 PM
#6
Posted 19 May 2012 - 06:05 PM
#7
Posted 20 May 2012 - 08:46 PM
#8
Posted 20 May 2012 - 09:32 PM
Hi
newb here... just a quick question re SD cards... Am I right in thinking that an 8GB card, for example, would not work at all in the NetduinoPlus? I've been trying to do something with one (an 8GB happens to be the only size I have lying around) but I can't seem to access any System.IO functionality. I get errors in Debug mode if I include any System.IO file/directory statements. I'm using v4.2 SDK and firmware.
Any input gratefully received
Thanks
Louise
Most 1 or 2 GB ones work. There was a beta version that the 4 & 8 GB worked, but that code is not in 4.2 that I know of, so you are stuck with 1 & 2 GB.
#9
Posted 20 May 2012 - 09:40 PM
Ok - thanks for the info. I'll have to buy one in!Most 1 or 2 GB ones work. There was a beta version that the 4 & 8 GB worked, but that code is not in 4.2 that I know of, so you are stuck with 1 & 2 GB.
Cheers
Louise
#10
Posted 21 May 2012 - 02:30 PM
#11
Posted 06 August 2012 - 07:19 AM
For me, the SD card also is not working because I bought a 8 gieg. (bigger counts :-))Most 1 or 2 GB ones work. There was a beta version that the 4 & 8 GB worked, but that code is not in 4.2 that I know of, so you are stuck with 1 & 2 GB.
I think the store (mediamarkt) will not exchange the card for a smaller one.
Is there any chance that the SD Card 4&8 Gb support will be implemented in the version 4.2
Because I program in VB, I am stuck on version 4.2
BTW, VB and 4.2 works very well.
Ellen
#12
Posted 06 August 2012 - 07:27 AM
#13
Posted 12 August 2012 - 08:01 AM
#14
Posted 13 August 2012 - 04:54 PM
I would recommend using NETMF 4.2. The SecretLabs.NETMF.IO assembly is included in the Netduino 4.2 SDK (on the download page).I can't find SecreLabs.NETMF.IO anywhere except mentioned in this thread. But then I'm only using 4.1. Will this only work with 4.2. I'm just starting out here and I'm looking for something like this to pour over and figure out modify as I need to.
That said, I _believe_ that the Netduino 4.1.1 beta firmware supported SecretLabs.NETMF.IO.dll as well.
Chris
#15
Posted 14 August 2012 - 12:35 AM
#16
Posted 14 August 2012 - 12:53 AM
Thanks Mate. Just out of curiosity, How stable is the current 4.2 release. I run beta software all the time and get a kick out of doing so. Some times it's more stable than the stable release. I'm even posting this from a Windows 8 tablet. But I'm new to this and I'm so nervous about hurting what my wife has described as my mistress.
.NET Micro Framework should be hitting the 4.2 QFE2 RTM release any day now. Once it does, it'll become our stable 4.2 firmware release.
It's possible that we'll find some glitches here or there after it ships, and we can address those if they crop up, but there are several bugfixes in 4.2 QFE2 (GC bugfixes, WinUSB drivers to avoid BSOD) that should make it a worthwhile upgrade.
Chris
#17
Posted 14 August 2012 - 01:38 AM
#18
Posted 28 May 2013 - 09:00 AM
Hello,
I have the same problem of fasbaker.
I have NP2, I have installed Netduino 4.2 SDK and I use VS2010, the target framework of my Application is .NET Micro Framework 4.2
The size of my MicroSD card is 1Gb.
[color=rgb(40,40,40);font-family:helvetica, arial, sans-serif;font-size:14px;]Using the Example code of mastronic, I don't found in my project with VS2010: [/color]
using Microsoft.SPOT.IO;
using SecretLabs.NETMF.Hardware.NetduinoPlus;
[color=rgb(40,40,40);font-family:helvetica, arial, sans-serif;]Using the [/color]example of VanderWekke, [color=rgb(40,40,40);font-family:helvetica, arial, sans-serif;]I don't found in my project with VS2010: [/color]
the object StreamWriter
What is my problem?
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users