BLE-Shield goes NetDuino2
Hello everyone,
as promised I tested the BLE-Shield with NetDuino2. As expected the Shields worked without any big problems on this platform as well. I spent about an hour with @tamberg to get my initial code cleaned up and he and Etan Kissling showed my how clean C# code as to look like 🙂 Finally I added an additional folder called “netmf” to my BLE-Shield github repository https://github.com/michaelkroll/BLE-Shield where you can now find a complete Microsoft Visual C# 2010 Express project which has been tested with a NetDuino2 board running .NET Micro Framework SDK v4.2.
The complete code is not longer than the code snipped shown below:
using System; using System.IO.Ports; using System.Text; using System.Threading; using Microsoft.SPOT; using SecretLabs.NETMF.Hardware.Netduino; public class Program { public static void Main() { Debug.Print("BLE Shield"); var port = SerialPorts.COM1; // using D0 & D1 //var port = SerialPorts.COM2; // using D2 & D3 var bleShield = new SerialPort(port, 19200, Parity.None, 8, StopBits.None); bleShield.DataReceived += (sender, args) => { var receiveBuffer = new byte[16]; int bytesReceived = bleShield.Read(receiveBuffer, 0, receiveBuffer.Length); if (bytesReceived > 0) { Debug.Print("Bytes received: " + bytesReceived); Debug.Print(new String (Encoding.UTF8.GetChars(receiveBuffer))); } }; bleShield.Open(); while (true) { var random = new Random(); var sendBuffer = new byte[4]; random.NextBytes(sendBuffer); bleShield.Write(sendBuffer, 0, sendBuffer.Length); Thread.Sleep(1000); } } }Please contact me if you encounter any problems of have some comment regarding C#. Please keep in mind that this is my first C# app.
Cheers,
Michael.