Source code for sensirion_i2c_sfx6xxx.device

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# (c) Copyright 2024 Sensirion AG, Switzerland
#
#     THIS FILE IS AUTOMATICALLY GENERATED!
#
# Generator:     sensirion-driver-generator 0.40.1
# Product:       sfx6xxx
# Model-Version: 2.3.1
#
"""
The class Sfx6xxxDeviceBase implements the low level interface of the sensor.
The class Sfx6xxxDevice extends the Sfx6xxxDeviceBase. It provides additional functions to ease the use of the
sensor.
"""

from sensirion_driver_adapters.transfer import execute_transfer
from sensirion_driver_support_types.mixin_access import MixinAccess
from sensirion_i2c_sfx6xxx.commands import (DisableRawFlowValues, EnableRawFlowValues, FlowUnitT, ForceCloseValve,
                                            ForceOpenValve, GetRawTemperature, PrepareReadGasCalibration, ReadFlow,
                                            ReadGasCalibration, ReadMeasurementData, ReadProductIdentifier,
                                            ResetForceCloseValve, ResetForceOpenValve, ResetPointerToMeasurementBuffer,
                                            StartAirContinuousMeasurement, StartArContinuousMeasurement,
                                            StartCo2ContinuousMeasurement, StartN2oContinuousMeasurement,
                                            StartO2ContinuousMeasurement, StartO2InAirContinuousMeasurement,
                                            StartRawThermalConductivityContinuousMeasurement, StatusWordT,
                                            StopContinuousMeasurement, UpdateCustomerGain, UpdateGasConcentration,
                                            UpdateInitStep, UpdateSetpoint)

from sensirion_i2c_sfx6xxx.result_types import (SignalFlow, SignalRawFlow, SignalTemperature)


