【问题标题】:How to fix a Memory Map Failed Exception for GPIO write on raspberry pi如何修复树莓派上 GPIO 写入的内存映射失败异常
【发布时间】:2017-06-02 13:41:22
【问题描述】:

我正在尝试使用 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 

我该如何解决?

【问题讨论】:

    标签: c# monodevelop raspberry-pi2 gpio


    【解决方案1】:

    我曾尝试通过 pi 上的 monodevelop 以及使用 mono filename.exe 来运行它。都没有奏效。但当我使用sudo ./filename.exe 时它确实如此。

    【讨论】:

    • 另外,sudo mono filename.exe 做同样的事情并且有效(以防有人感到困惑)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-15
    • 1970-01-01
    • 1970-01-01
    • 2020-02-20
    • 1970-01-01
    相关资源
    最近更新 更多