如何在微框架中实现中断?

Mic*_*ack 2 c# .net-micro-framework

我无法stm32f4discovery使用VS2010在.NET中编译代码.

运用 NETMF 4.2

    using System;
    using System.Threading;
    using Microsoft.SPOT;
    using Microsoft.SPOT.Hardware;

    namespace MFConsoleApplication1
    {

        public class Program
        {
            private static InterruptPort interruptPort;

            public static void Main()
            {
                interruptPort =  new InterruptPort(Cpu.Pin.GPIO_Pin2,
                                               false,
                                               Port.ResistorMode.PullUp,
                                               rt.InterruptMode.InterruptEdgeLevelLow);

                interruptPort.OnInterrupt += new NativeEventHandler(port_OnInterrupt);


                 Thread.Sleep(Timeout.Infinite);
            }


             private static void port_OnInterrupt(uint port, uint state, TimeSpan time)
             {
                Debug.Print("Pin=" + port + " State=" + state + " Time=" + time);
                interruptPort.ClearInterrupt();
             }
         }
    } 
Run Code Online (Sandbox Code Playgroud)

在编译时,我收到以下错误: No overload for 'port_OnInterrupt' matches delegate 'Microsoft.SPOT.Hardware.NativeEventHandler'

我怎么能编译代码?

我从"Expert .NET Micro框架"一书中选择了这个例子.

tob*_*sen 6

即使文档声明最后一个参数是一个,TimeSpan我认为它确实是DateTime我在使用的.net微框架中的一个.

而不是

 private static void port_OnInterrupt(uint port, uint state, TimeSpan time)
Run Code Online (Sandbox Code Playgroud)

尝试

 private static void port_OnInterrupt(uint port, uint state, DateTime time)
Run Code Online (Sandbox Code Playgroud)

另一个提示:而不是

 interruptPort.OnInterrupt += new NativeEventHandler(port_OnInterrupt);
Run Code Online (Sandbox Code Playgroud)

你可以写

 interruptPort.OnInterrupt += port_OnInterrupt;
Run Code Online (Sandbox Code Playgroud)

这相当于但更具可读性.