This project is read-only.

Motivation

Sending and receiving data on Netduino and other .NET Micro Framework powered devices is quite low-level. Enough Connectivity aims at easing this process and also provides some (well, errrm, one as of now) drivers.

Usage

The package Enough.Connectivity contains base classes and extension methods.

The Enough.Connectivity.IBinaryConnection interface allows you to send data in byte[] arrays and to register the OnDataReceived and/or the OnStringReceived delegates.

This sample program runs on a Netduino board and turns the onboard LED on when receiving a corresponding command via Bluetooth:

using Enough.Connectivity;
using Enough.Connectivity.Seeedstudio;
[...]

public class Program
{

	private static OutputPort _led = new OutputPort(Pins.ONBOARD_LED, false);
	private static IBinaryConnection _connection;

	public static void Main()
	{
		SeeedstudioBluetoothShieldConnection btConnection = new SeeedstudioBluetoothShieldConnection();
		btConnection.Initialize(serialPortname: SerialPorts.COM2, bluetoothName: "SeeedBTSlave");
		_connection = btConnection;
		_connection.OnStringReceived += onStringReceived;
		Thread.Sleep(0);
	}

	private static void onStringReceived(IBinaryConnection sender, string data)
	{
		if (data == "on" || data == "off")
		{
			bool ledOn = "on".Equals(data);
			_led.Write(ledOn);
		}
		else
		{
			_connection.SendString("unknown command: " + data, sendLength: true);
		}
	}
}

For a real world example, please refer to the Light-O-Mator project.

Seeedstudio Bluetooth Shield Driver

The Enough.Connectivity.Seeedstudio.SeeedstudioBluetoothShieldConnection class contains a driver for the Seeedstudio Bluetooth Shield.

You can initialize the shield using following optional parameters in the Initialize() method:
  • serialPortname: the name of the serial port, defaults to SerialPorts.COM2
  • bluetoothName: the name of the Bluetooth shield, defaults to SeeedBTSlave
  • isMaster: defines whether the shield should be a master or a slave, defaults to false (slave)
  • allowPairedDevices: should paired devices be allowed to connect? Defaults to true.
  • allowAutoConnection: should the shield connect to the last paired device automatically? Defaults to false.
  • allowInquire: should the device allow being inquired (slave) or start inquiry (master)? Defaults to true.
  • pinCode: an optional PIN code, defaults to null (factory PIN is 0000)

Example:
SeeedstudioBluetoothShieldConnection btConnection = new SeeedstudioBluetoothShieldConnection();
btConnection.Initialize(serialPortname: SerialPorts.COM2, bluetoothName: "SeeedBTSlave");

Installation

You can install the Enough.MF.Connectivity package from NuGet. Right-click on the references of your project, select "Manage NuGet Packages..." and search for Enough.MF.Connectivity in the online tab.







Last edited Oct 17, 2013 at 8:35 PM by enoughrob, version 6