You are viewing an older revision! See the latest version
DotNET
Here is a thery early BETA library for interfacing .NET programs with mbed using the RPC.
Information
Required Prerequisites
- Visual Studio Express 2010 (C# ore Visual Basic - free download and use - must be registered within 30 days)
- .NET 4.0
- mbed with installed RPC Library
This could be used for:
- Controlling actuators from and reading data into .NET programs
- Serial (RS232)
- USB
- Bluetooth over serial or USB (e.g. Prolific chip)
- ZigBee over serial
- HTTP (comming soon)
- etc...
- Creating a GUI for mbed programs
All this work could be done because you folks and mbed members did a great job. I just ported the Java stuff to .NET in a very easy manner. Thanks to Michael and to all others.
.NET is potentially a great choice for interfacing to mbed over a network as it can be run over Communication Foundation and across many different platforms - e.g.: .NET Microframework (Appache Licence - absolutely free to use and portable to ARM controllers and others!), Compact Framework, Standard Framework .NET 4.0, ASP.NET, etc.). This page shows how to use the library to create .NET applications using serial and (later) over HTTP. HTTP is not implemented till now in this BETA, but will be soon.
Information
To use the mbedRPC library your mbed needs to be running code which can receive and execute RPC commands. Information and examples of this, can be found on the Interfacing-Using-RPC page. Compile and run the program for the type of transport mechanism you wish to use.
The .NET mbedRPC Library¶
Here is the mbedRPC .NET library as a Visual Studio 2010 Project zip file: mbedRPC.zip - (no HTTP supported till now - very early BETA!)
Here is an example of the code required to get started and flash some LEDs - like Michaels Java sample. This will run as a .NET Windows application.
mbedRPC_HelloWorld_DotNET
using System; using System.Windows.Forms; using System.Diagnostics; using System.Threading; using org.mbed.RPC; namespace mbedRPC.Test { public partial class mbedRCPTest : Form { DigitalOut led1; // mbed DigitalOut RPC declaration -> LED1 DigitalOut led2; // mbed DigitalOut RPC declaration -> LED2 mbed mbed; // the embed itself public mbedRCPTest() { InitializeComponent(); } private void btnExit_Click(object sender, EventArgs e) { try { mbed.delete(); Debug.Print("Complete"); } catch (NullReferenceException ex) { Debug.Print("No Reference: " + ex.Message); } this.Close(); } private void mbedRCPTest_Load(object sender, EventArgs e) { Debug.Print("mbed RPC Hello World"); //Create an mbed object for communication over USB (serial) mbed = new SerialRxTxRPC("COM10", 9600); //Or over serial: mbed = new SerialRPC("COM10", 9600); //Or later: mbed = new HTTPRPC("http://192.168.2.2") //Create new Digital Outputs on the mbed led1 = new DigitalOut(mbed, mbed.LED1); led2 = new DigitalOut(mbed, mbed.LED2); } private void flash(int n) { try { for (int i = 0; i < n; i++) { //Call the DigitalOut objects' methods led1.write(1); // on led2.write(0); // off Thread.Sleep(250); led1.write(0); // off led2.write(1); // on Thread.Sleep(250); } led2.write(0); // reset last state - all leds are off now } catch (NullReferenceException ex) { Debug.Print("No Reference: " + ex.Message); } } private void btnFlash_Click(object sender, EventArgs e) { btnFlash.Enabled = false; btnExit.Enabled = false; btnFlash.Text = "Is Flashing"; flash(10); btnFlash.Text = "Start Flash"; btnExit.Enabled = true; btnFlash.Enabled = true; } } }