Table of Contents

Class Device

Namespace
Hse.EviFluor
Assembly
Hseagcom.EviFluor.dll

This class represents the eviFluor module.

public class Device : IDisposable
Inheritance
Device
Implements
Inherited Members

Constructors

Device(string?)

Initializes a new instance of the Device class. The constructor attempts to connect to an EviFluor module via a serial port. If no serial port is provided, it tries to auto-detect the device.

Throws an exception if:

  • No device is found during auto-detection.
  • The provided serial port does not match the expected VID/PID for the EviFluor device.
public Device(string? serialNumber = null)

Parameters

serialNumber string

The serial number of the device to connect to. If null or empty, the constructor attempts to automatically find a device.

Exceptions

Exception

Thrown when:

  • No device is found during auto-detection (if serialNumber is null or empty).
  • The provided serial port does not correspond to an EviFluor device.

Properties

LibraryVersion

Returns the library version.

public string LibraryVersion { get; }

Property Value

string

Methods

Autogain(int)

Performs an auto-gain operation at the specified level. Sends a command to the device and parses the response to determine if the operation was successful.

public AutoGainResult Autogain(int level)

Parameters

level int

The gain level (0-2500) to be set on the device.

Returns

AutoGainResult

An AutoGainResult indicating whether the gain was found and the LED power used.

Baseline()

Executes a baseline command. Actually no adjustment or measurement is performed. Only the internal measurement memory is deleted.

public void Baseline()

Command(string)

Sends a command string to the device over the serial interface and waits for a valid response.

public string[] Command(string tx)

Parameters

tx string

The command string to transmit (without prefix or newline, e.g., "V 1").

Returns

string[]

A list of response string tokens received from the device after processing the command. Each token represents a space- or quote-delimited component of the response.

Remarks

This method prepends a ':' to the transmitted command, sends it via the serial port, then reads and validates the response. If an error is indicated by the device (response starting with "E"), a corresponding error message is thrown based on the error code.

Exceptions

Exception

Thrown in the following cases:

  • No response within the timeout period.
  • Response does not start with ':' (invalid format).
  • Response indicates an error code (e.g., unknown command, invalid parameter).

Dispose()

Close the serial port and dispose it.

public void Dispose()

~Device()

Destructor

protected ~Device()

FirmwareVersion()

Retrieves the firmware version of the connected device. This method uses the Get<T>(Index) method to fetch the firmware version from the device at the predefined index for firmware versions.

public string FirmwareVersion()

Returns

string

The firmware version of the device as a string.

Exceptions

InvalidCastException

Thrown if the retrieval or conversion of the firmware version fails.

Exception

Thrown if there is an issue communicating with the device or retrieving the value.

FirstAirMeasurement()

Performs the first air measurement by measuring at minimum and maximum LED power levels.

public FirstAirMeasurementResult FirstAirMeasurement()

Returns

FirstAirMeasurementResult

A FirstAirMeasurementResult containing the minimum and maximum measurements.

FirstSampleMeasurement(double)

Performs the first sample measurement using an auto-gain operation to determine the optimal LED power level.

public FirstSampleMeasurementResult FirstSampleMeasurement(double factor = 0.8)

Parameters

factor double

A scaling factor for determining the initial gain level.

Returns

FirstSampleMeasurementResult

A FirstSampleMeasurementResult containing the auto-gain result and the measurement.

FwUpdate(string)

Performs a firmware update on the device. The method reads the firmware file, erases the existing firmware, writes the new firmware line by line, and then verifies its validity. If the update fails at any stage, an exception is thrown.

public void FwUpdate(string filename)

Parameters

filename string

The path to the firmware file that contains the new firmware image.

Remarks

The update process follows these steps:

  1. Read all lines from the specified firmware file.
  2. Erase the existing firmware using Hse.EviFluor.Device.erase().
  3. Send each line of the new firmware to the device using the "S {line}" command.
  4. Verify the firmware using verify(); if verification fails, throw an exception.
  5. Reboot the device and close the serial port.
  6. Wait for 30 seconds to allow the device to restart.
  7. Reopen the serial port and clear its buffers.
  8. Verify the firmware again; if verification still passes, throw an exception indicating the update failed.

Exceptions

IOException

Thrown if the firmware file cannot be read.

Exception

Thrown if the firmware update fails at any stage (e.g., verification fails before or after reboot).

GetAvailableDevices()

Retrieves a list of available eviFluor devices by scanning serial ports.

