Receive .JPEG stream via serial port, store, and resend

The project I’m working on will be interfacing a Netduino 3 WIFI (C# .NET micro Framework) and a PC application (C# .NET Framework). A serial TTL camera will be connected to one of the Netduino’s COM ports and the PC app will connection to another COM port. All will communicate via 8 bit UART. I have been successful in sending and receiving byte[] between the PC, Netduino, and Camera which serve the purpose of sending and acknowledging commands. The main goal is to be able to send the ‘take image’ command to the camera and catch the .JPEG byte[] coming back. I want to start receiving the data once the data received event occurs. I’m not finding much information online but from what I’ve read I may have to use the serialport.basestream property, or a Bitmap Constructor (Stream). I’m just not very familiar with the concept of streams and hope someone could point me to some information or give an example of how to set this up.

Well for starters you’d need an SD card (I guess). With only ~164KB RAM you’ll run out of memory pretty quickly when working with images. The camera probably outputs images in jpeg format directly, this works fast and reliable.

I’m not sure what kind of camera you have so, it’s hard to give you other real advice. On adafruit’s site there’s an example with code for arduino:
With the code ( they use a library ( and it looks like for this camera you can simply read a block of bytes of the jpeg.

It sounds like you could just use read write methods from the serialport with an occasional flush to send of commands immediately. The buffer sizes required to work with the camera look small so it should be sufficient. You could also use events for receiving but I’m not sure if this would be more optimal, since in the end you’ll have to send a new request to get more data after handling the event. Obviously this is possible, but read write commands would be easier for testing, afterwards you can always optimise!

Streams are not that hard, you could see it as an array basically. With every read or write you’ll loop through the “array”. Depending on what kind of stream it is you can also seek to set the index where to start reading/writing from.
You can use a stream directly, they have read and write methods, but there are also stream readers/writers out there that make using streams a bit more streamlined (pun).
You can use stream.write to store the jpeg to the sd-card:
A StreamWriter can be used for storing text easily (for example)

Usually general C# tutorials for using streams and serialports should point you in a good direction anyway. You might not be able to use the exact same code as Micro .NET is more simple in available methods and classes, yet it should be possible to find the right methods + maybe some extra code to get the exact same result! :smiley: