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  | |||||||||||||||||||||||||||
A first chance exception of type 'System.InvalidOperationException' occurred in Microsoft.SPOT.Hardware.dll
Started by
Graham.fry
, Aug 21 2013 02:15 PM
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
1 reply to this topic
#1Posted 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); } } } }
#2Posted 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 topic0 members, 0 guests, 0 anonymous users | |||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||
This webpage is licensed under a Creative Commons Attribution-ShareAlike License. | |||||||||||||||||||||||||||