Drivers

Device Identifier

class Drivers.DeviceIdentifier.DeviceIdentifier(serials: dict)[source]

The DeviceIdentifier lists all connected USB devices and tries to identify all devices listed in self.serials with their respective serial port, which are subsequently available as self.serial_ports

Parameters

serials (dict) – Dictionary with USB names as keys and USB serials as values.

Note

If the USB serials are unknown when launching the program first simply supply a dictionary with placeholders. DeviceIdentifier supplies information on all available devices upon failing to find one of the devices in the serials dictionary.

Warning

Windows detects USB serials differently than Linux. As experienced in the creating of this software, a serial read on a Linux system must be appended with the letter ‘A’ to be detected on a Windows system. To offer platform independence the serials must be given in ‘Linux-Form’ and are automatically appended with the letter ‘A’ when the program is run on Windows.

open()[source]

Detects the current os. For Windows the letter ‘A’ is appended to the Linux-specific serial of the device. For Linux an additional tty-setup script is executed to allow detection of all USB devices. After that the serials of the available devices are compared and linked to self.serials.

Returns

Returns True if all devices listed in self.serials could be found, False otherwise.

Platforms

Platform Base

class Drivers.PlatformBase.PlatformBase(name: str)[source]

Abstract base class for all platforms used in this project.

Parameters

name (str) – Each platform must have a unique name.

close() → None[source]

Disconnects the platform if it is currently connected.

open() → bool[source]

Attempts to connect the platform and reports success.

Returns

True if connected succesifully, False otherwise.

Shdlc IO Module - The Heater

class Drivers.Shdlc_IO.ShdlcIoModule(serial_port: str, baudrate=115200, slave_address=0, input_pins=None)[source]

Bases: Drivers.PlatformBase.PlatformBase

The ShdlcIoModule represents the custom Sensirion HDLC IO Box that allows driving the heater with a PWM output.

Parameters
  • serial_port (str) – Comport the IO box is connected to

  • baudrate (int) – Baudrate of the connection

  • slave_address (int) – Slave address

  • input_pins (list) – list of integers of the input pins

connect() → bool[source]

Attempts to connect the ShdlcIoModule

Returns

True if connected successifully, False otherwise.

disconnect() → None[source]

Sets all outputs off.

get_analog_input() → float[source]

Measures actual voltage on ADC input

Returns

A voltage between 0-10V

get_analog_output() → float[source]

Gets actual voltage for DAC output

Returns

A voltage between 0-10V

get_digital_io(io_bit: int) → bool[source]

Reads a digital io pin.

Parameters

io_bit (int) – Output bit to read

Returns

True if digital bit is set.

get_pwm(pwm_bit: int) → int[source]

Reads the current pwm setting.

Parameters

pwm_bit (int) – The index of the PWM channel to be used (0, 1)

Returns

A duty cycle value between 0 - 65535

is_connected() → bool[source]

Attempts to read the serial number of the device to check if it is connected.

Returns

True if connected, False otherwise.

set_all_digital_io_off() → None[source]

Turns of all digital pins.

set_analog_output(value: int) → None[source]

Sets the analog output

Parameters

value (int) – A voltage between 0-10V

set_digital_io(io_bit: int, value: bool) → None[source]

Sets a digital output pin.

Parameters
  • io_bit (int) – The digital pin index to set

  • value (bool) – True if set to on

set_pwm(pwm_bit: int, dc: int) → None[source]

Sets the pwm output

Parameters
  • pwm_bit (int) – The index of the PWM channel to be used (0, 1)

  • dc (int) –

Returns

A duty cycle value between 0 - 65535

Sensirion Sensor Bridge (EKS)

class Drivers.SHT.EKS(serial_port: str)[source]

Bases: Drivers.PlatformBase.PlatformBase

EKS represents a Sensirion Sensor Bridge which is used to communicate to a range of sensor via I2C.

Parameters

serial_port (str) – Name of the port to which the EKS is connected.

connect() → bool[source]

Attempts to connect to the EKS.

Returns

True if connected sucessifully, otherwise the encountered exception will be returned.

connect_sensors() → None[source]

Attempts to connect sensors at both EKS ports.

disconnect() → None[source]

Closes all connected sensors.

is_connected() → bool[source]

Tests if the EKS is responsive.

Returns

