.Net User's Guide

Overview

The ControlPanelManager class provides a unified interface for interacting with a programmable control panel device. It manages digital inputs, relay outputs, analog inputs, and analog outputs, while also supporting configuration persistence, calibration, filtering, and event-based notifications.

This library is designed for real-time hardware interaction in environments such as automation systems, test benches, environmental chambers, or any custom control panel application.

General Usage Flow

  1. Device Discovery and Initialization
    Start by finding available control panel devices using FindControlPanels(). Create a new ControlPanelManager instance using either the default constructor or by selecting from the discovered list.
    var available = ControlPanelManager.FindControlPanels();
    var panel = new ControlPanelManager(available[0]);
    
  2. Optional: Load Configuration
    Load previously saved settings to restore the panel to its last known configuration.
    panel.LoadConfig();
  3. Configure Behavior
    Set default output states, assign user-friendly names to channels, define units, and apply calibration parameters.
    panel.SetUserID(AnalogInputs.AI1, "TemperatureSensor");
    panel.SetUnit(AnalogInputs.AI1, "ºC");
    panel.SetRelayDefaultState(Relays.R1, false);
  4. Start Sampling
    Begin automatic polling of inputs and updating of outputs using StartSampling().
    panel.StartSampling(250); // Poll every 250ms
  5. Monitor or Control
    Read inputs and write outputs as needed:
    bool isPressed = panel.GetDigitalInput(DigitalInputs.DI1);
    panel.SetAnalogOutput(AnalogOutputs.AO1, 2.5);
  6. Optional: Respond to Events
    Subscribe to events to respond in real time when input values change.
    panel.DigitalInputChanged += (s, e) => {
        Console.WriteLine($"{e.Input} changed to {e.NewValue}");
    };
  7. Optional: Save Configuration
    Save your custom settings so they persist across sessions.
    panel.SaveConfig();
  8. Shut Down Cleanly
    Disconnect from the control panel and stop background processing.
    panel.Stop();

Who Should Use This Library?

  • Engineers building test rigs or control systems
  • Developers integrating with custom control panels
  • OEMs embedding programmable I/O functionality into their hardware
  • Anyone needing a simple, code-driven interface to physical inputs and outputs

Constructor Overloads

ControlPanelManager()

Purpose: Creates a new instance by automatically detecting and connecting to the first available control panel device.

Usage: Use this when only one device is expected to be connected, and no device selection is needed.

var panel = new ControlPanelManager();

If no compatible device is found, an exception will be thrown.

ControlPanelManager(Units unit)

Purpose: Connects to a specific control panel device using its serial and part numbers.

Usage: Use this when working with multiple devices, or when selecting from a list returned by FindControlPanels().

var available = ControlPanelManager.FindControlPanels();
if (available.Count > 0)
{
    var panel = new ControlPanelManager(available[0]);
}

This ensures the correct device is selected in systems with multiple connected units.

Device Properties

Type Name Description
string SerialNum Gets the unique serial number of the connected control panel device.
string CPSerialNum Gets the control panel's user-defined serial number.
string CPPartNum Gets or sets the control panel's part number.
string Name Gets or sets a user-defined name for the control panel.
int SamplingInterval Gets or sets the sampling interval in milliseconds for reading input data.

Sampling and Polling

This set of methods manages background activity that reads inputs and updates outputs on a continuous loop. The sampling process runs on a separate thread, providing real-time interaction with the control panel without blocking the main application.

StartSampling

void StartSampling(int SamplingIntervalMs)

Purpose: Begins continuous input polling and output updates in the background.

Usage: Call this method to start automatic sampling at a fixed interval (in milliseconds). Once started, the control panel will read all digital and analog inputs and make the latest values available for use in your application. If filtering is enabled on an analog input, averaged results are also calculated and dispatched via the AnalogInputChanged event.

Example:

panel.StartSampling(250); // Sample every 250 milliseconds

StopPolling

void StopPolling()

Purpose: Temporarily stops the sampling thread without shutting down the device.

Usage: Call this method when you want to pause real-time monitoring. This is useful if you need to change configurations or minimize resource usage without a full shutdown.

Reset

void Reset()

Purpose: Restores outputs to their default state and clears any filtered input history.

Usage: This method is useful for initializing the control panel to a known state. It resets all digital outputs (relays) and analog outputs to their defined defaults, and clears internal buffers used for filtering analog input data.

Stop

void Stop()

Purpose: Fully stops all background processes and disconnects the control panel device.

Usage: Call this when you are finished using the control panel. It gracefully ends the polling thread, releases all resources, and ensures a clean shutdown of the system.

Example:

panel.Stop(); // Fully disconnect and clean up

