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

Interrupt event handler issue


Best Answer CW2, 20 February 2013 - 07:50 AM

Your interrupt handler has wrong parameters, the following should work:

static void switchInterrupt_OnInterrupt(uint data1, uint data2, DateTime time){  var port = (Cpu.Pin)data1;  var state = (data2 != 0);  lampOutput.Write(state);}
Go to the full post


  • Please log in to reply
3 replies to this topic

#1 msakms

msakms

    New Member

  • Members
  • Pip
  • 4 posts
  • LocationEgypt

Posted 19 February 2013 - 09:25 PM

I've been experimenting with interrupts on the Netduino while trying out VS2012 and I got this error message:

 

"Error  1  No overload for [color=#ff0000;]'switchInterrupt_OnInterrupt'[/color] matches delegate 'Microsoft.SPOT.Hardware.NativeEventHandler'  C:Usersmoodydocumentsvisual studio 2012ProjectsLED-TestingLED-TestingProgram.cs  19  44  LED-Testing"

AND

"Error  2  The type or namespace name 'ResourceUtility' does not exist in the namespace 'Microsoft.SPOT' (are you missing an assembly reference?)  C:Usersmoodydocumentsvisual studio 2012ProjectsLED-TestingLED-TestingResources.Designer.cs  30  45  LED-Testing"

 

Here's my code

using System;using System.Threading;using Microsoft.SPOT;using Microsoft.SPOT.Hardware;using SecretLabs.NETMF.Hardware;using SecretLabs.NETMF.Hardware.Netduino;namespace MicroFrameworkFlashlight{    public class MicroFrameworkFlashlight    {        static InputPort switchPin;        static OutputPort lampOutput;        static InterruptPort switchInterrupt;        public static void Main()        {            lampOutput = new OutputPort(Pins.ONBOARD_LED, false);            switchInterrupt = new InterruptPort(Pins.ONBOARD_SW1,false,Port.ResistorMode.PullDown,Port.InterruptMode.InterruptEdgeBoth);            switchInterrupt.OnInterrupt += switchInterrupt_OnInterrupt;                        while (true)            {                                Thread.Sleep(Timeout.Infinite);            }        }        static void switchInterrupt_OnInterrupt(Cpu.Pin port, bool state, TimeSpan time)        {            lampOutput.Write(state);        }    }}

 

I know this is a newbie issue but I've done some research and couldn't find anything so far.

Many thanks in advance & Cheers



#2 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 20 February 2013 - 07:50 AM   Best Answer

Your interrupt handler has wrong parameters, the following should work:
static void switchInterrupt_OnInterrupt(uint data1, uint data2, DateTime time){  var port = (Cpu.Pin)data1;  var state = (data2 != 0);  lampOutput.Write(state);}


#3 hanzibal

hanzibal

    Advanced Member

  • Members
  • PipPipPip
  • 1287 posts
  • LocationSweden

Posted 20 February 2013 - 09:42 AM

Tip of the day

If you hit the TAB key twice right after typing the "+=" when assigning a handler, VS will automatically generate stub code for the handler with the correct signature - this way, you allways get the parameters right.

switchInterrupt.OnInterrupt += switchInterrupt_OnInterrupt;


#4 msakms

msakms

    New Member

  • Members
  • Pip
  • 4 posts
  • LocationEgypt

Posted 20 February 2013 - 01:25 PM

[font="'comic sans ms', cursive;"]Thanks for the prompt response, everything works now.[/font]  :D






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.