[docs]class Sfx6xxxDeviceBase: """Low level API implementation of SFX6XXX"""
[docs] def __init__(self, channel): self._channel = channel
@property def channel(self): return self._channel
[docs] def read_product_identifier(self): """ Read product identifier and the serial number. :return product_identifier: 32-bit product and revision number. :return serial_number: 64-bit unique serial number. .. note:: - This command is only available while no measurement is running """ transfer = ReadProductIdentifier() return execute_transfer(self._channel, transfer)
[docs] def reset_pointer_to_measurement_buffer(self): """ This instruction resets the I2C address pointer to the regular result output buffer such that the measurement data are obtained upon a subsequent read header. """ transfer = ResetPointerToMeasurementBuffer() return execute_transfer(self._channel, transfer)
[docs] def update_setpoint(self, setpoint): """ Set the flow setpoint as a physical value which is used by the flow controller as reference input. :param setpoint: The new setpoint. The value has to be given in the regular two's complement format, which is also used for the flow value output. .. note:: - The setpoint is set to 0 if calibration is changed. - You have to call reset_pointer_to_measurement_buffer after updating the setpoint - Only applicable for SFC6xxx mass flow controllers. """ transfer = UpdateSetpoint(setpoint) return execute_transfer(self._channel, transfer)
[docs] def update_init_step(self, init_step): """ This instruction transmits the InitStep value to the MFC. An MFC variant specific InitStep value is used by default, which will be applied after a hard- or soft-reset of the sensor. :param init_step: InitStep value in range [0..1] multiplied by 2^16. .. note:: - Only applicable for SFC6xxx mass flow controllers - You have to reset i2c address after updating the init step """ transfer = UpdateInitStep(init_step) return execute_transfer(self._channel, transfer)
[docs] def update_customer_gain(self, customer_gain): """ This instruction transmits the CustomerGain value to the MFC. A value of 1 is used by default for the CustomerGain, which will be applied after a hard- or soft-reset of the sensor. :param customer_gain: CustomerGain value in range [0..4] multiplied by 2^14. .. note:: - Only applicable for SFC6xxx mass flow controllers - You have to reset i2c address after updating the init step """ transfer = UpdateCustomerGain(customer_gain) return execute_transfer(self._channel, transfer)
[docs] def start_o2_continuous_measurement(self): """Start continuous O₂ measurement.""" transfer = StartO2ContinuousMeasurement() return execute_transfer(self._channel, transfer)
[docs] def start_air_continuous_measurement(self): """Start continuous air measurement.""" transfer = StartAirContinuousMeasurement() return execute_transfer(self._channel, transfer)
[docs] def start_co2_continuous_measurement(self): """Start continuous CO₂ measurement.""" transfer = StartCo2ContinuousMeasurement() return execute_transfer(self._channel, transfer)
[docs] def start_n2o_continuous_measurement(self): """Start continuous N₂O measurement.""" transfer = StartN2oContinuousMeasurement() return execute_transfer(self._channel, transfer)
[docs] def start_ar_continuous_measurement(self): """Start continuous Ar measurement.""" transfer = StartArContinuousMeasurement() return execute_transfer(self._channel, transfer)
[docs] def start_raw_thermal_conductivity_continuous_measurement(self): """ Start measurement for raw thermal conductivity. In this measurement mode the valve remains closed and the flow value is replaced by the raw thermal conductivity value. """ transfer = StartRawThermalConductivityContinuousMeasurement() return execute_transfer(self._channel, transfer)
[docs] def start_o2_in_air_continuous_measurement(self, volume_fraction): """ Start continuous measurement for gas mixture of O2 in Air. :param volume_fraction: Volume fraction of O2 in Air in per mille (‰). """ transfer = StartO2InAirContinuousMeasurement(volume_fraction) return execute_transfer(self._channel, transfer)
[docs] def stop_continuous_measurement(self): """ This transfer stops the continuous measurement and puts the sensor in idle mode. .. note:: - After it receives the stop command, the sensor needs up to 1 ms to power down the heater, enter idle mode and be receptive for a new command. """ transfer = StopContinuousMeasurement() return execute_transfer(self._channel, transfer)
[docs] def read_measurement_data(self): """ Read out the data from the sensor. :return flow: Calibrated flow signal read from the sensor. :return reserved: Reserved value for future use. :return status_word: Contains status information about the read data. """ transfer = ReadMeasurementData() res_0, res_1, res_2 = execute_transfer(self._channel, transfer) return res_0, res_1, StatusWordT(res_2)
[docs] def read_flow(self): """ Read out the flow only from the sensor. :return flow: Calibrated flow signal read from the sensor. """ transfer = ReadFlow() return execute_transfer(self._channel, transfer)[0]
[docs] def get_raw_temperature(self): """ While the sensor is in continuous measurement mode, the temperature of the bulk silicon in the flow-sensor chip can be read with a special I2C transmission sequence. The sensor must be in continuous measurement mode and the temperature is read without interrupting the running measurement. To this end a transmission sequence consisting of multiple instructions is detailed in this section. :return temperature: 16-bit temperature .. note:: - The first valid temperature value can be read after about 12 ms (i.e. for simplicity, the temperature shall be read upon the sensor acknowledged a read of the flow value, to make sure that a temperature value is available from the buffer) - The update rate for the temperature value is significantly slower than for the flow value. The most up- to-date temperature value is always available from the buffer (the sensor will ACK a corresponding read). Hence, the identical internally acquired temperature value can be read multiple times, which is not the case for the flow value, where the sensor will NACK if no new measurement data is yet available - You have to call reset_pointer_to_measurement_buffer after reading out the temperature - temperature value has a scaling factor or 1/200 """ transfer = GetRawTemperature() return execute_transfer(self._channel, transfer)[0]
[docs] def force_open_valve(self): """ Fully opens the valve. The flow value can still be read from the sensor. Call reset_force_open_valve to return to normal valve regulation. .. note:: - Only applicable for SFC6xxx mass flow controllers - Command has to be issued while continuous measurement is running """ transfer = ForceOpenValve() return execute_transfer(self._channel, transfer)
[docs] def reset_force_open_valve(self): """ Return to normal valve regulation after fully opening the valve. .. note:: - Only applicable for SFC6xxx mass flow controllers - Command has to be issued after force_open_valve """ transfer = ResetForceOpenValve() return execute_transfer(self._channel, transfer)
[docs] def force_close_valve(self): """ Fully closes the valve. The flow value can still be read from the sensor. Call reset_force_close_valve to return to normal valve regulation. .. note:: - Only applicable for SFC6xxx mass flow controllers - Command has to be issued while continuous measurement is running """ transfer = ForceCloseValve() return execute_transfer(self._channel, transfer)
[docs] def reset_force_close_valve(self): """ Return to normal valve regulation after force closing the valve. .. note:: - Only applicable for SFC6xxx mass flow controllers - Command has to be issued after force_close_valve """ transfer = ResetForceCloseValve() return execute_transfer(self._channel, transfer)
[docs] def update_gas_concentration(self, volume_fraction): """ Update the concentration of a binary gas mixture dynamically. :param volume_fraction: New O₂ volume fraction in Air .. note:: - You have to call reset_pointer_to_measurement_buffer after updating gas concentration - The concentration value must not be updated more than once per millisecond """ transfer = UpdateGasConcentration(volume_fraction) return execute_transfer(self._channel, transfer)
[docs] def prepare_read_gas_calibration(self, measurement_command): """ This command prepares read out of gas calibration. :param measurement_command: The continuous measurement command, that will be used. .. note:: - This command has to be sent before read_gas_calibration """ transfer = PrepareReadGasCalibration(measurement_command) return execute_transfer(self._channel, transfer)
[docs] def read_gas_calibration(self): """ Read the flow scale, offset and unit, full-scale flow and unique gas-ID for one of the calibrated gases. :return flow_scale_factor: Scale factor used by the sensor. :return flow_offset: Offset used by the sensor. :return flow_unit: Applicable flow unit. :return full_scale_flow: The full-scale flow value as a two's complement. :return gas_id: The unique gas-ID represents the code assigned to a gas by the SEMI standards. .. note:: - This command is only valid after prepare_read_gas_calibration """ transfer = ReadGasCalibration() res_0, res_1, res_2, res_3, res_4 = execute_transfer(self._channel, transfer) return res_0, res_1, FlowUnitT(res_2), res_3, res_4
[docs] def enable_raw_flow_values(self): """ There might be special cases where it is beneficial to read the uncalibrated raw flow value from the sensor. To this end a dedicated command can be issued requesting the sensor to return the uncalibrated raw flow values as opposed to the default linearized flow values. .. note:: - This command has to be issued while a continuous measurement is running """ transfer = EnableRawFlowValues() return execute_transfer(self._channel, transfer)
[docs] def disable_raw_flow_values(self): """ Causes the sensor to switch back to normalized flow values. .. note:: - This command has to be issued while a continuous measurement is running - Use this command to return to regular normalized flow values after enabling raw flow values """ transfer = DisableRawFlowValues() return execute_transfer(self._channel, transfer)
[docs]class Sfx6xxxDevice(Sfx6xxxDeviceBase): """Driver class implementation of SFX6XXX""" #: Access to base class sfx6xxx = MixinAccess()
[docs] def __init__(self, channel): super().__init__(channel) self._flow_offset = 0.0 self._flow_scale_factor = 1.0 self._flow_unit = 0 self._full_flow = 0 self._gas_id = 0
[docs] def get_gas_calibration(self, measurement_command): """ Read the flow scale, offset and unit, full-scale flow and unique gas-ID for one of the calibrated gases. :param measurement_command: The continuous measurement command, that will be used. :return flow_scale_factor: Scale factor used by the sensor. :return flow_offset: Offset used by the sensor. :return flow_unit: Applicable flow unit. :return full_scale_flow: The full-scale flow value as a two's complement. :return gas_id: The unique gas-ID represents the code assigned to a gas by the SEMI standards. """ self.sfx6xxx.prepare_read_gas_calibration(measurement_command) return self.sfx6xxx.read_gas_calibration()
[docs] def start_o2_continuous_measurement(self): """Start O2 measurement and readout the corresponding scale factor from the sensor""" (self._flow_scale_factor, self._flow_offset, flow_unit_field, self._full_flow, self._gas_id ) = self.get_gas_calibration(StartO2ContinuousMeasurement.CMD_ID) self._flow_unit = int(flow_unit_field) return self.sfx6xxx.start_o2_continuous_measurement()
[docs] def start_air_continuous_measurement(self): """Start Air measurement and readout the corresponding scale factor from the sensor""" (self._flow_scale_factor, self._flow_offset, flow_unit_field, self._full_flow, self._gas_id ) = self.get_gas_calibration(StartAirContinuousMeasurement.CMD_ID) self._flow_unit = int(flow_unit_field) return self.sfx6xxx.start_air_continuous_measurement()
[docs] def start_co2_continuous_measurement(self): """Start CO2 measurement and readout the corresponding scale factor from the sensor""" (self._flow_scale_factor, self._flow_offset, flow_unit_field, self._full_flow, self._gas_id ) = self.get_gas_calibration(StartCo2ContinuousMeasurement.CMD_ID) self._flow_unit = int(flow_unit_field) return self.sfx6xxx.start_co2_continuous_measurement()
[docs] def start_n2o_continuous_measurement(self): """Start N2O measurement and readout the corresponding scale factor from the sensor""" (self._flow_scale_factor, self._flow_offset, flow_unit_field, self._full_flow, self._gas_id ) = self.get_gas_calibration(StartN2oContinuousMeasurement.CMD_ID) self._flow_unit = int(flow_unit_field) return self.sfx6xxx.start_n2o_continuous_measurement()
[docs] def start_ar_continuous_measurement(self): """Start Ar measurement and readout the corresponding scale factor from the sensor""" (self._flow_scale_factor, self._flow_offset, flow_unit_field, self._full_flow, self._gas_id ) = self.get_gas_calibration(StartArContinuousMeasurement.CMD_ID) self._flow_unit = int(flow_unit_field) return self.sfx6xxx.start_ar_continuous_measurement()
[docs] def start_o2_in_air_continuous_measurement(self, volume_fraction): """ Start O2 in air measurement and readout the corresponding scale factor from the sensor :param volume_fraction: Volume fraction of O2 in Air in per mille (‰). """ (self._flow_scale_factor, self._flow_offset, flow_unit_field, self._full_flow, self._gas_id ) = self.get_gas_calibration(StartO2InAirContinuousMeasurement.CMD_ID) self._flow_unit = int(flow_unit_field) return self.sfx6xxx.start_o2_in_air_continuous_measurement(volume_fraction)
[docs] def start_raw_thermal_conductivity_continuous_measurement(self): """Start thermal conductivity measurement and readout the corresponding scale factor from the sensor""" (self._flow_scale_factor, self._flow_offset, flow_unit_field, self._full_flow, self._gas_id ) = self.get_gas_calibration(StartRawThermalConductivityContinuousMeasurement.CMD_ID) self._flow_unit = int(flow_unit_field) return self.sfx6xxx.start_raw_thermal_conductivity_continuous_measurement()
[docs] def read_measurement_data_raw(self): """ Read raw flow value :return arg_0: :return a_status_word: """ (flow_raw, reserved, status ) = self.sfx6xxx.read_measurement_data() return (flow_raw, status)
[docs] def read_measurement_data(self): """ Read measured data with scaling applied :return a_flow: This signal represents the measured flow. It is scaled with the corresponding scaling factor and offset :return a_status_word: """ (raw_flow, status_word ) = self.read_measurement_data_raw() return (SignalFlow(raw_flow, self._flow_scale_factor, self._flow_offset), status_word)
[docs] def read_flow_raw(self): """ Read raw flow value in ticks. :return arg_0: """ flow_raw = self.sfx6xxx.read_flow() return flow_raw
[docs] def read_flow(self): """ Read scaled flow value in standard liter per minute. :return a_flow: This signal represents the measured flow. It is scaled with the corresponding scaling factor and offset """ raw_flow = self.read_flow_raw() return SignalFlow(raw_flow, self._flow_scale_factor, self._flow_offset)
[docs] def read_raw_temperature(self): """ Read temperature in degrees celsius. :return arg_0: """ raw_temperature = self.sfx6xxx.get_raw_temperature() self.sfx6xxx.reset_pointer_to_measurement_buffer() return raw_temperature
[docs] def read_temperature(self): """ Read temperature in degrees celsius. :return a_temperature: Measured temperature in degrees celsius. The raw value is scaled appropriately. """ raw_temperature = self.read_raw_temperature() return SignalTemperature(raw_temperature)
[docs] def update_setpoint(self, flow): """ Update the setpoint during active measurement. :param flow: Setpoint in slm .. note:: - Only applicable for SFC6xxx mass flow controllers. """ raw_flow = SignalRawFlow(flow, self._flow_scale_factor, self._flow_offset) self.sfx6xxx.update_setpoint(raw_flow) return self.sfx6xxx.reset_pointer_to_measurement_buffer()