繁体   English   中英

如何修复Rasberry pi上GPIO写入的内存映射失败异常

[英]How to fix a Memory Map Failed Exception for GPIO write on raspberry pi

我正在尝试使用Raspberry Sharp IO库写入Pi上的引脚。 但它在运行时给了我一个例外。 它以前有用,但不再有用。 为什么抛出这个错误?

using System;
using Raspberry.IO.GeneralPurpose;
using Raspberry.IO.GeneralPurpose.Behaviors;
using System.Threading;

  namespace blinky
    {
       class MainClass
     {
    public static void Main (string[] args)
    {

    // Here we create a variable to address a specific pin for output
    // There are two different ways of numbering pins--the physical numbering, and the CPU number
    // "P1Pinxx" refers to the physical numbering, and ranges from P1Pin01-P1Pin40
        var led1 = ConnectorPin.P1Pin03.Output();

    // Here we create a connection to the pin we instantiated above
    var connection = new GpioConnection(led1);

    while(true){
        // Toggle() switches the high/low (on/off) status of the pin
        connection.Toggle(led1);
        Thread.Sleep(250);
    }

//  connection.Close();

}
}
 }

返回此错误:

pi@Minion01 ~/blinky1/blinky1/bin/Debug $ mono ./blinky1.exe

Unhandled Exception:
Raspberry.IO.Interop.MemoryMapFailedException: Exception of type 'Raspberry.IO.Interop.MemoryMapFailedException' was thrown.
  at Raspberry.IO.Interop.MemoryMap.ThrowOnError[MemoryMapFailedException] (IntPtr result) [0x00000] in <filename unknown>:0 
  at Raspberry.IO.Interop.MemoryMap.Create (IntPtr address, UInt32 size, MemoryProtection protection, MemoryFlags memoryflags, Int32 fileDescriptor, UInt32 offset) [0x00000] in <filename unknown>:0 
  at Raspberry.IO.GeneralPurpose.GpioConnectionDriver..ctor () [0x00000] in <filename unknown>:0 
  at Raspberry.IO.GeneralPurpose.GpioConnectionSettings.GetBestDriver (GpioConnectionDriverCapabilities capabilities) [0x00000] in <filename unknown>:0 
  at Raspberry.IO.GeneralPurpose.GpioConnectionSettings.get_DefaultDriver () [0x00000] in <filename unknown>:0 
  at Raspberry.IO.GeneralPurpose.GpioConnectionSettings..ctor () [0x00000] in <filename unknown>:0 
  at Raspberry.IO.GeneralPurpose.GpioConnection..ctor (Raspberry.IO.GeneralPurpose.GpioConnectionSettings settings, IEnumerable`1 pins) [0x00000] in <filename unknown>:0 
  at Raspberry.IO.GeneralPurpose.GpioConnection..ctor (Raspberry.IO.GeneralPurpose.PinConfiguration[] pins) [0x00000] in <filename unknown>:0 
  at blinky.MainClass.Main (System.String[] args) [0x00000] in <filename unknown>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: Raspberry.IO.Interop.MemoryMapFailedException: Exception of type 'Raspberry.IO.Interop.MemoryMapFailedException' was thrown.
  at Raspberry.IO.Interop.MemoryMap.ThrowOnError[MemoryMapFailedException] (IntPtr result) [0x00000] in <filename unknown>:0 
  at Raspberry.IO.Interop.MemoryMap.Create (IntPtr address, UInt32 size, MemoryProtection protection, MemoryFlags memoryflags, Int32 fileDescriptor, UInt32 offset) [0x00000] in <filename unknown>:0 
  at Raspberry.IO.GeneralPurpose.GpioConnectionDriver..ctor () [0x00000] in <filename unknown>:0 
  at Raspberry.IO.GeneralPurpose.GpioConnectionSettings.GetBestDriver (GpioConnectionDriverCapabilities capabilities) [0x00000] in <filename unknown>:0 
  at Raspberry.IO.GeneralPurpose.GpioConnectionSettings.get_DefaultDriver () [0x00000] in <filename unknown>:0 
  at Raspberry.IO.GeneralPurpose.GpioConnectionSettings..ctor () [0x00000] in <filename unknown>:0 
  at Raspberry.IO.GeneralPurpose.GpioConnection..ctor (Raspberry.IO.GeneralPurpose.GpioConnectionSettings settings, IEnumerable`1 pins) [0x00000] in <filename unknown>:0 
  at Raspberry.IO.GeneralPurpose.GpioConnection..ctor (Raspberry.IO.GeneralPurpose.PinConfiguration[] pins) [0x00000] in <filename unknown>:0 
  at blinky.MainClass.Main (System.String[] args) [0x00000] in <filename unknown>:0 

我该怎么办呢?

我试图通过pi上的monodevelop运行它,也使用mono filename.exe 都没有奏效。 但是当我使用sudo ./filename.exe时它就这样做了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM