SD huh?
#1
Posted 30 September 2010 - 03:01 AM
#2
Posted 30 September 2010 - 03:25 AM
#3
Posted 30 September 2010 - 03:35 AM
Steven,
To use the SD card, add the System.IO.dll reference to your project.
You may also want to update to the Netduino Plus v4.1.0.4 beta firmware.
Chris
I will do that indeed!
#4
Posted 30 September 2010 - 03:56 AM
#5
Posted 30 September 2010 - 04:32 AM
The thread '<No Name>' (0x2) has exited with code 0 (0x0). Current Directory: \SD\DCIM\100CANON File: \SD\DCIM\100CANON\IMG_0870.JPG File Size: 1418885 read 128 bytes... #### Exception System.ArgumentException - 0xfd000000 (1) #### #### Message: #### Microsoft.SPOT.IO.NativeFileStream::Read [IP: 0000] #### #### System.IO.FileStream::Read [IP: 0028] #### #### NetduinoPlusSample.Program::Main [IP: 00bd] #### A first chance exception of type 'System.ArgumentException' occurred in Microsoft.SPOT.IO.dll An unhandled exception of type 'System.ArgumentException' occurred in Microsoft.SPOT.IO.dll
And my code for reading:
using System; using System.Threading; using Microsoft.SPOT; using Microsoft.SPOT.Hardware; using SecretLabs.NETMF.Hardware; using SecretLabs.NETMF.Hardware.Netduino; using System.IO; namespace NetduinoPlusSample { public class Program { public static void Main() { string currentDirectory = @"\SD\DCIM\100CANON"; Debug.Print("Current Directory: " + currentDirectory); string[] directories = Directory.GetDirectories(currentDirectory); foreach (string directory in directories) { Debug.Print("Directory: " + directory); } string[] files = Directory.GetFiles(currentDirectory); foreach (string file in files) { Debug.Print("File: " + file); FileInfo fInfo = new FileInfo(file); Debug.Print("File Size: " + fInfo.Length); FileStream fStream = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.None, 1024); byte[] buffer = new byte[128]; int fileLocation = 0; while (fileLocation < fInfo.Length) { fileLocation += fStream.Read(buffer, fileLocation, System.Math.Min(128, (int)(fInfo.Length - fileLocation))); Debug.Print("\tread " + fileLocation + " bytes..."); } } } } }
#6
Posted 30 September 2010 - 04:53 AM
#7
Posted 30 September 2010 - 05:10 AM
Steven...what happens if you dispose of your filestream before opening another file?
I can try, but this is the same file, just the next 128 bytes of it where the exception is thrown.
#8
Posted 30 September 2010 - 06:02 AM
I can try, but this is the same file, just the next 128 bytes of it where the exception is thrown.
On second thought...
fileLocation += fStream.Read(buffer, fileLocation, System.Math.Min(128, (int)(fInfo.Length - fileLocation)));
fileLocation is 128 on your second loop--too high of an offset in your 128-byte buffer array. Did you want to pass 0 as your second parameter?
Chris
#9
Posted 30 September 2010 - 06:11 AM
Also, it looks like you can just use 128 for the 3rd parameter to FileStream.Read()...if it reads less than 128 bytes, then it should be OK (the method will return the actual number of bytes it read).On second thought...
fileLocation += fStream.Read(buffer, fileLocation, System.Math.Min(128, (int)(fInfo.Length - fileLocation)));
fileLocation is 128 on your second loop--too high of an offset in your 128-byte buffer array. Did you want to pass 0 as your second parameter?
Chris
~ David ~
#10
Posted 30 September 2010 - 01:46 PM
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users