Serial Camera NullReferenceException

“An unhandled exception of type ‘System.NullReferenceException’ occurred in GTM.GHIElectronics.SerCam.dll”

Error occurs when I call TakePicture on a serial camera. Also, anyone have a sample code for video capture using serCam?

@ TechDev - I think that exception occurs when serial data from the cam is either corrupt or not seen. You may want to look here for further information.
http://www.tinyclr.com/forum/topic?id=9085

I have 2 serial cameras. Both are exhibiting the same behavior (NullReferenceException) …

try registering for all the camera events

Please show stack-trace

I just tested here on spider and Hydra, and there is no problem.
Can you show us your code?

“…Also, anyone have a sample code for video capture using serCam?..”

And I hope this is what you want :))


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 TestSerCam4._2
{
    public partial class Program
    {
        // This method is run when the mainboard is powered up or reset. 
        byte[] datajpg;
        int index = 0;
        void ProgramStarted()
        {
            /*******************************************************************************************
            Modules added in the Program.gadgeteer designer view are used by typing 
            their name followed by a period, e.g.  button.  or  camera.
            
            Many modules generate useful events. Type +=<tab><tab> to add a handler to an event, e.g.:
                button.ButtonPressed +=<tab><tab>
            
            If you want to do something periodically, use a GT.Timer and handle its Tick event, e.g.:
                GT.Timer timer = new GT.Timer(1000); // every second (1000ms)
                timer.Tick +=<tab><tab>
                timer.Start();
            *******************************************************************************************/


            // Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
            Debug.Print("Program Started");
            serCam.StartDataCaptured += new SerCam.StartDataCapturedEventHandler(serCam_StartDataCaptured);
            serCam.OnDataCaptured += new SerCam.DataCapturedEventHandler(serCam_OnDataCaptured);
            serCam.FinishDataCaptured += new SerCam.FinishDataCapturedEventHandler(serCam_FinishDataCaptured);
            new Thread(VideoStreamming).Start();
        }
        void VideoStreamming()
        {
            while (true)
            {
                if (!serCam.isBusy)
                {
                    serCam.TakePicture();
                }
                else Thread.Sleep(50);
            }
        }
        void serCam_FinishDataCaptured(SerCam sender)
        {
            display_T35.SimpleGraphics.DisplayImage(new Bitmap(datajpg, Bitmap.BitmapImageType.Jpeg), 0, 0);
        }
        
        void serCam_OnDataCaptured(SerCam sender, byte[] data)
        {
            if (index + data.Length > datajpg.Length)
            {
                throw new Exception("Error");
            }
            Array.Copy(data, 0, datajpg, index, data.Length);
            index += data.Length;
        }

        void serCam_StartDataCaptured(SerCam sender, int sizeImage)
        {
            index = 0;
            datajpg = new byte[sizeImage];
        }
    }
}

Could this be an internal attempt to fire an event when the user has not registered for it?

Started a new topic for my post… http://www.tinyclr.com/forum/topic?id=11161

@ Tomas - Hello Tomas and welcome to the community. Can you please start a new thread with your question? This thread is getting messy ot provide enough help.

Same for @ hoss please