Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Can Anyone Help with Error "An unhandled exception of type 'System.Exception' occurred in Microsoft.SPOT.Hardware.dll "


  • Please log in to reply
10 replies to this topic

#1 Danny

Danny

    Member

  • Members
  • PipPip
  • 10 posts

Posted 10 March 2011 - 03:06 PM

Hi I have this error when trying to build and send to my Netduino "An unhandled exception of type 'System.Exception' occurred in Microsoft.SPOT.Hardware.dll" Can anyone help or suggest why? I'm fairly new to this so any help would be appreciated. If the code is needed I can upload. Thanks Danny

#2 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 10 March 2011 - 03:10 PM

Hi Danny, Could you post (a bit of) your code please? Without knowing what the code does it's very hard to tell since it's quite a generic error.
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#3 Danny

Danny

    Member

  • Members
  • PipPip
  • 10 posts

Posted 10 March 2011 - 03:12 PM

Here is my code, I did say I was new to this. Obviously its not finished but I cant test it without it uploading. It has worked before but now has this error. Thanks Danny using System; using System.Threading; using Microsoft.SPOT; using Microsoft.SPOT.Hardware; using SecretLabs.NETMF.Hardware; using SecretLabs.NETMF.Hardware.Netduino; namespace Object_Avoidance_Robot { static class Program { static void Main() { int index = 0; //Initialise index variable const uint periodL = 3000; // This produces a pulse every 10ms (100Hz) of duration 1 ms const uint durationL = 2000; PWM pwmL = new PWM(Pins.GPIO_PIN_D5); const uint periodR = 3000; // This produces a pulse every 10ms (100Hz) of duration 1 ms const uint durationR = 2000; PWM pwmR = new PWM(Pins.GPIO_PIN_D6); pwmL.SetPulse(periodL, durationL); pwmR.SetPulse(periodR, durationR); OutputPort LeftMF = new OutputPort(Pins.GPIO_PIN_D0, false); OutputPort LeftMR = new OutputPort(Pins.GPIO_PIN_D1, false); OutputPort RightMF = new OutputPort(Pins.GPIO_PIN_D2, false); OutputPort RightMR = new OutputPort(Pins.GPIO_PIN_D8, false); InputPort echo = new InputPort(Pins.GPIO_PIN_D13, false, Port.ResistorMode.Disabled); //Initialises inputport if (true) //Begin Infinate while loop { OutputPort trigger = new OutputPort(Pins.GPIO_PIN_D12, false); trigger.Write(true); Thread.Sleep(10 / 1000); trigger.Write(false); Thread.Sleep(250); //Set trigger pin low ?? } for (index = 0; index < 1000; index++) //for loop to wait for echo { if (echo.Read() == true) //If echo is recieved { avoidThread(); //Run avoidThread function } //End if { forward(); //Run forward function } //End for loop } //End while (loop back to top) } //End function main static void avoidThread() //AvoidThread { //Start Fucntion reverse(); //Run Reverse function turnRight(); //Run turnright function } //End AvoidThread (return) static void forward() //Forward Function { OutputPort LeftMF = new OutputPort(Pins.GPIO_PIN_D0, true); //set pins for forward movement OutputPort LeftMR = new OutputPort(Pins.GPIO_PIN_D1, false); OutputPort RightMF = new OutputPort(Pins.GPIO_PIN_D2, true); OutputPort RightMR = new OutputPort(Pins.GPIO_PIN_D8, false); Thread.Sleep(1000); // sleep 1 second } //End function static void reverse() { OutputPort LeftMF = new OutputPort(Pins.GPIO_PIN_D0, false); //// forward OutputPort LeftMR = new OutputPort(Pins.GPIO_PIN_D1, true); OutputPort RightMF = new OutputPort(Pins.GPIO_PIN_D2, false); OutputPort RightMR = new OutputPort(Pins.GPIO_PIN_D8, true); Thread.Sleep(1000); } static void turnRight() { OutputPort LeftMF = new OutputPort(Pins.GPIO_PIN_D0, true); //// turn right OutputPort LeftMR = new OutputPort(Pins.GPIO_PIN_D1, false); OutputPort RightMF = new OutputPort(Pins.GPIO_PIN_D2, false); OutputPort RightMR = new OutputPort(Pins.GPIO_PIN_D8, true); Thread.Sleep(1000); } static void turnLeft() { OutputPort LeftMF = new OutputPort(Pins.GPIO_PIN_D0, false); //// turn left OutputPort LeftMR = new OutputPort(Pins.GPIO_PIN_D1, true); OutputPort RightMF = new OutputPort(Pins.GPIO_PIN_D2, true); OutputPort RightMR = new OutputPort(Pins.GPIO_PIN_D8, false); Thread.Sleep(1000); } } }

#4 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 10 March 2011 - 03:19 PM

Can't test it here since I got no Netduino at my side, but this line I found interesting:
Thread.Sleep(10 / 1000);
You could just as well type:
Thread.Sleep(0.01);
It will be rounded down, so it actually does:
Thread.Sleep(0);

This, since Thread.Sleep requires an integer (int millisecondsTimeout) as parameter, 0.01 is not an integer number.


On which line occures the error?
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#5 Danny

Danny

    Member

  • Members
  • PipPip
  • 10 posts

Posted 10 March 2011 - 03:27 PM

Hi Thanks for the reply The thread.sleep(10/1000) is the only way it would work as you said it would not allow me to enter 0.01. The error points, well highlights this line in the code in the reverse function but also highlights all the OutputPort words. static void reverse() { OutputPort LeftMF = new OutputPort(Pins.GPIO_PIN_D0, false); //Error xxxxxxxxxxxxxxx Its a strange one. thanks

#6 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 10 March 2011 - 03:34 PM

I get the same error on the second line when I do this in an empty program:
OutputPort op1 = new OutputPort(Pins.GPIO_PIN_D0, false);
OutputPort op2 = new OutputPort(Pins.GPIO_PIN_D0, false);
Fixed it by doing this:
OutputPort op1 = new OutputPort(Pins.GPIO_PIN_D0, false);
op1.Dispose();
OutputPort op2 = new OutputPort(Pins.GPIO_PIN_D0, false);

I think the reference to the pin still existed so it gave the error. I'm no expert myself, but you should try to dispose the ports at the end of the functions "reverse" etc.
You could also consider to make your output ports global in your class.

Besides that, I'm curious of what you would like to do with a Thread.Sleep(0); (since that's what it actually does at that point, not 0.01)
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#7 Stefan

Stefan

    Moderator

  • Members
  • PipPipPip
  • 1965 posts
  • LocationBreda, the Netherlands

Posted 10 March 2011 - 03:50 PM

Oh and one more thing:
if (true) //Begin Infinate while loop
{
I think you mean:
while (true) //Begin Infinate while loop
{

:)
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs

#8 Danny

Danny

    Member

  • Members
  • PipPip
  • 10 posts

Posted 10 March 2011 - 03:53 PM

Hi Tried the dispose() and I still have the same error but it breaks and highlights the line that I have xxxxxxxxxxxxxxx static void reverse() { OutputPort LeftMF = new OutputPort(Pins.GPIO_PIN_D0, false); //// forward LeftMF.Dispose(); OutputPort LeftMR = new OutputPort(Pins.GPIO_PIN_D1, true); LeftMR.Dispose(); OutputPort RightMF = new OutputPort(Pins.GPIO_PIN_D2, false); RightMF.Dispose(); OutputPort RightMR = new OutputPort(Pins.GPIO_PIN_D8, true); xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx RightMR.Dispose(); I'm stumped a bit more reading I think ; ) Thanks

#9 Danny

Danny

    Member

  • Members
  • PipPip
  • 10 posts

Posted 10 March 2011 - 03:55 PM

Hi again Thank the reason I put if (true) is because when I put while I have the error unreachable code on the for (index = 0; index < 1000; index++) that seemed to solve it But again Im no expert. Thanks

#10 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 10 March 2011 - 04:10 PM

I don't think you need to dispose the OutputPort-s and instantiate them again - create them once and then just call Write() with the needed values:

static OutputPort leftMF = new OutputPort(Pins.GPIO_PIN_D0, false); // Initially off
static OutputPort leftMR = new OutputPort(Pins.GPIO_PIN_D1, false);
static OutputPort rightMF = new OutputPort(Pins.GPIO_PIN_D2, false);
static OutputPort rightMR = new OutputPort(Pins.GPIO_PIN_D8, false);

static void forward()
{
  leftMF.Write(true);
  leftMR.Write(false);
  rightMF.Write(true);
  rightMR.Write(false);
}

static void reverse()
{
  leftMF.Write(false);
  leftMR.Write(true);
  rightMF.Write(false);
  rightMR.Write(true);
}

// Similarly for turnLeft, turnRight...


#11 Troll feeder

Troll feeder

    Advanced Member

  • Members
  • PipPipPip
  • 38 posts
  • LocationArizona, USA

Posted 18 March 2011 - 08:08 AM

Hi

I have this error when trying to build and send to my Netduino "An unhandled exception of type 'System.Exception' occurred in Microsoft.SPOT.Hardware.dll"

Can anyone help or suggest why? I'm fairly new to this so any help would be appreciated. If the code is needed I can upload.

Thanks

Danny


I had the same error tonight on almost the same code. I checked the firmware level of my board and it was 4.1.0. Upgraded to 4.1.0.6 and the error went away.

Worth a look.

Mike.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.