Excepiton when using both the SerialCameraL2 and WiFiRS21 module together

I need help resolving the following exception when using both the SerialCameraL2 and WiFiRS21 module together in the same program. The following code the will generate the Exception using Visual Studio 2012, NETMF 4.3 and a Spider Motherboard. If you comment out the following lines of code for one of the two modules the modules work great independently. As soon as you include both “this.serialCameraL2.StartStreaming();” and “netif.NetworkInterface.Join(“SSID”, “PASSWORD”);” an exception is thrown.

I have also tried putting both SerialCameraL2 and WiFi in to their own separate threads but I still get the same exception and switching up the different ports on the spider the modules are plugged into.

I welcome any ideas you may have.

Exception System.InvalidOperationException - 0x00000000 (6)

Message: Failed to read all of the bytes from the port.

Gadgeteer.Modules.GHIElectronics.SerialCameraL2::ReadBytes [IP: 002f]

Gadgeteer.Modules.GHIElectronics.SerialCameraL2::ReadFrameBuffer [IP: 0076]

Gadgeteer.Modules.GHIElectronics.SerialCameraL2::UpdateStreaming [IP: 003d]

A first chance exception of type ‘System.InvalidOperationException’ occurred in GTM.GHIElectronics.SerialCameraL2.dll


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;

using GHI.Networking;
using Microsoft.SPOT.Net.NetworkInformation;
using Microsoft.SPOT.Hardware;

namespace Clean.Camera
{
    public partial class Program
    {
        private GT.Timer timerCamera;

        void ProgramStarted()
        {

            this.serialCameraL2.StartStreaming();

            this.timerCamera = new GT.Timer(100);
            this.timerCamera.Tick += this.timer_Tick;
            this.timerCamera.Start();
            //The camera is now taking pictures.

            netif.NetworkInterface.Join("SSID", "PASSWORD");

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

            Debug.Print("IP: " + netif.NetworkInterface.IPAddress);
            Debug.Print("Mask: " + netif.NetworkInterface.SubnetMask);
            Debug.Print("Gateway: " + netif.NetworkInterface.GatewayAddress);
            //The network is now ready to use.
        }

        private void timer_Tick(GT.Timer timer)
        {
            if (this.serialCameraL2.NewImageReady)
            {
                var image = this.serialCameraL2.GetImage();
                Debug.Print("Image Size " +image.Height + "x" + image.Width);
                image.Dispose();
            }
        }
    }
}


//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:4.0.30319.18444
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace Clean.Camera {
    using Gadgeteer;
    using GTM = Gadgeteer.Modules;
    
    
    public partial class Program : Gadgeteer.Program {
        
        /// <summary>The USB Client DP module using socket 1 of the mainboard.</summary>
        private Gadgeteer.Modules.GHIElectronics.USBClientDP usbClientDP;
        
        /// <summary>The Serial Camera L2 module using socket 9 of the mainboard.</summary>
        private Gadgeteer.Modules.GHIElectronics.SerialCameraL2 serialCameraL2;
        
        /// <summary>The WiFi RS21 module using socket 6 of the mainboard.</summary>
        private Gadgeteer.Modules.GHIElectronics.WiFiRS21 netif;
        
        /// <summary>This property provides access to the Mainboard API. This is normally not necessary for an end user program.</summary>
        protected new static GHIElectronics.Gadgeteer.FEZSpider Mainboard {
            get {
                return ((GHIElectronics.Gadgeteer.FEZSpider)(Gadgeteer.Program.Mainboard));
            }
            set {
                Gadgeteer.Program.Mainboard = value;
            }
        }
        
        /// <summary>This method runs automatically when the device is powered, and calls ProgramStarted.</summary>
        public static void Main() {
            // Important to initialize the Mainboard first
            Program.Mainboard = new GHIElectronics.Gadgeteer.FEZSpider();
            Program p = new Program();
            p.InitializeModules();
            p.ProgramStarted();
            // Starts Dispatcher
            p.Run();
        }
        
        private void InitializeModules() {
            this.usbClientDP = new GTM.GHIElectronics.USBClientDP(1);
            this.serialCameraL2 = new GTM.GHIElectronics.SerialCameraL2(9);
            this.netif = new GTM.GHIElectronics.WiFiRS21(6);
        }
    }
}

@ sytak - Can you initialize and join the WiFi network before you start streaming?