public static List<string> GetAvailableDevices()

Returns

List<string>

A list of serial numbers of available matching devices.

Get<T>(Index)

Retrieves a value from the device at the specified index and converts it to the desired type. Sends a command to the device to fetch the value and parses the response.

public T Get<T>(Index index)

Parameters

index Index

The index from which the value should be retrieved.

Returns

T

The value retrieved from the device, converted to the specified type T.

Type Parameters

T

The type to which the retrieved value will be converted.

Exceptions

InvalidCastException

Thrown if the conversion to the specified type T fails.

Exception

Thrown if the device response is invalid or does not contain the expected data format.

IsCuvetteHolderEmpty()

Checks whether the cuvette holder is empty.

public bool IsCuvetteHolderEmpty()

Returns

bool

true if the cuvette holder is empty; otherwise, false.

Exceptions

FormatException

Thrown if the response value from the device cannot be parsed as an integer.

IndexOutOfRangeException

Thrown if the device response does not contain the expected number of values.

Logging()

Sets the status led color.

public List<string> Logging()

Returns

List<string>

Exceptions

IndexOutOfRangeException

Thrown if the device response does not contain the expected number of values.

Measure()

Performs a measurement and retrieves data from the device.

public SingleMeasurement Measure()

Returns

SingleMeasurement

A SingleMeasurement object containing the measured data for all channels.

Exceptions

FormatException

Thrown if any of the response values from the device cannot be parsed as integers.

IndexOutOfRangeException

Thrown if the device response does not contain the expected number of values.

ProductionNumber()

Retrieves the production number of the connected device. This method uses the Get<T>(Index) method to fetch the production number from the device at the predefined index.

public string ProductionNumber()

Returns

string

The production number of the device as a string.

Exceptions

Exception

Thrown if there is an issue communicating with the device or retrieving the value.

SelfTest()

Performs a self-test on the device and retrieves the result.

public SelfTestResult SelfTest()

Returns

SelfTestResult

A SelfTestResult object containing the parsed self-test result.

Exceptions

FormatException

Thrown if the response value from the device cannot be parsed as an integer.

IndexOutOfRangeException

Thrown if the device response does not contain the expected number of values.

SerialNumber()

Retrieves the serial number of the connected device. This method uses the Get<T>(Index) method to fetch the serial number from the device at the predefined index for serial numbers.

public string SerialNumber()

Returns

string

The serial number of the device as a string.

Exceptions

InvalidCastException

Thrown if the retrieval or conversion of the serial number fails.

Exception

Thrown if there is an issue communicating with the device or retrieving the value.

Set(Index, double)

Sets a value on the device at the specified index. Sends a command to update the value on the device.

public void Set(Index index, double value)

Parameters

index Index

The index where the value should be set.

value double

The double value to set at the specified index.

Set(Index, int)

Sets a value on the device at the specified index. Sends a command to update the value on the device.

public void Set(Index index, int value)

Parameters

index Index

The index where the value should be set.

value int

The integer value to set at the specified index.

Set(Index, string)

Sets a value on the device at the specified index. Sends a command to update the value on the device.

public void Set(Index index, string value)

Parameters

index Index

The index where the value should be set.

value string

The string value to set at the specified index.

SetStatusLed(StatusLedColor)

Sets the status led color.

public void SetStatusLed(StatusLedColor color)

Parameters

color StatusLedColor

Exceptions

IndexOutOfRangeException

Thrown if the device response does not contain the expected number of values.

TechnicalReport()

Generates a technical report containing various diagnostic data from the device. The report includes levelling results, self-test data, serial number, and firmware version.

public JsonNode TechnicalReport()

Returns

JsonNode

A JsonNode object containing structured diagnostic data.

Remarks

The generated report consists of the following fields:

ToString()

Returns a string representation of the device, including its serial port, serial number, and firmware version.

public override string ToString()

Returns

string

A formatted string containing the device's port name, serial number, and firmware version.

Remarks

The returned string follows the format: "eviFluor Module@{PortName} SN:{SerialNumber} Version:{FirmwareVersion}" Example output: "eviFluor Module@COM3 SN:12345678 Version:1.0.5"

verify()

Verifies if the 2nd firmware image is valid.

public bool verify()

Returns

bool

true if the verification was successful; otherwise, false.

Exceptions

FormatException

Thrown if the response value from the device cannot be parsed as an integer.

IndexOutOfRangeException

Thrown if the device response does not contain the expected number of values.