Digital Inputs and Outputs

These methods allow your application to monitor external digital signals and control digital output relays. Each digital input and relay output is individually addressable using the provided enumerations.

GetDigitalInput

bool GetDigitalInput(DigitalInputs input)

Purpose: Returns the current state of the specified digital input.

Usage: Call this method to check whether a digital input (such as a button or sensor) is currently active. The return value is true if the input is high (on) or false if it is low (off).

Example:

bool doorOpen = panel.GetDigitalInput(DigitalInputs.DI1);

GetDigitalOutput

bool GetDigitalOutput(Relays relay)

Purpose: Returns the current on/off state of the specified relay output.

Usage: Use this method to check whether a relay is currently energized (true) or not (false).

Example:

bool isHeaterOn = panel.GetDigitalOutput(Relays.R2);

SetDigitalOutput

void SetDigitalOutput(Relays relay, bool value)

Purpose: Sets the state of a relay output.

Usage: This method turns a specific relay on or off. Pass true to turn the relay on or false to turn it off. Use this to control external devices like lights, valves, or alarms.

Example:

panel.SetDigitalOutput(Relays.R2, true);  // Turn on relay R2
panel.SetDigitalOutput(Relays.R2, false); // Turn off relay

Default States

This section describes how to configure default values that will be applied to the control panel's outputs upon startup or reset. Default states are useful for ensuring the system enters a known-safe condition after a power cycle or software reboot. Relays and analog outputs can be preset to a defined value, allowing critical outputs to be off or set to a safe voltage by default.

GetRelayDefaultState

bool GetRelayDefaultState(Relays relay)

Purpose: Returns the configured default power-on state of a relay output.

Usage: Use this method to query the initial on/off state a relay should assume when the control panel is powered on or reset. This is helpful for confirming fail-safe or startup behaviors.

Example:

bool defaultState = panel.GetRelayDefaultState(Relays.R5);
Console.WriteLine($"Relay R5 default state is: {(defaultState ? "ON" : "OFF")}");

SetRelayDefaultState

void SetRelayDefaultState(Relays relay, bool value)

Purpose: Sets the power-on default state for a relay output.

Usage: Call this method to define the desired initial state of a relay (on or off) at startup. Useful for ensuring that connected devices (like pumps or alarms) behave safely during power restoration or system resets.

Example:

panel.SetRelayDefaultState(Relays.R5, false); // Ensure R5 is OFF by default

GetAODefaultState

double GetAODefaultState(AnalogOutputs ao)

Purpose: Retrieves the default voltage assigned to an analog output on startup.

Usage: Use this method to read the power-on default voltage level configured for an analog output. This is helpful when you need to verify the expected voltage applied to external devices during system initialization.

Example:

double defaultVoltage = panel.GetAODefaultState(AnalogOutputs.AO1);
Console.WriteLine($"AO1 default voltage: {defaultVoltage}V");

SetAODefaultState

void SetAODefaultState(AnalogOutputs ao, double value)

Purpose: Assigns a power-on default voltage to an analog output channel.

Usage: Use this method to define the voltage that should be output on a specific analog channel when the system is powered up or reset. This is useful for controlling devices that need a known voltage at startup.

Example:

panel.SetAODefaultState(AnalogOutputs.AO1, 2.5); // Set AO1 to 2.5V at startup

Metadata and Configuration

This section allows you to manage additional descriptive properties for each I/O channel. These metadata values help make your control panel setup more readable, understandable, and tailored to the application at hand. You can assign friendly names (user IDs), define engineering units for analog values, and control whether a low-pass filter is applied to analog inputs.

GetUserID

string GetUserID<TEnum>(TEnum key)

Purpose: Retrieves the user-defined ID (friendly name) associated with the specified input or output channel.

Usage: Use this to access any custom label previously set for a relay, digital input, analog input, or analog output.

Example:

string name = panel.GetUserID(AnalogInputs.AI1); // Returns "TemperatureSensor", if previously set

SetUserID

void SetUserID<TEnum>(TEnum key, string userID)

Purpose: Assigns a user-defined ID (friendly name) to the specified I/O channel.

Usage: Useful for labeling inputs and outputs with meaningful identifiers, such as "FanControl", "FlowSensor", or "Valve1".

Example:

panel.SetUserID(Relays.R3, "CoolingFan");

GetUnit

string GetUnit<TEnum>(TEnum key)

Purpose: Retrieves the unit string associated with a specific analog input or output.

Usage: Useful when displaying analog values, so you can automatically label them with the correct engineering units (e.g., ºC, PSI, Volts).

Example:

string unit = panel.GetUnit(AnalogInputs.AI2); // Might return "ºC"

