Main Site Documentation

Display a picture captured on html page. (Fez Spider I)


#1

Hey ! First of all, forgive me for the mistakes i’ll make, I’m French.
Here is the thing :
I’m working on a school project: " a connected vivarium ".
And i’m kind of in a trouble right now.
The modules i’m using for this part are: Extender J11D 1.2 (to use the fez spider as an embedded server) ; Camera 1.1 ; USB Client DP (of course). There are lot of others connected modules for the whole project but those are the ones needed for what i’m working on atm.

Sooo, i’m trying to display the picture captured from the camera on the html page I made. The HTML code is integrated into the C# Code. I created 2 clickable web events : one called " Capture Image ", the other one called " Display Image ", with their obvious goal. ^^
But everytime I’m clicking on the " Capture Image " link on the html page, this is what my debugger says:

Exception System.InvalidOperationException - 0x00000000 (1)

#### Message: No camera is connected.
#### Gadgeteer.Modules.GHIElectronics.Camera::TakePicture [IP: 0015] ####
#### Gadgeteer.Networking.WebEvent::OnWebEventReceived [IP: 004e] ####
#### System.Reflection.MethodBase::Invoke [IP: 0000] ####
#### Gadgeteer.Program::DoOperation [IP: 001a] ####
#### Microsoft.SPOT.Dispatcher::PushFrameImpl [IP: 0054] ####
#### Microsoft.SPOT.Dispatcher::PushFrame [IP: 001a] ####
#### Microsoft.SPOT.Dispatcher::Run [IP: 0006] ####
#### Gadgeteer.Program::Run [IP: 001d] ####

Une exception de première chance de type ‘System.InvalidOperationException’ s’est produite dans GTM.GHIElectronics.Camera.dll
Error invoking method “Gadgeteer.Networking.WebEvent” (check arguments to Program.BeginInvoke are correct)

I tried using different cameras, used my code on different computers, tried another mainboard, but It just doesn’t work… :c

Here is the main code for this part :

 Debug.Print("Le programme a bien démarré.");
            ethernetJ11D.UseDHCP();
            ethernetJ11D.NetworkInterface.Open();
            ethernetJ11D.UseStaticIP("10.17.15.229", "255.255.0.0", "10.17.254.1");
            ethernetJ11D.NetworkUp += ethernetJ11D_NetworkUp; //Création de l'évènement quand le network est UP
            ethernetJ11D.NetworkDown += ethernetJ11D_NetworkDown; //Création de l'évènement quand le network est DOWN

            //Créer l'evènement pour quand la photo est prise
            camera.PictureCaptured += camera_PictureCaptured;

CaptureImage = WebServer.SetupWebEvent("Capture");
            CaptureImage.WebEventReceived += CaptureImage_WebEventReceived;

            AfficherImage = WebServer.SetupWebEvent("Afficher");
            AfficherImage.WebEventReceived += AfficherImage_WebEventReceived;
void camera_PictureCaptured(Camera sender, GT.Picture picture)
        {
            Debug.Print("Enregistrement de la photo dans la variable");
            imagePrise = picture;
            Debug.Print("Image bien enregistrée dans la variable");
        }
void AfficherImage_WebEventReceived(string path, WebServer.HttpMethod method, Responder responder)
        {
            if (imagePrise != null)
            {
                responder.Respond(imagePrise);
                Debug.Print("responder(imagePrise) a fonctionné");
            }

            string affiche = "<html><body><p><img src= \"http://10.17.15.229/Afficher\"/></p></body></html>";
            byte[] bytes = new System.Text.UTF8Encoding().GetBytes(affiche);
            responder.Respond(bytes, "text/html");
        } 

        void CaptureImage_WebEventReceived(string path, WebServer.HttpMethod method, Responder responder)
        {
            Debug.Print("Evenement caméra lancé");

            
                camera.TakePicture();
                Debug.Print("La photo a bien été prise !");
           
            
        }

        //Page D'Acceuil 
        void sayHello_WebEventReceived(string path, WebServer.HttpMethod method, Responder responder)
        {
            string contenu = "<html>"
                + "<body>"
                
                + "<p> Ceci est un test de lien cliquable pour prendre une photo <a href=\"http://10.17.15.229/Capture\"> Cliquez ici </a> </p>"
                + "<p> Ceci est un test de lien cliquable pour afficher la photo prise <a href=\"http://10.17.15.229/Afficher\"> Cliquez ici </a> </p>"
                + "</body>"
                + "</html>";
            byte[] bytes = new System.Text.UTF8Encoding().GetBytes(contenu);
            responder.Respond(bytes, "text/html");
        }

What should I do ;-; !
Tell me if the code isn’t clear.
Thanks !


#2

@ Myad - Based on the error it looks like the camera isn’t being detected. I’d start a new project and just try to test the camera, displaying whatever it captures on a screen if you have one. https://www.ghielectronics.com/docs/36/usb-host#3127 shows a basic non-Gadgeteer example. It assumes the display is already configured.


#3

Only some thoughts, I don’t know if it shows the right direction.
(I suppose that you have a gadgeteer application)
The _WebEventReceived events run in another thread as the main thread, so the instance of the camera module may be out of the scope of the code in the event handler. Perhaps it helps to declare the instance of the camera module as public and static. Another way could be to set up a new gadgeteer event handler in the _WebEventReceived event ( the camera instance then should be in the scope).
Can you please show the declaration/instanciation of your modules and the webserver.
Does the webserver work correctly (reaches the Debug.Print Messages)?