John, unfortunately I get the exact same exception using the following code. The “this.serialCameraL2.StartStreaming();” line creates the exception. The wireless connection establishes but as soon as it hits the StartStreaming() it throws the exception.

Any other thoughts? Willing to try just about anything at this point.


void ProgramStarted()
{
    netif.NetworkInterface.Join("SSID", "PASSWORD");
    while (netif.NetworkInterface.IPAddress == "0.0.0.0")
    {
        Debug.Print("Waiting for DHCP");
        Thread.Sleep(250);
    }
    Debug.Print("IP: " + netif.NetworkInterface.IPAddress);
    Debug.Print("Mask: " + netif.NetworkInterface.SubnetMask);
    Debug.Print("Gateway: " + netif.NetworkInterface.GatewayAddress);
    //The network is now ready to use.

    this.serialCameraL2.StartStreaming();
    this.timerCamera = new GT.Timer(100);
    this.timerCamera.Tick += this.timer_Tick;
    this.timerCamera.Start();
    //The camera is now taking pictures.
}

@ sytak - I was able to run that code without issue. The camera will sometimes fail to read all the bytes given that it is serial, especially under heavier loads that wifi can introduce just by running. That will throw off the current image but it should get back in sync. Are you actually drawing the image to the screen? Can you post the contents of the tick function?

Ok, It must be something that has to do with my config. I’m using version 4.3.3.0 for both the TinyBooter and TinyCLR. Can you confirm this is the current version (see attached image) I should be using.

Here is the tick function. To keep it simple I’m just writing the image size for now.


private void timer_Tick(GT.Timer timer)
 {
   if (this.serialCameraL2.NewImageReady)
      {
          var image = this.serialCameraL2.GetImage();
          Debug.Print("Image Size " +image.Height + "x" + image.Width);
            image.Dispose();
       }
}

You can check what SDK you have installed by looking in your PC, in the GHI directory starting C:\Program Files (x86)\GHI Electronics

Look at the release notes, it will tell you what version you have.

From this page .NET Micro Framework – GHI Electronics you can see what the latest SDK version is. Right now it is “NETMF and Gadgeteer Package 2014 R2”.

Brett - Thanks! This is exactly what I was looking for. I have installed the latest SDK and according to the release notes the latest firmware too.

Resolved

I was able to resolve this exception by the following steps:

  1. Run the FEZ Config application
  2. Click on the Network Configuration then RS910 tab
  3. Click on the Load RS910 WiFi Config button
  4. The click the Apply Rs910 WiFi Config button

Then re-ran the code and it worked perfectly without the exception.

1 Like

Hi,

I have a similar problem with serial camera 1 and ENC28 module.
I have tested your solution but doesn’t work for me :(.

The problem appear when I link the ENC28 module on the Program.gasgeteer interface :frowning:

Have you an another idea ?

Thank you in advance.

Micka

@ Micka - There is an issue in NETMF where interrupts are disabled when you use networking that can cause a loss of serial data. This loss of data can cause corrupt or exceptions in the serial camera.

HI John,
Thank you for your answer.
How I can correct this ?

Thank you in advance.

Micka

@ Micka - Sadly there is no way to correct it. It is an issue with Microsoft’s code in NETMF that we are waiting on them to fix.

having the same issue on the FEZ Hydra serial cam + enc28 :’(

any news regarding the fix?

@ Alexandru - It’s already been fixed, it’ll be in the next SDK release.

EDIT: It actually has not been fixed. I was thinking of a different issue.

1 Like

Who fixed it?

@ njbuch - I’m sorry, I read the latest post and thought it was referring to our bitmap converter bug. That bug has been fixed for the next SDK. The actual issue in this thread with serial has not been fixed.

Ahh. Thanks for clarifying.

Guys, Thanks for info!

@ John, sorry to derail the subject a bit but is the ‘bitmap converter bug’ you’re referring to the one that causes things to render incorrectly to the DisplayN18 display? I remember it being mentioned in another thread and I’m running into that problem now. If it is indeed that bug you’re referring to, do we have a time estimate for when the fix will be available or if it could be available separately from the SDK?

If it is not the problem you’re referring to then just ignore me :slight_smile:

@ blekk - That is the problem I was referring to. We are looking to get an SDK out soon for it, but we don’t have anything definite just yet and regretfully there is not a patch available.