andycb / pisharp Goto Github PK
View Code? Open in Web Editor NEWRaspberry Pi GPIO Library for .NET
License: MIT License
Raspberry Pi GPIO Library for .NET
License: MIT License
This isn't an issue with PiSharp, but more of a general discussion about creating programs that don't require to be run as root to access the GPIO.
I added the pi
user to the gpio
group, usermod -a -G gpio pi
. Logged out and back in again and I was then able to control the GPIO via the command line without the need for sudo. However when I ran a program like LibGPIODemo1 (again without sudo) it would throw exceptions complaining about not having permission to access a pins files.
After doing a bit of digging it seems that when a pin is exported it takes a little while for the directory structure for that pin to be set up under /sys/class/gpio
and for the group permission on that directory to be set to gpio
. If a non-sudo program tries to access one of the pins' files before the group is changed a permission exception will be raised.
A solution which worked in my case was to put a call to Thread.Sleep(200
at the end of the Export() method in LibGpio.cs. This will of course slow down the starting up of a program by 200ms for each call to Export().
Another more involved option might be to split the SetupChannel() method into two methods one to set export the pin the other to set the direction (this is actually done but the methods are private). This way an application using the library could do all the exports first, wait 200ms, then setup the direction of the pin. This would only require one delay rather than a delay after every export.
There are of course issues with using a delay like this. For instance if other programs were running and putting load on the CPU it might take longer than 200ms to set up the group. It might be possible to wait on the creation of the pins direction file and the setting of it's group to gpio
before continuing.
I'm new to the Raspberry Pi so it could be I'm missing something obvious. If I am please let us know, or if there are other ways to solve the permission issue I'd be interested in hearing about them as well.
Hello!
OS: Windows 7
VB.NET always gives me an error message like written in title, when running test application and clicking the Button1:
`
Imports PiSharp.LibGpio
Imports PiSharp.LibGpio.Entities
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
LibGpio.Gpio.SetupChannel(BroadcomPinNumber.Four, Direction.Output)
LibGpio.Gpio.SetupChannel(BroadcomPinNumber.Eighteen, Direction.Input)
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
LibGpio.Gpio.OutputValue(BroadcomPinNumber.Four, True)
End Sub
End Class
`
It denies the access to the path written in the "LibGpio.cs" unter GetGpioPath() in line 470:
private string GetGpioPath() { if (Environment.OSVersion.Platform == PlatformID.Win32NT || Environment.OSVersion.Platform == PlatformID.Win32Windows || Environment.OSVersion.Platform == PlatformID.Win32S || Environment.OSVersion.Platform == PlatformID.WinCE) { // If we're running under Windows, use a Windows format test path return "C:\\RasPiGpioTest"; } }
Doesn't matter which path i'm filling in there (i tried different paths in my user directory or on another hard disk): the error rests. I tried to run the application as administrator and from the compiled .exe. It doesn't work.
Thank you!
Running PiSharpGpio on Raspberry Pi and Mac results in a File Not Found exception in LibGpio.Export( BroadcomPinNumber pinNumber) when trying to open the file stream for the "export" file.
The attempt to open /tmp/RasPiGpio/export fails since the file doesn't exist (the directory does exist).
When opening a FileStream in FileMode.Truncate the file must already exist.
After put in a "fix" for not been able to find the "export" file, PiSharpGpio ran on my Mac. However, towards the end it threw a file not found exception in the LibGpio.UnExport( BraodcomPinNumber pinNumber) method.
The file /tmp/RasPiGpioTest/unexport does not exist and I can't seem to find where it should be created.
The file must exist when using FileMode.Open in the FileStream constructor.
LibGpio.GetGpioPath() is not picking up that the code is running on a Mac. The issue seems to be that the Environment.OSVersion.Platform is not returning PlatformID.MacOSX but is instead returning PlatformID.Unix.
Need to also check for PlatformID.Unix
See discussion here http://www.mono-project.com/docs/faq/technical/#how-to-detect-the-execution-platform
When using PiSharp, "Physical pin 13" is refered to "Broadcom Pin 21" which doesn't work on my Raspberry Pi B+
I don't know why but it seems that this Pin has two broadcom number, and in my case it was the number "27" so I had to edit your code and change line 45 of Entities/BroadcomPinNumbers.cs
I don't know much about it but maybe it's related to the model
Hi,
You might want to consider adding a method such as:
CloseChannel( BroadcomPinNumber pinNumber)
which will unexport a pin. Would be useful in cleanup code at the end of a program.
Cheers,
Paul
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.