/PiNet

Primary LanguageC#

PiNet - .NET (C#) wrapper for the Raspberry Pi

Provides .NET access to the RPi's IOs through the RPi's Linux file drivers. Configures the device tree (optionally) as necessary.

The following IOs are current complete:

  • PWM
  • GPIO

If you're using the other IOs, please contribute to this library.

The following projects are included:

  • PiNet.csproj - This contains the IO device wrappers
  • PiNet.Test - Unit tests - should run on any hardware (PC)
  • PiNet.InteractiveTests - To be run on the RPi to allows command-line experimentation with the ports
  • ConsoleUi - Simple menuing system used by the InteractiveTests project

Setting up Mono on the Raspberry Pi

Unfortunately, as of this writing (Dec 22, 2014), there isn't a mono package for Weezy on ARMhf, otherwise installing mono would be as easy as this command (on Debian):

# DOESN'T WORK - there is not a package available yet.  But see below...
sudo apt-get install mono-complete

You could pull down the source and let the RPi churn on compiling that for about a day, but fortunately, "pingfu" has kindly provided a .deb package for us.

Make sure that you setup networking on your RPi first:

  • Setup your network interface to share with the USB adapter.

  • Setup your RPi to use the USB host as the gateway:

      /sbin/route add default gw 192.168.7.1
    

Update your package list:

sudo apt-get update

Now download this package then install it like this:

sudo dpkg -i mono*.deb

You can download the above file using commands, or download the file on your host computer and SCP it (I use WinSCP) to your RPi.

Compiling And Running

There are various options for compiling and running on Mono on the RPi.

  • If you are using HDMI or VNC you can install MonoDevelop on the Raspberry Pi and use it as per normal.
  • Supposedly Monodevelop (Xamarin) has remote debugging capabilities, but I've yet to get it to work. Instructions are here.
  • What I've been trying to get working is remote debugging from Visual Studio. The Mono soft debugger appears to be rather mature, as it's used by Unity and Xamarin, and I think even when debugging locally by the MonoDevelop environment, but integration with Visual Studio is the main issue.

There is a promising looking Visual Studio plugin, MonoDebugger which automatically packages up the build output, copies it to the Linux target, converts the PDBs to MDBs and starts the soft debugger, but unfortunately the present state of the VS debugger integration is so limited as to be nearly useless. So far I've found it to only work for a single thread and to inspect local variables.
I wish I had more time to give to help that project along because it would be so useful if it worked well.

Please let us know if you find a better debugging option.

Dependencies

PiNet depends on:

  • JSON.Net - only for one small bit of logging code which could easily be changed.

PiNet.Test depends on:

  • Moq
  • NUnit - added packages include VS testing integration so you don't have to install NUnit.

Logging

There are no direct dependencies on a logging frameworks. Instead, hook the Logging.LogError and/or Logging.LogTrace events and log through your favorite framework, or simply dump log entries to the console.

Usage Examples

Interacting with a Pulse Width Modulation device:

    var device = new Pwm(P9_14);
    device.DutyPercent = 35;
    device.Run = true;

Interacting with a GPIO:

    var device = new Gpio(P8_12);
    device.Direction = RPiDirection.Out;
    device.IsHigh = true;