Camera not connecting after adding ethernetj11d module

Dear all,

I have the following very simple code to stream video to the LCD display in a Fez Spider GHI kit:

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.Presentation.Shapes;
using Microsoft.SPOT.Touch;

using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;

namespace CameraTest
    public partial class Program
        // This method is run when the mainboard is powered up or reset.   
        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>

            // Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
            Debug.Print("Program Started");

            camera.BitmapStreamed += camera_BitmapStreamed;
            camera.CameraConnected += camera_CameraConnected;
            button.ButtonReleased += button_ButtonReleased;

        void button_ButtonReleased(Button sender, Button.ButtonState state)
            Debug.Print("Button pressed");

        void camera_CameraConnected(Camera sender, EventArgs e)
            Debug.Print("Camera connected");

        void camera_BitmapStreamed(Camera sender, Bitmap e)
            displayTE35.SimpleGraphics.DisplayImage(e, 0, 0);

The code works fine. However, after adding the ethernetJ11d module to the project and consequently this line is added to Program.generated.cs:

The camera does not connect, or rather, the callback function [em]camera_CameraConnected[/em] never gets called. Therefore, I can't use the camera while ethernetj11D is included in the project (I get camera not connected exceptions).

I am using Visual Studio 2012 Express on Windows 7 64 bits. This is the firmware I have:
 Loader (TinyBooter) version information: on this computer. on this device.
 >>> The Loader (TinyBooter) is up to date. <<<

 Firmware (TinyCLR) version information: on this computer. on this device.
 >>> The Firmware (TinyCLR) is up to date. <<<

Any help will be greatly appreciated!

Kind regards,

Might be a power issue. try with a powered Ethernet hub.

Thank you Mike for the quick reply. I am not sure if it is a power issue. I tried with the Ethernet module connected to a powered switch and also disconnected, with the same results. The only action that fixes the camera is commenting out this line:

Removing this line will work regardless of whether the ethernetj11d module is physically connected (and therefore drawing power) or not to the FEZ Spider board.

@ fexadom - Oooops. I meant a powered USB hub. I am working on a project now, and I had a problem when I initialized the builtin ethernet port. The problem went away when I inserted a USB switch instead of directly connecting to the PC USB port.

Thanks Mike. Ok, I got my hands on a Hema USB 2.0 hub, connected a 5V 2A power supply to it and tried to run everything again using the hub. I got the same results. So, no luck, still stuck. I saw other new topics in the forum where they are running into trouble with the Camera 1.1 module. Perhaps this error provides a clue? Can anyone replicate this error? Thanks in advance guys for your help.

Hi everybody,

In case anyone is interested, I found a workaround for this problem. Simply remove this line:

from [em]Program.generated.cs[/em] and add it in [em]Program.cs[/em] in the CameraConnected callback:


 void camera_CameraConnected(Camera sender, EventArgs e)
     Debug.Print("Camera connected");
     this.ethernetJ11D = new GTM.GHIElectronics.EthernetJ11D(7);

It is not the best option, after all it is never a good idea to edit generated code but so far it is the only solution I found that allows me to use the camera module and the ethernet module at the same time in the GHI Fez Spider kit.

Good luck with your projects!

@ fexadom - We have investigated the issue and it looks like it is a race condition. Ethernet takes awhile to initialize, so when you leave it in its default generated state, there is a delay before ProgramStarted is called. As a result, the camera is initialized and CameraConnected is called before Ethernet initialization finishes and you configure the event handlers. Instead of moving the Ethernet line, I would add the following to the bottom of program started:

camera.CameraConnected += camera_CameraConnected;

if (camera.Connected)
 camera_CameraConnected(camera, null);

Make sure camera_CameraConnected can handle getting called twice because there is still a small race condition between the event subscription and if.