Mono / C# and the Framebuffer


15 posts
by ordan77 » Mon Aug 27, 2012 4:52 pm
One of the things I want to do with one of my Pis is to use it to display certain status information on a full-HD screen.

I don't want to run a full X server for what will be fairly simple information, but I'd rather not do the whole thing on the text console either - the Framebuffer is the ideal halfway-house between these two.

However, to throw a spanner in the works, I'd like to throw the code together in C# atop the Mono framework - while I could do the whole thing in Perl, or take the time to learn Python, it'll be a whole lot easier to do this using the language I use every day anyway.

All so simple so far - I have Debian Wheezy (armel) running, Mono is installed and working, and MonoDevelop works suitably well for my needs (yes, I know I can code on another machine and run on the Pi - but some debugging will be necessary on the Pi itself which is why I got MonoDevelop running too).

Then I looked for ways to access the Framebuffer from C# / Mono:
  • Mono.Cairo: Really easy, but the DirectFB bindings are missing (or rather, the native Cairo library no longer seems to include DirectFB Surfaces)
  • GtkFB: Sounds straightforward, except for the fact that GtkFB isn't available precompiled on Wheezy (armel), and I'd rather not recompile the whole GDK / GTK+ / GTK# framework
  • Tao.Sdl: OK, with this, I can do some primitive drawing onto the Framebuffer, but the interface is very klunky and SDL itself is designed more for games than for my simple 2D user interface requirements
So, in short, Cairo and GtkFB won't work "out of the box", and SDL is about as painful as sleeping in the middle of the M25 during rush hour (don't try this kids!!!!!).

I've not been able to find any other way of accessing the Framebuffer from Mono / C#, so thought I'd turn to the community for some advice ... Has anyone out there managed to do anything constructive with direct Framebuffer access from the Mono runtime using Debian Wheezy (armel) - ideally using supplied packages, not libraries you've had to build / rebuild yourself? If you have, which libraries and interfaces did you use, and can you post basic examples?

Looking forward to any advice you guys might have ...
Posts: 3
Joined: Mon Aug 27, 2012 4:32 pm
by amigarulez » Mon Aug 27, 2012 7:28 pm
Read someone was working on DirectFB on RPi with some success haven't seen any released bits though.

MonoGame is also a cool framework, don't now it's framebuffer status.
Posts: 42
Joined: Wed Jul 18, 2012 10:16 am
by ordan77 » Mon Aug 27, 2012 8:21 pm
amigarulez wrote:Read someone was working on DirectFB on RPi with some success haven't seen any released bits though.

MonoGame is also a cool framework, don't now it's framebuffer status.


Thanks, I'll keep searching for info.

I pulled MonoGame down and spent a little time looking for a way to initialise on the Framebuffer, but it seems geared towards running within X - still have a few bits of the API to poke into though, but sadly it's not looking hopeful just now :(
Posts: 3
Joined: Mon Aug 27, 2012 4:32 pm
by christopher.landress » Mon Aug 27, 2012 9:09 pm
You might want to have a look at svgalib and/or libggi if you are absolutely sure you can't get used to SDL. Neither of which have wrappers for c# that I am aware of, meaning you'll have to make all your calls through [DLLImport]. Though I think you'll find that SDL is a dream compared to other graphics libs out there.

You can also run an xserver without all the overhead of a desktop and windowing environment fullscreen and with full acceleration (which is surprisingly lightweight). Then use System.Windows.Forms for all your drawing needs. I do something similar with a MAME frontend I built for my children.
Posts: 5
Joined: Sat Aug 25, 2012 7:03 am
by ordan77 » Tue Aug 28, 2012 6:42 pm
I'm slowly becoming resigned to the fact that DirectFB in Mono just isn't going to work ... So I think I'll be heading back to the Cairo library and taking a full-screen surface for my drawing needs.

Thanks for the replies though - much appreciated.

