I just got my serial camera today and tried the example code from Dat in his post at http://www.tinyclr.com/forum/topic?id=9506&page=1#msg94738 (although changed to use a button to trigger when to capture a photo instead of a loop, I did try your threaded loop method but with same result), but the FinishedDataCapture event never fires. I added some Debug.Print lines, below is the output. This is on a Hydra. Am I doing something wrong?
Here is the code that produced the above…
using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Touch;
using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;
namespace SerialCameraScratch
{
public partial class Program
{
byte[] datajpg;
int index = 0;
void ProgramStarted()
{
button.ButtonPressed += new Button.ButtonEventHandler(button_ButtonPressed);
//serCam.SetImageSize(SerCam.Camera_Resolution.SIZE_QQVGA);
serCam.OnDataCaptured += new SerCam.DataCapturedEventHandler(serCam_OnDataCaptured);
serCam.FinishDataCaptured += new SerCam.FinishDataCapturedEventHandler(serCam_FinishDataCaptured);
serCam.StartDataCaptured += new SerCam.StartDataCapturedEventHandler(serCam_StartDataCaptured);
display_TE35.SimpleGraphics.AutoRedraw = true;
}
void button_ButtonPressed(Button sender, Button.ButtonState state)
{
if (serCam.isBusy)
{
Debug.Print("Camera is busy, try again in a couple of seconds.");
}
else
{
Debug.Print("Taking picture...");
serCam.TakePicture();
}
}
void serCam_StartDataCaptured(SerCam sender, int sizeImage)
{
index = 0;
datajpg = new byte[sizeImage];
Debug.Print("Image size to capture: " + sizeImage);
}
void serCam_FinishDataCaptured(SerCam sender)
{
Debug.Print("Finished capturing image from camera, displaying on screen.");
display_TE35.SimpleGraphics.DisplayImage(new Bitmap(datajpg, Bitmap.BitmapImageType.Jpeg), 0, 0);
}
void serCam_OnDataCaptured(SerCam sender, byte[] data)
{
if (index + data.Length > datajpg.Length)
{
Debug.Print("serCam_OnDataCaptured() ERROR.");
}
Array.Copy(data, 0, datajpg, index, data.Length);
index += data.Length;
Debug.Print("OnDataCaptured: Index = " + index + ", datajpg.Length = " + datajpg.Length + ", data.Length = " + data.Length + ", datajpg.Length - index = " + (datajpg.Length - index));
}
}
}