#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# (c) Copyright 2026 Sensirion AG, Switzerland
#
# THIS FILE IS AUTOMATICALLY GENERATED!
#
# Generator: sensirion-driver-generator 1.5.3
# Product: sen62
# Model-Version: 1.1.0
#
"""
The class Sen62DeviceBase implements the low level interface of the sensor.
The class Sen62Device extends the Sen62DeviceBase. 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_sen62.commands import (ActivateShtHeater, DeviceReset, DeviceStatus, GetDataReady, GetProductName,
GetSerialNumber, GetShtHeaterMeasurements, GetVersion,
ReadAndClearDeviceStatus, ReadDeviceStatus, ReadMeasuredRawValues,
ReadMeasuredValuesAsIntegers, ReadNumberConcentrationValuesAsIntegers,
SetTemperatureAccelerationParameters, SetTemperatureOffsetParameters,
StartContinuousMeasurement, StartFanCleaning, StopMeasurement)
from sensirion_i2c_sen62.result_types import (SignalDividedBy10, SignalHumidity, SignalTemperature)
[docs]
class Sen62DeviceBase:
"""Low level API implementation of SEN62"""
[docs]
def __init__(self, channel):
self._channel = channel
@property
def channel(self):
return self._channel
[docs]
def start_continuous_measurement(self):
"""
Starts a continuous measurement.
After starting the measurement, it takes some time (~1.1s) until the
first measurement results are available. You could poll with the command
"Get Data Ready" to check when the results are ready to read.
This command is only available in idle mode. If the device is already
in any measure mode, this command has no effect.
"""
transfer = StartContinuousMeasurement()
return execute_transfer(self._channel, transfer)
[docs]
def stop_measurement(self):
"""
Stops the measurement and returns to idle mode. After sending this
command, wait at least 1000 ms before starting a new measurement.
If the device is already in idle mode, this command has no effect.
"""
transfer = StopMeasurement()
return execute_transfer(self._channel, transfer)
[docs]
def get_data_ready(self):
"""
This command can be used to check if new measurement results are ready to read. The data ready flag
is automatically reset after reading the measurement values.
:return padding:
Padding byte, always 0x00.
:return data_ready:
True (0x01) if data is ready, False (0x00) if not. When no measurement is running, False will be
returned.
"""
transfer = GetDataReady()
return execute_transfer(self._channel, transfer)
[docs]
def read_measured_values_as_integers(self):
"""
Returns the measured values.
The command \"Get Data Ready\" can be used to check if new
data is available since the last read operation. If no new data is
available, the previous values will be returned again. If no data
is available at all (e.g. measurement not running for at least one
second), all values will be at their upper limit (0xFFFF for `uint16`,
0x7FFF for `int16`).
:return mass_concentration_pm1p0:
Value is scaled with factor 10: PM1.0 [µg/m³] = value / 10
*Note: If this value is unknown, 0xFFFF is returned.*
:return mass_concentration_pm2p5:
Value is scaled with factor 10: PM2.5 [µg/m³] = value / 10
*Note: If this value is unknown, 0xFFFF is returned.*
:return mass_concentration_pm4p0:
Value is scaled with factor 10: PM4.0 [µg/m³] = value / 10
*Note: If this value is unknown, 0xFFFF is returned.*
:return mass_concentration_pm10p0:
Value is scaled with factor 10: PM10.0 [µg/m³] = value / 10
*Note: If this value is unknown, 0xFFFF is returned.*
:return ambient_humidity:
Value is scaled with factor 100: RH [%] = value / 100
*Note: If this value is unknown, 0x7FFF is returned.*
:return ambient_temperature:
Value is scaled with factor 200: T [°C] = value / 200
*Note: If this value is unknown, 0x7FFF is returned.*
"""
transfer = ReadMeasuredValuesAsIntegers()
return execute_transfer(self._channel, transfer)
[docs]
def read_number_concentration_values_as_integers(self):
"""
Returns the measured number concentration values.
The command 0x0202 "Get Data Ready" can be used to check if new
data is available since the last read operation. If no new data is
available, the previous values will be returned again. If no data
is available at all (e.g. measurement not running for at least one
second), all values will be at their upper limit (0xFFFF for `uint16`).
:return number_concentration_pm0p5:
Value is scaled with factor 10: PM0.5 [particles/cm³] = value / 10
*Note: If this value is unknown, 0xFFFF is returned.*
:return number_concentration_pm1p0:
Value is scaled with factor 10: PM1.0 [particles/cm³] = value / 10
*Note: If this value is unknown, 0xFFFF is returned.*
:return number_concentration_pm2p5:
Value is scaled with factor 10: PM2.5 [particles/cm³] = value / 10
*Note: If this value is unknown, 0xFFFF is returned.*
:return number_concentration_pm4p0:
Value is scaled with factor 10: PM4.0 [particles/cm³] = value / 10
*Note: If this value is unknown, 0xFFFF is returned.*
:return number_concentration_pm10p0:
Value is scaled with factor 10: PM10.0 [particles/cm³] = value / 10
*Note: If this value is unknown, 0xFFFF is returned.*
"""
transfer = ReadNumberConcentrationValuesAsIntegers()
return execute_transfer(self._channel, transfer)
[docs]
def read_measured_raw_values(self):
"""
Returns the measured raw values.
The command 0x0202 \"Get Data Ready\" can be used to check if new
data is available since the last read operation. If no new data is
available, the previous values will be returned again. If no data
is available at all (e.g. measurement not running for at least one
second), all values will be at their upper limit (0x7FFF for `int16`).
:return raw_humidity:
Value is scaled with factor 100: RH [%] = value / 100
*Note: If this value is unknown, 0x7FFF is returned.*
:return raw_temperature:
Value is scaled with factor 200: T [°C] = value / 200
*Note: If this value is unknown, 0x7FFF is returned.*
"""
transfer = ReadMeasuredRawValues()
return execute_transfer(self._channel, transfer)
[docs]
def start_fan_cleaning(self):
"""
This command triggers fan cleaning. The fan is set to the maximum
speed for 10 seconds and then automatically stopped. Wait at least 10s
after this command before starting a measurement.
.. note::
This command is only available in idle mode.
"""
transfer = StartFanCleaning()
return execute_transfer(self._channel, transfer)
[docs]
def set_temperature_offset_parameters(self, offset, slope, time_constant, slot):
"""
This command allows to compensate temperature effects of the
design-in at customer side by applying custom temperature offsets
to the ambient temperature.
The compensated ambient temperature is calculated as follows:
* T_Ambient_Compensated = T_Ambient + (slope * T_Ambient) + offset
Where `slope` and `offset` are the values set with this command,
smoothed with the specified time constant.
All temperatures (`T_Ambient_Compensated`, `T_Ambient` and `offset`)
are represented in °C.
There are 5 temperature offset slots available that all contribute
additively to `T_Ambient_Compensated`. The default values for
the temperature offset parameters are all zero, meaning that
`T_Ambient_Compensated` is equal to `T_Ambient` by default.
The parameters can be changed in any state of the device, i.e. both in
idle mode and in measure mode.
:param offset:
Constant temperature offset scaled with factor 200 (T [°C] = value / 200).
:param slope:
Normalized temperature offset slope scaled with factor 10000 (applied factor = value / 10000).
:param time_constant:
The time constant determines how fast the new slope and offset will be applied.
After the specified value in seconds, 63% of the new slope and offset are applied.
A time constant of zero means the new values will be applied immediately
(within the next measure interval of 1 second).
:param slot:
The temperature offset slot to be modified.
Valid values are 0 .. 4. If the value is outside this range,
the parameters will not be applied.
.. note::
This configuration is volatile, i.e. the parameters will be reverted to their default value of zero
after a device reset.
:Example:
.. code-block:: python
sensor.set_temperature_offset_parameters(1, 10, 1, 0)
"""
transfer = SetTemperatureOffsetParameters(offset, slope, time_constant, slot)
return execute_transfer(self._channel, transfer)
[docs]
def set_temperature_acceleration_parameters(self, k, p, t1, t2):
"""
This command allows to set custom temperature acceleration parameters of the RH/T engine.
It overwrites the default temperature acceleration parameters of the RH/T engine with custom values. This
configuration is volatile, i.e. the parameters will be reverted to their default values after a device reset.
:param k:
Filter constant K scaled with factor 10 (K = value / 10).
:param p:
Filter constant P scaled with factor 10 (P = value / 10).
:param t1:
Time constant T1 scaled with factor 10 (T1 [s] = value / 10).
:param t2:
Time constant T2 scaled with factor 10 (T2 [s] = value / 10).
.. note::
The command is only available in idle mode.
:Example:
.. code-block:: python
sensor.set_temperature_acceleration_parameters(1, 1, 1, 1)
"""
transfer = SetTemperatureAccelerationParameters(k, p, t1, t2)
return execute_transfer(self._channel, transfer)
[docs]
def activate_sht_heater(self):
"""
Activate the heater feature of the SHT4x sensor.
This command allows to use the inbuilt heater in SHT sensor
to decontaminate and reverse creep at high humidity.
This command activates the SHT sensor heater with 200mW for 1s.
The SHT heater measurement done just before deactivation can be
read using the command \"Get SHT Heater Measurements\" after
the duration of the heating feature as specified in the SHT4x
datasheet.
Wait at least 20s after this command before starting a measurement
to get coherent temperature values (heating consequence to disappear).
.. note::
This command is only available in idle mode.
"""
transfer = ActivateShtHeater()
return execute_transfer(self._channel, transfer)
[docs]
def get_sht_heater_measurements(self):
"""
Get the measurement values when the SHT sensor heating
is finished.
:return sht_relative_humidity:
If the sht heating is completed, this value indicates
the scaled relative humidity of the SHT4x sensor.
Value is scaled with factor 100: RH [%] = value / 100
*Note: If this value is not available, 0x7FFF is returned.*
:return sht_temperature:
If the sht heating is completed, this value indicates
the scaled temperature of the SHT4x sensor.
Value is scaled with factor 200: T [°C] = value / 200
*Note: If this value is not available, 0x7FFF is returned.*
.. note::
This command must be used after the \"Activate SHT Heater\" command. The get sht heater measurements
command can be queried every 0.05s to get the measurements. This command is only available in idle
mode.
"""
transfer = GetShtHeaterMeasurements()
return execute_transfer(self._channel, transfer)
[docs]
def get_product_name(self):
"""
Gets the product name from the device.
:return product_name:
Null-terminated ASCII string containing the product name. Up to 32 characters can be read from the
device.
"""
transfer = GetProductName()
return execute_transfer(self._channel, transfer)[0]
[docs]
def get_serial_number(self):
"""
Gets the serial number from the device.
:return serial_number:
Null-terminated ASCII string containing the serial number. Up to 32 characters can be read from the
device.
"""
transfer = GetSerialNumber()
return execute_transfer(self._channel, transfer)[0]
[docs]
def get_version(self):
"""
Gets the version information for the hardware, firmware and communication protocol.
:return firmware_major:
Firmware major version number.
:return firmware_minor:
Firmware minor version number.
"""
transfer = GetVersion()
return execute_transfer(self._channel, transfer)
[docs]
def read_device_status(self):
"""
Reads the current device status.
Use this command to get detailed information about the device status.
The device status is encoded in flags. Each device status flag
represents a single bit in a 32-bit integer value. If more than one
error is present, the device status register value is the sum of the
corresponding flag values. For details about the available flags,
refer to the device status flags documentation in the data sheet.
:return device_status:
Device status (32 flags as an integer value). For details, please refer to the device status flags
documentation in the datasheet.
.. note::
The status flags of type "Error" are sticky, i.e. they are not cleared automatically even if the
error condition no longer exists. So they can only be cleared manually with the command
"Read And Clear Device Status" or with a device reset. All other flags are not sticky, i.e. they
are cleared automatically if the trigger condition disappears.
"""
transfer = ReadDeviceStatus()
res_0 = execute_transfer(self._channel, transfer)[0]
return DeviceStatus(res_0)
[docs]
def read_and_clear_device_status(self):
"""
Reads the current device status (like command 0xD206 "Read Device Status") and afterwards clears
all flags.
:return device_status:
Device status (32 flags as an integer value) **before** clearing it. For details, please refer to
the device status flags documentation.
"""
transfer = ReadAndClearDeviceStatus()
res_0 = execute_transfer(self._channel, transfer)[0]
return DeviceStatus(res_0)
[docs]
def device_reset(self):
"""Executes a reset on the device. This has the same effect as a power cycle."""
transfer = DeviceReset()
return execute_transfer(self._channel, transfer)
[docs]
class Sen62Device(Sen62DeviceBase):
"""Driver class implementation of SEN62"""
#: Access to base class
sen62 = MixinAccess()
[docs]
def __init__(self, channel):
super().__init__(channel)
[docs]
def read_measured_values(self):
"""
Read measured values and apply scaling as defined in datasheet.
:return mass_concentration_pm1p0:
Mass concentration in μg/m³ for particles smaller than 1.0 μm.
:return mass_concentration_pm2p5:
Mass concentration in μg/m³ for particles smaller than 2.5 μm.
:return mass_concentration_pm4p0:
Mass concentration in μg/m³ for particles smaller than 4.0 μm.
:return mass_concentration_pm10p0:
Mass concentration in μg/m³ for particles smaller than 10.0 μm.
:return humidity:
Measured humidity in %RH.
:return temperature:
Measured temperature in degrees celsius.
"""
(mass_concentration_pm1p0_raw, mass_concentration_pm2p5_raw, mass_concentration_pm4p0_raw,
mass_concentration_pm10p0_raw, humidity_raw, temperature_raw
) = self.read_measured_values_as_integers()
return (SignalDividedBy10(mass_concentration_pm1p0_raw), SignalDividedBy10(mass_concentration_pm2p5_raw),
SignalDividedBy10(mass_concentration_pm4p0_raw), SignalDividedBy10(mass_concentration_pm10p0_raw),
SignalHumidity(humidity_raw), SignalTemperature(temperature_raw))
[docs]
def read_number_concentration_values(self):
"""
Read measured number concentration values and apply scaling as defined in datasheet.
:return number_concentration_pm0p5:
Number concentration in particles/cm³ for particles smaller than 0.5 μm.
:return number_concentration_pm1p0:
Number concentration in particles/cm³ for particles smaller than 1.0 μm.
:return number_concentration_pm2p5:
Number concentration in particles/cm³ for particles smaller than 2.5 μm.
:return number_concentration_pm4p0:
Number concentration in particles/cm³ for particles smaller than 4.0 μm.
:return number_concentration_pm10p0:
Number concentration in particles/cm³ for particles smaller than 10.0 μm.
"""
(number_concentration_pm0p5_raw, number_concentration_pm1p0_raw, number_concentration_pm2p5_raw,
number_concentration_pm4p0_raw, number_concentration_pm10p0_raw
) = self.read_number_concentration_values_as_integers()
return (SignalDividedBy10(number_concentration_pm0p5_raw),
SignalDividedBy10(number_concentration_pm1p0_raw),
SignalDividedBy10(number_concentration_pm2p5_raw),
SignalDividedBy10(number_concentration_pm4p0_raw),
SignalDividedBy10(number_concentration_pm10p0_raw))