If I revisit DirectFB later on, I'll be sure to post and pass along my results :)
Posts: 3
Joined: Mon Aug 27, 2012 4:32 pm
by Twinkletoes » Tue Aug 28, 2012 6:47 pm
I've been using OpenGL from Mono - and OpenTK didn't have some of the required RPi init code. Rather than try and work out how OpenTK worked, instead I just wrote a simple C wrapper round the required APIs and then used P/Invoke to call into it. I'd recommend the same for you.
Posts: 210
Joined: Fri May 25, 2012 9:44 pm
by amigarulez » Tue Aug 28, 2012 7:09 pm
Twinkletoes wrote:Rather than try and work out how OpenTK worked, instead I just wrote a simple C wrapper round the required APIs and then used P/Invoke to call into it. I'd recommend the same for you.
Any code you be willing to share?:)
Posts: 42
Joined: Wed Jul 18, 2012 10:16 am
by vng3333 » Tue Feb 19, 2013 5:35 am
ordan77 wrote:One of the things I want to do with one of my Pis is to use it to display certain status information on a full-HD screen.

I don't want to run a full X server for what will be fairly simple information, but I'd rather not do the whole thing on the text console either - the Framebuffer is the ideal halfway-house between these two.

However, to throw a spanner in the works, I'd like to throw the code together in C# atop the Mono framework - while I could do the whole thing in Perl, or take the time to learn Python, it'll be a whole lot easier to do this using the language I use every day anyway.

Then I looked for ways to access the Framebuffer from C# / Mono:

Looking forward to any advice you guys might have ...


This might be too late, but for benefit of others - why not accessing directfb though P/Invoke? Since you need to display certain status (which I guess is limited to rendering text and maybe charts,) a very limited set of directfb calls should be sufficient. I've been studying directfb for a few days now, and after noticing your post decided to create a proof of concept in C#, which was successful. However, my testbed is x86 Linux running in VirtualBox. But if you manage to get mono running on R-Pi, the PoC should compile and run there too. Also, while directfb team released a preliminary version for R-Pi, I think it only works on squeeze, not wheezy. I suspect it will be addressed any time soon though. For now, it may very well happen that instead of utilizing R-Pi graphics, directfb calls will fallback to software implementation.

Anyway, if anyone's interested, I can share my PoC code. Just let me know...
Posts: 3
Joined: Fri Oct 26, 2012 2:45 am
by amigarulez » Tue Feb 19, 2013 6:25 am
vng3333 wrote:This might be too late, but for benefit of others - why not accessing directfb though P/Invoke? Since you need to display certain status (which I guess is limited to rendering text and maybe charts,) a very limited set of directfb calls should be sufficient. I've been studying directfb for a few days now, and after noticing your post decided to create a proof of concept in C#, which was successful. However, my testbed is x86 Linux running in VirtualBox. But if you manage to get mono running on R-Pi, the PoC should compile and run there too. Also, while directfb team released a preliminary version for R-Pi, I think it only works on squeeze, not wheezy. I suspect it will be addressed any time soon though. For now, it may very well happen that instead of utilizing R-Pi graphics, directfb calls will fallback to software implementation.

Anyway, if anyone's interested, I can share my PoC code. Just let me know...

I'm interested;)
Posts: 42
Joined: Wed Jul 18, 2012 10:16 am
by 3gws » Tue Feb 19, 2013 8:41 am
vng3333, I would very much appreciate if you could share your work with us.

Thanks you for the offer.

Regards

3gws
Posts: 49
Joined: Sat Oct 20, 2012 10:32 am
by vng3333 » Tue Feb 19, 2013 8:14 pm
Posts: 3
Joined: Fri Oct 26, 2012 2:45 am
by 3gws » Wed Feb 20, 2013 12:32 am
Thanks for posting your work. I will give this a go.

Regards

3gws
Posts: 49
Joined: Sat Oct 20, 2012 10:32 am
by amigarulez » Wed Feb 20, 2013 9:50 am

Thanks for sharing!
Posts: 42
Joined: Wed Jul 18, 2012 10:16 am
by thetemplar » Mon Apr 08, 2013 3:20 pm
Hey,
irst, thanks for sharing, but I get an error when running "sudo ./line" (and it freezes the whole console)

Code: Select all
(!) [ 2020:    0.000] --> Caught signal 11 (at 0xb6d2e000, invalid permissions) <--


I have a complete new installation and followed the guide.
But no monitor worked (i also tried "FRAMEBUFFER=/dev/fb1 ./line" for my gpio-connected TFT).

Anyone the same or an idea?
Posts: 12
Joined: Tue Mar 26, 2013 10:48 am
by thetemplar » Tue Apr 16, 2013 10:35 pm
Anyone?
Does it work on your pi?
Posts: 12
Joined: Tue Mar 26, 2013 10:48 am