Working with Analog IO
This guide covers analog inputs and outputs on ED-series devices that support analog IO, including data formats, temperature measurement, and delta/target events.
Analog Devices
Not all ED-series devices have analog IO. The following devices support analog lines:
| Device | Analog Lines | Type |
|---|---|---|
| ED-549 | 8 analog inputs | Voltage or current |
| ED-560 | 4 analog outputs | Voltage or current |
| ED-582 | 4 RTD inputs | Temperature (PT100/PT1000) |
| ED-593 | 8 thermocouple inputs | Temperature |
Reading Analog Inputs
Use the AValue property to read analog values:
using Brainboxes.IO;
using (EDDevice ed = EDDevice.Create("192.168.0.100"))
{
// Read a single analog input
double value = ed.AInputs[0].AValue;
Console.WriteLine($"Analog input 0: {value}");
// Read all analog inputs
for (int i = 0; i < ed.AInputs.Count; i++)
{
Console.WriteLine($"Analog input {i}: {ed.AInputs[i].AValue}");
}
}
Like digital values, analog values are cached for IOLineCacheTimeout milliseconds (default 250 ms) and reading any line refreshes all analog lines in one network call.
Setting Analog Outputs
On the ED-560 (4 analog outputs):
using (EDDevice ed = EDDevice.Create("192.168.0.100"))
{
// Set analog output 0 to 5.0 (units depend on AnalogDataFormat)
ed.AOutputs[0].AValue = 5.0;
}
Data Formats
The AnalogDataFormat enum controls how analog values are interpreted:
| Format | Description |
|---|---|
Engineering | Real-world units (volts, milliamps, degrees) |
FullScaleRange | Percentage of full-scale range (0.0 – 100.0) |
Hexadecimal | Raw ADC value in two's complement |
Set the data format through the protocol:
using (EDDevice ed = EDDevice.Create("192.168.0.100"))
{
ASCIIProtocol protocol = (ASCIIProtocol)ed.Protocol;
// Read in engineering units (default)
protocol.SetAnalogDataFormat(AnalogDataFormat.Engineering);
double voltage = ed.AInputs[0].AValue; // e.g. 3.245 (volts)
// Read as percentage of full-scale range
protocol.SetAnalogDataFormat(AnalogDataFormat.FullScaleRange);
double percent = ed.AInputs[0].AValue; // e.g. 32.45 (%)
}
Temperature Measurement
The ED-582 (RTD) and ED-593 (thermocouple) devices measure temperature. The TemperatureUnit enum controls the unit:
| Unit | Description |
|---|---|
Celsius | Degrees Celsius |
Fahrenheit | Degrees Fahrenheit |
Kelvin | Degrees Kelvin |
using (EDDevice ed = EDDevice.Create("192.168.0.100"))
{
ASCIIProtocol protocol = (ASCIIProtocol)ed.Protocol;
// Read temperature in Celsius
protocol.SetTemperatureUnit(TemperatureUnit.Celsius);
double tempC = ed.AInputs[0].AValue;
Console.WriteLine($"Temperature: {tempC} °C");
// Read temperature in Fahrenheit
protocol.SetTemperatureUnit(TemperatureUnit.Fahrenheit);
double tempF = ed.AInputs[0].AValue;
Console.WriteLine($"Temperature: {tempF} °F");
}
Analog Events
Analog lines support three types of events for change notification. Unlike digital events, analog events require explicit subscription with threshold parameters.
Delta Events
Fire when the value changes by more than a specified amount:
using (EDDevice ed = EDDevice.Create("192.168.0.100"))
{
AIOLineChangedEventHandler handler = (line, device, value, changeType) =>
{
Console.WriteLine($"Analog {line.IONumber} changed to {value}");
};
// Notify when value changes by more than 0.5
ed.AInputs[0].SubscribeToDeltaEvent(ref handler, delta: 0.5);
Console.ReadKey();
ed.AInputs[0].UnsubscribeToDeltaEvent(ref handler);
}
Target Events
Fire when the value crosses a specified threshold:
AIOLineChangedEventHandler handler = (line, device, value, changeType) =>
{
if (changeType == AIOChangeTypes.Above)
Console.WriteLine($"Value went above target: {value}");
else if (changeType == AIOChangeTypes.Below)
Console.WriteLine($"Value went below target: {value}");
};
// Notify when value crosses 3.3V
ed.AInputs[0].SubscribeToTargetEvent(ref handler, target: 3.3);
Target Range Events
Fire when the value enters or exits a range around a target:
AIOLineChangedEventHandler handler = (line, device, value, changeType) =>
{
if (changeType == AIOChangeTypes.Enter)
Console.WriteLine($"Value entered range: {value}");
else if (changeType == AIOChangeTypes.Exit)
Console.WriteLine($"Value left range: {value}");
};
// Notify when value enters/exits the range 3.3 ± 0.2
ed.AInputs[0].SubscribeToTargetRangeEvent(ref handler, target: 3.3, delta: 0.2);
AIOChangeTypes
| Value | Event Type | Meaning |
|---|---|---|
Delta | Delta | Value changed by more than the delta threshold |
Above | Target | Value crossed above the target |
Below | Target | Value crossed below the target |
Enter | Target Range | Value entered the target ± delta range |
Exit | Target Range | Value left the target ± delta range |