Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make System.Device.Gpio work on Mono #1095

Merged
merged 1 commit into from
Jun 1, 2020
Merged

Conversation

krwq
Copy link
Member

@krwq krwq commented May 30, 2020

Fixes #1089

Use workaround provided by Mono for the type loading issue.

cc: @Ellerbach

@krwq krwq requested a review from joperezr May 30, 2020 22:14
Copy link
Member

@joperezr joperezr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome thanks for fixing and for checking with the Mono team about the right fix. I assume we tested this suggestion they gave and it worked right?

@krwq
Copy link
Member Author

krwq commented Jun 1, 2020

@joperezr yes, I've tried if calling SpiDevice.Create/I2cDevice.Create/new GpioGontroller/PwmChannel.Create doesn't cause any TypeLoadException.

@krwq krwq merged commit 7d9d407 into dotnet:master Jun 1, 2020
@Ellerbach
Copy link
Member

Thanks a lot @krwq for fixing the issue! This new version works like a charm with mono on my Raspberry Pi Zero.

@R10Rasmus
Copy link
Contributor

I still have problems with System.Device.Gpio on mono (running on my Raspberry Pi Zero).
I use version 1.1.0-prerelease.20153.1 of System.Device.Gpio.
I get this error:
Unhandled Exception:
System.PlatformNotSupportedException: Operation is not supported on this platform.
at diod.Program.Main (System.String[] args) [0x0000c] in <807d9bdced0d4b01bab17bb49da4e5d9>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.PlatformNotSupportedException: Operation is not supported on this platform.
at diod.Program.Main (System.String[] args) [0x0000c] in <807d9bdced0d4b01bab17bb49da4e5d9>:0

hope you can help :)

@Ellerbach
Copy link
Member

@R10Rasmus, just a stupid question: are you running a .NET Framework 4.8 application on the Pi Zero? .NET Core application are not supported.
The fix provided solved my problem and it's perfectly working with a .NET Framework 4.8 application.

@R10Rasmus
Copy link
Contributor

@Ellerbach I did run a .Net Core version. I is now convert to an .NET Framework 4.8 application, but I get the same issue.
I am running it like this:

mono diode.exe
Hello World!

Unhandled Exception:
System.PlatformNotSupportedException: Operation is not supported on this platform.
at diode.Program.Main (System.String[] args) [0x0000c] in <00d189148f054da3a840744526508385>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.PlatformNotSupportedException: Operation is not supported on this platform.
at diode.Program.Main (System.String[] args) [0x0000c] in <00d189148f054da3a840744526508385>:0

@Ellerbach
Copy link
Member

@R10Rasmus , try from https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet5/nuget/v3/index.json one of the latest version like 1.1.0-prerelease.20276.1

@R10Rasmus
Copy link
Contributor

@Ellerbach I use version 1.1.0-prerelease.20153.1. If I try to install 1.1.0-prerelease.20276.1 from https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet5/nuget/v3/index.json I gen an dependency error:

Attempting to gather dependency information for package 'System.Device.Gpio.1.1.0-prerelease.20276.1' with respect to project 'C:\Users\rasmu\source\repos\pi\diod', targeting 'Any,Version=v0.0'
Gathering dependency information took 6,63 sec
Attempting to resolve dependencies for package 'System.Device.Gpio.1.1.0-prerelease.20276.1' with DependencyBehavior 'Lowest'
nuget : Unable to resolve dependency 'System.Memory'. Source(s) used: 'nuget.org', 'Gpio'.
At line:1 char:1

  • nuget install System.Device.Gpio -PreRelease -Source https://pkgs.dev ...
  •   + CategoryInfo          : NotSpecified: (Unable to resol...t.org', 'Gpio'.:String) [], RemoteException
      + FullyQualifiedErrorId : NativeCommandError
    
    
    

I still get this error, if I install System.Memory from nuget.org :(

@R10Rasmus
Copy link
Contributor

@Ellerbach I got it to work :)
I build System.Device.Gpio my self from master and then I installed libgpiod-dev on my Pi Zero.

@Ellerbach
Copy link
Member

I got it to work :)

Great! Yes, libgpiod-dev is needed in the Pi Zero. I have a service running for the last few weeks like a charm. Few things to keep in mind: you you want to manage gpio pin state changes, it's not working the best. If you have only 1 thread, then the events are coming in. If you start to have a large app with a lot of thread, then for some reason, you'll stop getting the events. So in this case, just do a thread dedicated to the pin change.

frogcrush pushed a commit to frogcrush/iot that referenced this pull request Oct 13, 2020
@github-actions github-actions bot locked and limited conversation to collaborators Dec 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

System.Device.Gpio does not work on Mono
4 participants