- Netduino Forums
- → Evotodi's Content
The Netduino forums have been replaced by new forums at community.wildernesslabs.co.
This site has been preserved for archival purposes only
and the ability to make new accounts or posts has been turned off.
Evotodi's Content
There have been 2 items by Evotodi (Search limited from 01-July 23)
#36200 SD Only Write First File But Not Second
Posted by
Evotodi
on 28 September 2012 - 08:08 PM
in
Netduino Plus 2 (and Netduino Plus 1)
coyttl,
Adding a using statement around the streamwriter did not help.
Another quirk i have found is after flashing the 4.2 QFE2 tiny-boot-decompressor.bin with sam-ba the reset pin will not reset the netduino plus. Works fine with the 4.1 tiny-boot-decompressor.bin
#35985 SD Only Write First File But Not Second
Posted by
Evotodi
on 25 September 2012 - 07:49 PM
in
Netduino Plus 2 (and Netduino Plus 1)
Hello all,
I have run into a issue I cannot find a way around. My main program calls MakeSD, which checks for an SD card, removes all files on the SD card, creates a file called inVision.cfg, creates another file called config.cfg, this all works on firmware 4.2 RC1. However when I update to 4.2 QFE2 that is when things go bad... MakeSD is called, checks for SD card, removes all files, creates the file inVision.cfg correctly, creates the file config.cfg but does not write anything into it. If i swap the order of operations and create the config.cfg first, then inVision.cfg is created but contains no data.
The only way for it to work is flash 4.2 RC1 onto the Netduino.
Any help or insight would greatly be appreciated.
Justin
Some information:
Things I've tried:
The Code:
I have run into a issue I cannot find a way around. My main program calls MakeSD, which checks for an SD card, removes all files on the SD card, creates a file called inVision.cfg, creates another file called config.cfg, this all works on firmware 4.2 RC1. However when I update to 4.2 QFE2 that is when things go bad... MakeSD is called, checks for SD card, removes all files, creates the file inVision.cfg correctly, creates the file config.cfg but does not write anything into it. If i swap the order of operations and create the config.cfg first, then inVision.cfg is created but contains no data.
The only way for it to work is flash 4.2 RC1 onto the Netduino.
Any help or insight would greatly be appreciated.
Justin
Some information:
- Netduino Plus
- 2 gig sandisk sd card
- .NET Micro Framework SDK v4.2 (QFE2)
- Netduino SDK v4.2: 64-bit
- Netduino Flashed with 4.2 QFE2
Things I've tried:
- Add/Remove sw.dispose and file.dispose
- Make the FileStream and StreamWriter varilbles different between routines
- Add a delay between routines
- Flash TinyBooterDecompressor.bin for 4.2 QFE2
- Different brand 2gig SD cards
- Beat my head on the desk while uploading the program (didn't work!)
The Code:
public bool MakeSD() { if (!VolumeExist()) { Debug.Print("No SD Card"); return false; } RemFiles(); Debug.Print("SD Cleaned"); if (MakeConfigFile()) { Debug.Print("CFG Conplete"); if (MakeMacFile()) { Debug.Print("MAC Complete"); } } Debug.Print("SD Complete"); Thread.Sleep(1000); return true; } private bool VolumeExist() { VolumeInfo[] volumes = VolumeInfo.GetVolumes(); foreach (VolumeInfo volumeInfo in volumes) { if (volumeInfo.Name.Equals("SD")) return true; } return false; } public bool RemFiles() { try { string[] filePaths = Directory.GetFiles(@"\SD\"); foreach (string filePath in filePaths) { Debug.Print(filePath.ToString()); try { File.Delete(filePath); } catch (Exception f) { Debug.Print("File Delete Error"); Debug.Print(f.ToString()); } } } catch (Exception e) { Debug.Print("RemFiles Error"); Debug.Print(e.ToString()); } return true; } public bool MakeMacFile() { string original_string = MAC(); byte[] original_data = UTF8Encoding.UTF8.GetBytes(original_string); int[] new_data = new int[17]; ushort a = 0; for (int i = 0; i <= original_data.Length - 1 ; i++) { a = Convert.ToUInt16(original_data[i].ToString()); new_data[i] = a * 16; } try { FileStream file = new FileStream(@"\SD\inVision.cfg", FileMode.Create); StreamWriter sw = new StreamWriter(file); foreach (int l in new_data) { sw.WriteLine(l.ToString()); } sw.WriteLine("EOF"); sw.Flush(); sw.Close(); file.Close(); file.Dispose(); sw.Dispose(); Debug.Print("MAC Saved !"); } catch(Exception e) { Debug.Print("MakeMacFile"); Debug.Print(e.ToString()); } return true ; } public bool MakeConfigFile() { FileStream file = new FileStream(@"\SD\config.cfg", FileMode.Create); StreamWriter sw = new StreamWriter(file); string[] config = new string[17]; config[0] = "192.168.1.100"; //IP config[1] = "255.255.255.0"; //Subnet config[2] = "192.168.1.1"; //Gateway config[3] = "True"; //DHCP enabled config[4] = "8.8.4.4"; //DNS Pri config[5] = "8.8.8.8"; //DNS Sec config[6] = "-39.7"; //tc offset (-41.7) config[7] = "0"; //rh offset config[8] = "0"; //wtf offset config[9] = "0"; //he offset config[10] = "0"; //hep offset config[11] = "0"; //wf offset config[12] = Server; //Server address config[13] = pingable.ToString(); //Server pingable config[14] = "True"; //FieldOn detect config[15] = "True"; //compressor detect config[16] = "EOF"; foreach (string l in config) { Debug.Print(l); sw.WriteLine(l.ToString()); } sw.Flush(); sw.Close(); sw.Dispose(); file.Close(); file.Dispose(); Debug.Print("Config Saved !"); return true; }
- Netduino Forums
- → Evotodi's Content
- Privacy Policy