SetUnit

void SetUnit<TEnum>(TEnum key, string unit)

Purpose: Sets a unit string for the given analog input or output.

Usage: This helps clarify what the analog values represent in user interfaces or reports.

Example:

panel.SetUnit(AnalogOutputs.AO1, "V"); // Sets unit for AO1 to "Volts"

GetFilter

bool GetFilter(AnalogInputs key)

Purpose: Checks if input filtering is enabled for a specific analog input channel.

Usage: Use this to verify whether the input signal is being averaged over time to reduce noise.

Example:

bool isFiltering = panel.GetFilter(AnalogInputs.AI3);

SetFilter

void SetFilter(AnalogInputs key, bool value)

Purpose: Enables or disables low-pass filtering for an analog input.

Usage: Set this to true for noisy signals where smoothing improves accuracy. Set to false to get raw values instantly.

Example:

panel.SetFilter(AnalogInputs.AI3, true); // Enable filtering on AI3

Calibration

Calibration allows analog inputs and outputs to be corrected for sensor drift, scaling mismatches, or voltage offsets. Each analog channel can apply a linear calibration equation to convert raw hardware values into meaningful engineering units like volts, psi, or ºC. This improves accuracy and consistency across devices.

GetCalibrationValue

double GetCalibrationValue<TEnum>(TEnum key, CalVals calVal)

Purpose: Retrieves a specific calibration parameter associated with an analog input or output channel.

Usage: Use this method to inspect calibration parameters such as raw input values or their corresponding corrected values. Calibration consists of a linear transformation based on two input-value pairs.

Parameters:

  • key: The analog input or output (e.g., AnalogInputs.AI1, AnalogOutputs.AO2)
  • calVal: The calibration parameter to retrieve (e.g., CalVals.INPUT1, CalVals.CORRECTION2)

Example:

double correction = panel.GetCalibrationValue(AnalogInputs.AI2, CalVals.CORRECTION1);
Console.WriteLine($"Correction 1 for AI2: {correction}");

SetCalibrationValue

void SetCalibrationValue<TEnum>(TEnum key, CalVals calVal, double value)

Purpose: Sets a calibration parameter for an analog input or output.

Usage: Use this method to programmatically adjust the calibration curve for an analog input or output. For example, you can align a sensor's raw voltage to a real-world physical measurement.

Parameters:

  • key: The analog input or output to calibrate
  • calVal: The calibration parameter to set (e.g., CalVals.ISCAL, CalVals.INPUT1)
  • value: The value to assign

Example:

panel.SetCalibrationValue(AnalogOutputs.AO1, CalVals.CORRECTION2, 10.0); // Output should map to 10.0V

Persistence

The control panel library supports saving and restoring configuration data. This includes user-defined labels, sampling settings, filter options, default output states, and calibration parameters. Configurations are saved to disk in a readable JSON format, allowing easy inspection or version control.

SaveConfig

void SaveConfig()

Purpose: Saves the current control panel configuration to a file.

Usage: Call this method to persist all customized settings so they can be restored after a reboot or software restart. Useful for deploying systems with predefined calibration and naming conventions.

Example:

panel.SaveConfig(); // Save current configuration to disk

LoadConfig

void LoadConfig()

Purpose: Loads a saved configuration from disk. Falls back to defaults if no saved config is found.

Usage: Call this method during initialization to restore saved settings for a specific device. If the configuration file does not exist, it will initialize with factory defaults.

Example:

panel.LoadConfig(); // Load previous config or fall back to default values

Event System

The control panel supports event-driven programming, allowing your application to respond automatically when inputs change. These events are ideal for updating user interfaces in real-time, triggering alarms, or logging state changes without constantly polling the device.

DigitalInputChanged

event EventHandler<DigitalInputChangedEventArgs> DigitalInputChanged

Purpose: Raised whenever the state of a digital input changes (e.g., a button press or sensor signal).

Usage: Subscribe to this event to receive notifications when a digital input is toggled. The event arguments provide the input channel and its new state.

Example:

panel.DigitalInputChanged += (sender, e) =>
{
    Console.WriteLine($"Digital input {e.Input} changed to {e.NewValue}");
};

AnalogInputChanged

event EventHandler<AnalogInputChangedEventArgs> AnalogInputChanged

Purpose: Raised periodically for each analog input during sampling, delivering the latest value.

Usage: Subscribe to this event to receive smoothed or raw analog input values as they are read. The frequency depends on the sampling interval and whether filtering is enabled.

Example:

panel.AnalogInputChanged += (sender, e) =>
{
    Console.WriteLine($"Analog input {e.Input} now reads {e.NewValue:F2}");
};