Source code for sensirion_uart_sps30.device

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# (c) Copyright 2025 Sensirion AG, Switzerland
#
#     THIS FILE IS AUTOMATICALLY GENERATED!
#
# Generator:     sensirion-driver-generator 1.3.3
# Product:       sps30
# Model-Version: 1.0.1
#
"""
The class Sps30DeviceBase implements the low level interface of the sensor.
The class Sps30Device extends the Sps30DeviceBase. 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_uart_sps30.commands import (DeviceReset, ReadAutoCleaningInterval, ReadDeviceStatusRegister,
                                           ReadMeasurementValuesFloat, ReadMeasurementValuesUint16,
                                           ReadProductType, ReadSerialNumber, ReadVersion, Sleep,
                                           StartFanCleaning, StartMeasurement, StopMeasurement, WakeUp, WakeUpCommunication,
                                           WriteAutoCleaningInterval)


[docs]class Sps30DeviceBase: """Low level API implementation of SPS30"""
[docs] def __init__(self, channel): self._channel = channel
@property def channel(self): return self._channel
[docs] def start_measurement(self, measurement_output_format): """ Starts the measurement. After power up, the module is in Idle-Mode. Before any measurement values can be read, the Measurement-Mode needs to be started using this command. :param measurement_output_format: Possible enum values: output_format_float, output_format_uint16 .. note:: This command can only be executed in Idle-Mode. :Example: .. code-block:: python sensor.start_measurement(OutputFormat(261)) """ transfer = StartMeasurement(measurement_output_format) return execute_transfer(self._channel, transfer)
[docs] def stop_measurement(self): """Use this command to return to the Idle-Mode.""" transfer = StopMeasurement() return execute_transfer(self._channel, transfer)
[docs] def read_measurement_values_uint16(self): """ Reads the measured values from the module. If no new measurement values are available, the module returns an empty response frame. :return mc_1p0: Mass Concentration PM1.0 [µg/m³] :return mc_2p5: Mass Concentration PM2.5 [µg/m³] :return mc_4p0: Mass Concentration PM4.0 [µg/m³] :return mc_10p0: Mass Concentration PM10.0 [µg/m³] :return nc_0p5: Number Concentration PM0.5 [#/cm³] :return nc_1p0: Number Concentration PM1.0 [#/cm³] :return nc_2p5: Number Concentration PM2.5 [#/cm³] :return nc_4p0: Number Concentration PM4.0 [#/cm³] :return nc_10p0: Number Concentration PM10.0 [#/cm³] :return typical_particle_size: Typical Particle Size [µm] """ transfer = ReadMeasurementValuesUint16() return execute_transfer(self._channel, transfer)
[docs] def read_measurement_values_float(self): """ Reads the measured values from the module. If no new measurement values are available, the module returns an empty response frame. :return mc_1p0: Mass Concentration PM1.0 [µg/m³] :return mc_2p5: Mass Concentration PM2.5 [µg/m³] :return mc_4p0: Mass Concentration PM4.0 [µg/m³] :return mc_10p0: Mass Concentration PM10.0 [µg/m³] :return nc_0p5: Number Concentration PM0.5 [#/cm³] :return nc_1p0: Number Concentration PM1.0 [#/cm³] :return nc_2p5: Number Concentration PM2.5 [#/cm³] :return nc_4p0: Number Concentration PM4.0 [#/cm³] :return nc_10p0: Number Concentration PM10.0 [#/cm³] :return typical_particle_size: Typical Particle Size [µm] """ transfer = ReadMeasurementValuesFloat() return execute_transfer(self._channel, transfer)
[docs] def sleep(self): """ Enters the Sleep-Mode with minimum power consumption. This will also deactivate the UART interface. .. note:: This command can only be executed in Idle-Mode. """ transfer = Sleep() return execute_transfer(self._channel, transfer)
[docs] def wake_up_communication(self): """""" transfer = WakeUpCommunication() return execute_transfer(self._channel, transfer)
[docs] def wake_up(self): """ Use this command to switch from Sleep-Mode to Idle-Mode. In Sleep-Mode the UART interface is disabled and must first be activated by sending a low pulse on the RX pin. This pulse is generated by sending a single byte with the value 0xFF. If then a Wake-up command follows within 100ms, the module will switch on again and is ready for further commands in the Idle-Mode. Alternatively, if the software implementation does not allow to send a single byte with the value 0xFF, the Wake-up command can be sent twice in succession. In this case the first Wake-up command is ignored, but causes the interface to be activated. """ transfer = WakeUp() return execute_transfer(self._channel, transfer)
[docs] def start_fan_cleaning(self): """ Starts fan cleaning manually .. note:: This command can only be executed in Measurement-Mode. """ transfer = StartFanCleaning() return execute_transfer(self._channel, transfer)
[docs] def read_auto_cleaning_interval(self): """ Reads auto cleaning interval of the periodic fan-cleaning :return auto_cleaning_interval: Interval in seconds """ transfer = ReadAutoCleaningInterval() return execute_transfer(self._channel, transfer)[0]
[docs] def write_auto_cleaning_interval(self, auto_cleaning_interval): """ Writes auto cleaning interval of the periodic fan-cleaning :param auto_cleaning_interval: Interval in seconds :Example: .. code-block:: python sensor.write_auto_cleaning_interval(604800) """ transfer = WriteAutoCleaningInterval(auto_cleaning_interval) return execute_transfer(self._channel, transfer)
[docs] def read_product_type(self): """ This command returns the product type. It is defined as a string value with a length of 8 ASCII characters (excluding terminating null-character) :return product_type: 8-byte ASCII string + null-character """ transfer = ReadProductType() return execute_transfer(self._channel, transfer)[0]
[docs] def read_serial_number(self): """ This command returns the serial number. It is defined as a string value with a maximum length of 32 ASCII characters (including terminating null-character) :return serial_number: 32-byte ASCII string """ transfer = ReadSerialNumber() return execute_transfer(self._channel, transfer)[0]
[docs] def read_version(self): """ Gets version information about the firmware, hardware, and SHDLC protocol. :return firmware_major_version: :return firmware_minor_version: :return reserved1: :return hardware_revision: :return reserved2: :return shdlc_major_version: :return shdlc_minor_version: """ transfer = ReadVersion() return execute_transfer(self._channel, transfer)
[docs] def read_device_status_register(self, clear_status_register): """ Use this command to read the device status register. For more details, check explanations given in chapter 4.4 of the datasheet. :param clear_status_register: To clear the status register after reading set to true, otherwise set to false. :return device_status_register: :return reserved: """ transfer = ReadDeviceStatusRegister(clear_status_register) return execute_transfer(self._channel, transfer)
[docs] def device_reset(self): """ Device software reset command. After calling this command, the module is in the same state as after a power reset. .. note:: To perform a reset when the sensor is in sleep mode, it is required to send first a wake-up sequence to activate the interface. """ transfer = DeviceReset() return execute_transfer(self._channel, transfer)
[docs]class Sps30Device(Sps30DeviceBase): """Driver class implementation of SPS30""" #: Access to base class sps30 = MixinAccess()
[docs] def __init__(self, channel): super().__init__(channel)
[docs] def wake_up_sequence(self): """Fully wake up the device""" self.sps30.wake_up_communication() self.sps30.wake_up()