2

stm32f4discoveryVS2010を使用して.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();
             }
         }
    } 

コンパイル時に、次のエラーが発生します。 No overload for 'port_OnInterrupt' matches delegate 'Microsoft.SPOT.Hardware.NativeEventHandler'

コードをコンパイルするにはどうすればよいですか?

この例は、「Expert.NETMicroframework」という本から引用したものです。

4

1 に答える 1

6

ドキュメントには最後の引数が a であると記載されていますが、私が使用している .net マイクロフレームワークではTimeSpan実際に a であると思います。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;

これは同等ですが、より読みやすくなっています。

于 2012-12-09T17:11:08.887 に答える