LED Control
Controlling an LED on the Application Board is one of the simplest things to do from .NET, making it an excellent first thing to try. We'll work with the code from the included QuickTest app for this example. QuickTest as its provided uses the USB connection to the board, but you can uncomment the Ethernet code to experiment with that as well.
The QuickTest UI
The name of the LED subsystem on the board is appled - Application LED. There are 4 LEDs, numbered 0 - 3, and they have a state - whether they're on or off. The argument that comes after the address sets the value of state. So the OSC message we create will be in the form /subsystem/device/property argument
A simple way to send the message is to create a UI form with a checkbox. Then, in the routine that gets called when the checkbox is changed, send out an OSC message. Creating forms and attaching events to them is beyond the scope of this tutorial - check out the Microsoft Dev Network, and click on C# in the left hand column for more info.
First of all, there's some setup to take care of in the constructor - namely, the network settings for talking to our board over the network. We'll also add a variable to hold the state of our LED.
public QuickTest()
{
// ...other initialization routines...
usbPacket = new UsbPacket();
usbPacket.Open();
osc = new Osc(usbPacket);
}
// this gets called when the checkbox changes
Led0_CheckedChanged( object sender, EventArgs e )
{
LedSet(0, Led0.Checked);
}
// then call LedSet() to create and send the message to the LED
LedSet(int index, bool value)
{
OscMessage oscMS = new OscMessage();
oscMS.Address = "/appled/" + index.ToString() + "/state";
oscMS.Values.Add(value?1:0);
oscUdp.Send(oscMS);
}
Explanation
When we get called from Led0_CheckedChanged(), we in turn call LedSet() with the device number of the LED (0 in this case), and the current value of the checkbox - Led0.Checked. In LedSet() we make a new OscMessage, and set its address to the OSC address we discussed earlier - /appled/0/state, add a value of either 1 or 0 for the state, and send it off.