我正在尝试使aspnet核心web应用程序在我的树莓派上运行。该应用程序使用Bifrost与树莓的GPIO进行交互,但是每次执行sudo dotnet run
时,它都会失败,并显示错误
Using launch settings from /home/pi/Desktop/keypad-alarm/keypad-alarm-server/Properties/launchSettings.json...
Write value High to pin at /sys/class/gpio/gpio17/value
Unhandled Exception: System.UnauthorizedAccessException: Access to the path '/sys/class/gpio/gpio17/value' is denied. ---> System.IO.IOException: Operation not permitted
--- End of inner exception stack trace --- at
System.IO.FileStream.WriteNative(ReadOnlySpan`1 source) at
System.IO.FileStream.FlushWriteBuffer() at
System.IO.FileStream.FlushInternalBuffer() at
System.IO.FileStream.Flush(Boolean flushToDisk) at
System.IO.FileStream.Flush() at
System.IO.StreamWriter.Flush(Boolean flushStream, Boolean flushEncoder) at
System.IO.StreamWriter.Dispose(Boolean disposing) at
System.IO.TextWriter.Dispose()
at System.IO.File.WriteAllText(String path, String contents) at
Bifrost.Devices.Gpio.GpioPin.Write(GpioPinValue pinValue) at
keypad_alarm_server.TweetController.Tweet(Int32 milliseconds) in
/home/pi/Desktop/keypad-alarm/keypad-alarm-server/TweetController.cs:line 25 at
keypad_alarm_server.Program.Main(String[] args) in /home/pi/Desktop/keypad-alarm/keypad-alarm-server/Program.cs:line 15
我应该提到的是,我什至在Program.cs中启动Web服务器之前,都会立即将GPIO 17设为高电平以发出蜂鸣声。
我如何确保dotnet具有访问gpio的足够权限?
答案 0 :(得分:0)
好吧,像往常一样,花了很多时间在发布问题之后,您会在某个地方找到答案...
未经授权的异常非常令人误解,因为缺少的是c#中的以下语句:setText
pin.SetDriveMode(GpioPinDriveMode.Output);