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

时间:2012-12-09 16:15:24

标签: c# .net-micro-framework

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

使用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();
             }
         }
    } 

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

我如何编译代码?

我从“专家.NET微框架”一书中采用了这个例子。

1 个答案:

答案 0 :(得分:6)

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

所以而不是

 private static void port_OnInterrupt(uint port, uint state, TimeSpan time)

 private static void port_OnInterrupt(uint port, uint state, DateTime time)

另一个提示:而不是

 interruptPort.OnInterrupt += new NativeEventHandler(port_OnInterrupt);

你可以写

 interruptPort.OnInterrupt += port_OnInterrupt;

相当但更具可读性。