Main Site Documentation

Spider, Camera & EthernetJ11D


#1

I’m having a problem with the Camera & EthernetJ11D modules on a Spider.

If I include the J11D module in designer the camera.CameraConnected and camera.BitmapStreamed events never fire. If I remove the J11D from the project the events are fired as expected.

Anybody else experienced this issue (or possibly confirm it)?


#2

It’s the usb cam andre.


#3

@ Sprigo - Can you post some code that reliably shows the problem? Using the latest 2014 R4 SDK, I had a camera and J11D module connected in the designer and both BitmapStreamed and CameraConnected fired fine.


#4

I suspect that it’s the setup on this machine then John. Just created a new project with the following.



namespace GadgeteerApp5
{
    public partial class Program
    {
        // This method is run when the mainboard is powered up or reset.   
        void ProgramStarted()
        {
            Debug.Print("Program Started");
            camera.CameraConnected += camera_CameraConnected;
            camera.BitmapStreamed += camera_BitmapStreamed;
        }

        void camera_BitmapStreamed(Camera sender, Bitmap e)
        {
            Debug.Print("Bitmap Streamed Event");
        }

        void camera_CameraConnected(Camera sender, EventArgs e)
        {
            Debug.Print("Camera Connected Event");
            camera.StartStreaming();
        }
    }
}

Before adding the EthernetJ11D I get the output shown in Camera1.jpg. After adding the J11D I don’t see the camera events fire. If I don’t add the J11D to designer but manually create an instance AFTER registering the camera event everything appears to work normally.


#5

@ Sprigo - When you say you manually created an instance after setting up the event, it worked, was it an instance of the EthernetJ11D module or the EthernetBuiltIn class from GHI.Networking? Have you by any chance tried with a different camera, Spider, or Ethernet module if you have any?


#6

@ John I’ve attached two screen shots showing the debugger output for the two setups. The code is as shown below.


    public partial class Program
    {
        // This method is run when the mainboard is powered up or reset.   
        void ProgramStarted()
        {
            Debug.Print("Program Started");

            // With these here the events always fire. (Camera1.jpg)
            //camera.CameraConnected += camera_CameraConnected;
            //camera.BitmapStreamed += camera_BitmapStreamed;

            #region Ethernet Connection

            EthernetJ11D ethernetJ11D = new EthernetJ11D(7);

            if (!ethernetJ11D.NetworkInterface.Opened)
                ethernetJ11D.NetworkInterface.Open();

            if (!ethernetJ11D.NetworkInterface.IsDhcpEnabled)
            {
                ethernetJ11D.NetworkInterface.EnableDhcp();
            }
            ethernetJ11D.NetworkInterface.EnableDynamicDns();

            while (ethernetJ11D.NetworkInterface.IPAddress == "0.0.0.0")
            {
                Debug.Print("Waiting for DHCP");
                Thread.Sleep(250);
            }

            Debug.Print("Connected to Network.");
            Debug.Print("IP Address : " + ethernetJ11D.NetworkInterface.IPAddress);
            Debug.Print("Gateway Address : " + ethernetJ11D.NetworkInterface.GatewayAddress);
            string[] DnsAddress = ethernetJ11D.NetworkInterface.DnsAddresses;
            foreach (string dnsAddress in DnsAddress)
            {
                Debug.Print("DNS Address : " + dnsAddress);
            }

            #endregion

            // With these here the events never fire. (Camera2.jpg)
            camera.CameraConnected += camera_CameraConnected;
            camera.BitmapStreamed += camera_BitmapStreamed;
        }

        void camera_BitmapStreamed(Camera sender, Bitmap e)
        {
            Debug.Print("Bitmap Streamed Event");
        }

        void camera_CameraConnected(Camera sender, EventArgs e)
        {
            Debug.Print("Camera Connected Event");
            camera.StartStreaming();
        }
    }
}


I’m running a bit late tonight but will try swapping out the kit tomorrow.


#7

@ Sprigo -The problem is a race condition. I’m guessing you have the camera connected to the Spider all the time. So, when you power up the device, the camera is seen and the CameraConnected event is fired. When you have the events early in ProgramStarted, you subscribe to them before our host controller finishes initializing the device and you catch the event. When you put them after the Ethernet initialization, too much time has passed and the event already fired so you missed it.

To work around this, you can check the CameraReady property. It returns true when the camera is connected and not currently taking a picture. So if it is true, you can just call StartStreaming as the camera is already connected.

In your sample program, at the bottom of ProgramStarted, I added the following and it worked:


// With these here the events never fire. (Camera2.jpg)
camera.CameraConnected += camera_CameraConnected;
camera.BitmapStreamed += camera_BitmapStreamed;

if (camera.CameraReady)
    camera.StartStreaming();


#8

You’re right John. by making that change I now receive the events correctly. Many thanks.


#9

any video of it working?


#10

@ ShieldJ - I’ve been side tracked by a couple of other projects so it’s still work in progress.