Personal tools
You are here: Home Documentation Tutorials .NET C# Analog Inputs
Document Actions

Analog Inputs

Another example, this time on how to read values back from the board.
How to communicate with the Make Controller from with Microsoft's .NET C# environment.
Page 3 of 5.

To read an analog input, send an OSC message to ask for the current value, and the board will send an OSC message back with the value. Unlike the OSC messages sent to the LEDs, an OSC message asking to read a value will not have an argument on the end of it. This is what distinguishes a read message from a write message - the lack of an argument.

The name of the analog input subsystem is analogin, there are 8 devices numbered 0 - 7, and we're interested in reading their value. 'Read' messages have the form /subsystem/device/property, with no argument. If you're monitoring a single value, it's convenient to use the SetAddressHandler( ) routine - you can pass it the address of a device on the board you're waiting for, and it will call a given method back with the value when it arrives. Include this in your constructor:

public QuickTest()
{
// ...other initialization routines...
osc.SetAddressHandler("/analogin/7/value", TrimPotReading);
}
void TrimPotReading( OscMessage oscM )
{
int value = (int)oscM.Values[0];
SetIndicator( value );
}

Explanation

In the constructor, we set the TrimPotReading( ) method to handle all the returning messages with an address of "/analogin/7/value". Then in the TrimPotReading( ) method, we take the value from the incoming message and use it to update the Indicator in the UI.