Skip to main content

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:

DeviceAnalog LinesType
ED-5498 analog inputsVoltage or current
ED-5604 analog outputsVoltage or current
ED-5824 RTD inputsTemperature (PT100/PT1000)
ED-5938 thermocouple inputsTemperature

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:

FormatDescription
EngineeringReal-world units (volts, milliamps, degrees)
FullScaleRangePercentage of full-scale range (0.0 – 100.0)
HexadecimalRaw 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:

UnitDescription
CelsiusDegrees Celsius
FahrenheitDegrees Fahrenheit
KelvinDegrees 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​

ValueEvent TypeMeaning
DeltaDeltaValue changed by more than the delta threshold
AboveTargetValue crossed above the target
BelowTargetValue crossed below the target
EnterTarget RangeValue entered the target ± delta range
ExitTarget RangeValue left the target ± delta range