True if the EKs serial number can be read, False otherwise.

measure() → list[source]

Measures both channels if a sensor is attached

Returns

A list of measured values.

Sensors

Sensor Base

class Drivers.SensorBase.SensorBase(name)[source]

Abstract base class for all sensors used in this project.

Parameters

name (str) – Each sensor must have a unique name.

close() → None[source]

Disconnects the sensor if it is currently connected.

open() → bool[source]

Attempts to connect the sensor and reports success. :return: True fi connected successifully, False otherwise

Sensirion Humidity Temperature (STH)

class Drivers.SHT.SHT(device_port: int, shdlc_device: sensirion_shdlc_sensorbridge.device.SensorBridgeShdlcDevice, name='SHT')[source]

Bases: Drivers.SensorBase.SensorBase

SHT represents either an SHT85 or an STH31 of the Sensirion Humidity Temperature (SHT) sensor range, connected via the Sensirion Sensor Bridge (EKS).

Parameters
  • device_port (SensorBridgePort) – EKS port, either ONE or TWO.

  • shdlc_device (SensorBridgeShdlcDevice) – Instance of the controlling EKS.

  • name (str) – Name of the sensor.

_convert_humidity(data: bytearray) → float[source]

Converts the raw sensor data to the actual measured humidity according to the data sheet Sensirion_Humidity_Sensors_SHT3x

Parameters

data (bytearray) – 2 bytes, namely number 4 (humidity MSB) and 5 (humidity LSB) of the answer delivered by the sensor.

Returns

The relative humidity measured by the sensor in percent.

_convert_temperature(data: bytearray) → float[source]

Converts the raw sensor data to the actual measured temperature according to the data sheet Sensirion_Humidity_Sensors_SHT3x

Parameters

data (bytearray) – 2 bytes, namely number 1 (temperature MSB) and 2 (humidity LSB) of the answer delivered by the sensor.

Returns

The temperature measured by the sensor in degrees Celsius.

connect() → bool[source]

Attempts to connect the sensor and signals success by blinking the corresponding port’s LEDs.

Returns

Returns True if connected successifully, False otherwise.

connect_sensor(supply_voltage: float, frequency: int) → None[source]

Connection of a sensor attached to the sensirion sensor bridge according to the quick start guide to sensirion-shdlc-sensorbridge.

Parameters
  • supply_voltage (float) – Desired supply voltage in Volts.

  • frequency (int) – I2C frequency in Hz

disconnect() → None[source]

Called by SensorBase.close upon deletion of this class. Switches supply off.

is_connected() → bool[source]

Check if the sensor operates correctly

Returns

True if the status register can be read, False otherwise

measure() → dict[source]

Implementats a single shot measurement according to the SHT3x datasheet. A high repeatability measurement with clock stretching enabled is performed.

Returns

Dictionary containing temperature in degrees Celsius and relative humiditiy in percent.

read_status_reg() → bytearray[source]

Reads the status register

Returns

Status register value as bytearray.

Sensirion Mass Flow Meter / Controller (SFM / SFC)

class Drivers.SFX5400.SFX5400(serial_port: str, name='Sfc5400')[source]

Bases: Drivers.SensorBase.SensorBase

SFX5400 represents either a Sensirion Flow Controller (SFC) or a Sensirion Flow Meter (SFM) of type 5400.

Parameters
  • serial_port (str) – Name of the comport the SFX is connected to.

  • name (str) – Name of the device.

connect() → bool[source]

Attempts to connect to the SFX and reports success.

Returns

True if connected successifully, False otherwise.

disconnect() → None[source]

Disconnects the device.

get_device_information(index: int) → str[source]

Retrieves device information depending on the index given.

Parameters

index (int) –

Integer between 1 and 3 to request on of the data below:

  1. Product Name

  2. Article Code

  3. Serial number

Returns

String containing the requested information.

is_connected()[source]

Checks if the device is connected by reading its serial number.

Returns

True if connected, False if not.

measure() → dict[source]

Measures the current mass flow.

Returns

Dictionary containing the measurement.

set_flow(setpoint_normalized: float) → bool[source]

Sets the current desired mass flow if a flow controller is connected.

Parameters

setpoint_normalized (float) – Flow setpoint as normalized input between 0 and 1.

Returns

True if set successifully, False if exception occured.