Netduino home hardware projects downloads community

Jump to 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.
Photo

Read from UART & Write directly to SD file?


  • Please log in to reply
4 replies to this topic

#1 AndyC

AndyC

    New Member

  • Members
  • Pip
  • 3 posts

Posted 16 November 2011 - 02:03 PM

For my LinkSprite camera, I'm reading from COM1 into a buffer and then writing the picture to the SD card.
The file size of the jpg is about 50k. It's more memory than on the N+.
The challenge is because I can't read the buffer in one shot, I'm getting lines in the picture from buffering.
Is it possible to do something instead of:
<pseudo code>
FileStream fs = File.Create("\\SD\\mypicture.jpg");
SerialPort p = new SerialPort("COM1", 38400, Parity.None, 8, StopBits.One);
byte [] buffer = new byte[512];
while ( until EOF) {
   read(buffer,0, 512);
  fs.write(buffer,0, 512);
}
p.Dispose()
fs.close

to write something that writes directly to the SD card without a buffer?

Thanks
Andrew

#2 Spork

Spork

    Advanced Member

  • Members
  • PipPipPip
  • 105 posts

Posted 17 November 2011 - 02:31 AM

Hi Andy.

I think you might want to look at DataReceived. You can create an event handler for this event type and have it write out to the SD card. Since interrupts might come in quick succession, you might need to make sure that the event handler protects its critical section so that there aren't threading issues.

Somewhere in the forums there is a SerialHelper class which builds up a buffer in response to DataReceived events. You might want to hunt it down and use it as a starting point. Instead of building up a buffer, you'd be writing to SD.

Do you know, in advance, how many bytes the JPG will be? If not, it will probably be a little tricky to detect the end of the image.

#3 AndrewC

AndrewC

    New Member

  • Members
  • Pip
  • 9 posts

Posted 17 November 2011 - 01:51 PM

Thanks for the idea of using DataReceived. I'll take a look at it. I do have other interrupts running, but I can turn them off when taking a picture. Regarding the JPEG file, the LinkSprite camera tells you both, the file size and there is a EOF marker. I'm checking both, and then issueing a warning that it may be an invalid file if I don't get both. I'm still playing around with the baud rate and timing. I'm getting a valid file 75% of the time, but all pictures have streaks in them. I think something goes out of alignment when I get a Read() timeout instead of having bytes to read from the UART. If the DataReceived interrupt only fires when there is data in the buffer, that may solve my problem. I'll try it shortly and let everyone know. Regards Andrew PS I think somehow I have 2 accounts - AndyC and AndrewC are both me!

#4 AndrewC

AndrewC

    New Member

  • Members
  • Pip
  • 9 posts

Posted 21 November 2011 - 05:43 PM

Just an FYI I found out that making the buffer size = 256 for the Linksprite camera will get the camera to take uncorrupted pictures 99% of the time. It's just slow, takes about 25 seconds to save the picture to the SD card. Changing the baud rate didn't materially change the time so I'm thinking it's writing the SD card that is slow. Andrew

#5 apitsuikka

apitsuikka

    New Member

  • Members
  • Pip
  • 2 posts

Posted 28 December 2011 - 01:12 PM

Just an FYI

I found out that making the buffer size = 256 for the Linksprite camera will get the camera to take uncorrupted pictures 99% of the time. It's just slow, takes about 25 seconds to save the picture to the SD card. Changing the baud rate didn't materially change the time so I'm thinking it's writing the SD card that is slow.

Andrew


Thanks for the ideas! I am also trying to get some pictures stored to SD, from Linksprite..
Not very succesful yet...
Could you throw with your solution -> apitsuikka@gmail.com to give a try?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.