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

A first chance exception of type 'System.InvalidOperationException' occurred in Microsoft.SPOT.Hardware.dll

servo A first chance exception

Best Answer Graham.fry , 03 September 2013 - 08:03 AM

For anybody that cares

 

If you having a problem using the hardware DLL in 4.3 (with servos) you need to uninstall all 4.3 sdk's and reinstall 4.2

 

This fixed my problem

Go to the full post


  • Please log in to reply
1 reply to this topic

#1 Graham.fry

Graham.fry

    Member

  • Members
  • PipPip
  • 15 posts

Posted 21 August 2013 - 02:15 PM

Hi

 

I am trying to get a servo working I copied this code from the internet when I run it, it fails with the following error

 

A first chance exception of type 'System.InvalidOperationException' occurred in Microsoft.SPOT.Hardware.dll

 

Any help will be appreciated

 

Thanks in advance

 

Graham

 

Attached is the code I am using on a netduino plus2 version 4.2.2

 

program.cs

 

using System.Threading;

using SecretLabs.NETMF.Hardware.Netduino;

using Microsoft.SPOT;

namespace MinelectricsV2

{

public class Program

{

static Servo[] servos = new Servo[4];

public static void Main()

{

//Netduino only has four PWM pins: GPIO_PIN_D5, 6, 9, and 10

servos[0] = new Servo(Pins.GPIO_PIN_D5);

servos[1] = new Servo(Pins.GPIO_PIN_D6);

servos[2] = new Servo(Pins.GPIO_PIN_D9);

servos[3] = new Servo(Pins.GPIO_PIN_D10);

while (true)

{

MoveServos(0);

MoveServos(90);

MoveServos(180);

}

}

private static void MoveServos(uint angle)

{

for (int i = 0; i < servos.Length; i++)

{

servos[i].Angle = angle;

}

Thread.Sleep(2000);

}

}

}

 

 

 

 

class.cs

 

using Microsoft.SPOT.Hardware;

using SecretLabs.NETMF.Hardware;

namespace MinelectricsV2

{

public class Servo

{

static PWM servo;

public Servo(Cpu.Pin pin)

{

servo = new PWM(pin);

servo.SetDutyCycle(dutyCycle: 0);

}

private uint _angle = 0;

public uint Angle

{

get

{

return _angle;

}

set

{

const uint degreeMin = 0;

const uint degreeMax = 180;

const uint durationMin = 500; // 480

const uint durationMax = 2300; // 2450

_angle = value;

if (_angle < degreeMin) _angle = degreeMin;

if (_angle > degreeMax) _angle = degreeMax;

uint dur = (_angle - degreeMin) * (durationMax - durationMin) / (degreeMax - degreeMin) + durationMin;

servo.SetPulse(period: 20000, duration: dur);

}

}

}

}

 

 

 



#2 Graham.fry

Graham.fry

    Member

  • Members
  • PipPip
  • 15 posts

Posted 03 September 2013 - 08:03 AM   Best Answer

For anybody that cares

 

If you having a problem using the hardware DLL in 4.3 (with servos) you need to uninstall all 4.3 sdk's and reinstall 4.2

 

This fixed my problem







Also tagged with one or more of these keywords: servo, A first chance exception

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.