mraa icon indicating copy to clipboard operation
mraa copied to clipboard

.Net Core / C# bindings

Open VladimirAkopyan opened this issue 7 years ago • 12 comments

I am looking for a cross-platform GPIO library that I can use as a basis for a C# applications. This seems to be as close as it gets (or am i wrong?). Now that .Net is open source we will soon have a release of C# run-time for Arm Linux. I want to see if there is any appetite to create bindings for C#, and if anyone would be willing to help.

VladimirAkopyan avatar Jul 01 '17 12:07 VladimirAkopyan

mraa is not cross-platform in a typical sense - it only supports Linux (various distros and kernel versions though), as it uses sysfs extensively, so if you have Windows for IOT in mind, that won't work, at least not without major development effort. There's mock platform, that compiles under MSYS in Windows, but that's a self-contained simulator, not an actual use of Windows system interfaces.

C# bindings for Linux should be doable though and would be quite cool to have, maybe even with the same SWIG used for other bindings.

alext-mkrs avatar Jul 01 '17 14:07 alext-mkrs

As @alext-mkrs mentions, sounds like you're using cross platform to mean cross board/arch rather than cross OS? If that's correct then mraa is a good choice (unbiased opinion obv ;-)).

How do you feel about swig generated C# bindings? If that would satisfy your need i'm happy to help. If it's manual bindings I'm also happy to include that but probably won't be able to provide all that much help since I know very little about C#...

arfoll avatar Jul 01 '17 16:07 arfoll

yeah, I meant "cross-board". I haven't tried SWIG yet 🚀 I also have not previously used MRAA, is there anything unusual I should be aware of? How's the performance?

VladimirAkopyan avatar Jul 03 '17 14:07 VladimirAkopyan

Maybe this is interesting also especially for the pru.

http://www.ofitselfso.com/BBBCSIO/BBBCSIO.php

mgiaco avatar Jul 05 '17 20:07 mgiaco

Hard to benchmark objectively. Generally I would say perf is pretty good. Our nodejs bindings are not well liked because they are not asynchronous but if you look at the python ones performance is really not far off C and largest overhead is the binding size itself. Most of this is because swig generated code has alot of redundant checks.

Try it out! It's really the only way. I think generating swig c# bindings for at least the basic stuff should be relatively easy. We can help you with the small niggles like getting isrs to work.

On 3 Jul 2017 15:06, "Vladimir Akopyan" [email protected] wrote:

yeah, I meant "cross-board". I haven't tried SWIG yet 🚀 I also have not previously used MRAA, is there anything unusual I should be aware of? How's the performance?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/intel-iot-devkit/mraa/issues/778#issuecomment-312654707, or mute the thread https://github.com/notifications/unsubscribe-auth/AAfZZtkPldgkAs-M8Obj6RSYxsWbi6D-ks5sKPVfgaJpZM4OLTnG .

arfoll avatar Jul 05 '17 20:07 arfoll

...and I happen to be working on a different project which is a cross-platform C# app, so while I'm far off from being an expert, I know a thing or two and would be glad to help as well, having firsthand mraa knowledge.

alext-mkrs avatar Jul 06 '17 10:07 alext-mkrs

Awesome. Thx @alext-mkrs.

IvanFarkas avatar Mar 21 '18 21:03 IvanFarkas

@VladimirAkopyan Have you made any progress. I'd like to do the same with swig.

IvanFarkas avatar Mar 21 '18 21:03 IvanFarkas

https://www.nuget.org/packages/SystemExt.Devices.Mraa/

Actualy it requires have libmraa installed, but i'm working on have an aditional NuGet called for example (SystemExt.Devices.Mraa.runtime.linux-arm) that will not require to have libmraa it will use a local compiled version of libmraa

deinok avatar Sep 21 '18 08:09 deinok

I'm open to transfer the ownership of the bindings to the MRAA project if they will promise still giving support to .NET

deinok avatar Sep 21 '18 08:09 deinok

Hi @deinok do you think this would work on Windows with a mock platform build? I'm thinking the new WSL feature in Win10 might help load the mraa ELF binary (once again pointing out Mock is key here because it doesn't use /sys or /dev) but I have no idea how you would tie that to .NET or MSVS from there...

Propanu avatar Sep 26 '18 20:09 Propanu

The lib by itself just make calls to libmraa.so using [DllImport]. So in theory, if in a WSL environment you can use libmraa, indirectly you can execute a .NET Core app inside the WSL using this bindings and should work pretty well. I think that the biggest problem for you will be setup libmraa inside WSL. Once done, it should be pretty easy access to the info using my package

deinok avatar Sep 26 '18 21:09 deinok