#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# (c) Copyright 2023 Sensirion AG, Switzerland
#
# THIS FILE IS AUTOMATICALLY GENERATED!
#
# Generator: sensirion-driver-generator 0.23.0
# Product: sfx6xxx
# Model-Version: 2.0.0
#
"""
The transfer classes specify the data that is transferred between host and sensor. The generated transfer classes
are used by the driver class and not intended for direct use.
"""
from enum import Enum
from sensirion_driver_adapters.transfer import Transfer
from sensirion_driver_adapters.rx_tx_data import TxData, RxData
[docs]class StatusCode(Enum):
SUCCESS = 0
DATA_SIZE_ERROR = 1
UNKNOWN_COMMAND_ERROR = 2
PARAMETER_ERROR = 4
I2C_NACK_ERROR = 41
I2C_MASTER_HOLD_ERROR = 42
I2C_CRC_ERROR = 43
SENSOR_DATA_WRITE_ERROR = 44
SENSOR_MEASURE_LOOP_NOT_RUNNING_ERROR = 45
INVALID_CALIBRATION_INDEX_ERROR = 51
SENSOR_BUSY_ERROR = 66
COMMAND_NOT_ALLOWED_IN_CURRENT_STATE = 67
FATAL_ERROR = 127
def __int__(self):
return self.value
[docs]class SetSetpoint(Transfer):
"""
Set the flow setpoint as a physical value which is
used by the flow controller as reference input.
"""
CMD_ID = 0x0
def __init__(self, setpoint):
self._setpoint = setpoint
[docs] def pack(self):
return self.tx_data.pack([0x1, self._setpoint])
tx = TxData(CMD_ID, '>BBf')
[docs]class GetSetpoint(Transfer):
"""Get the current flow setpoint as a physical value."""
CMD_ID = 0x0
[docs] def pack(self):
return self.tx_data.pack([0x1])
tx = TxData(CMD_ID, '>BB')
rx = RxData('>f')
[docs]class ReadMeasuredValue(Transfer):
"""The command returns the latest measured flow as physical value."""
CMD_ID = 0x8
[docs] def pack(self):
return self.tx_data.pack([0x1])
tx = TxData(CMD_ID, '>BB', device_busy_delay=0.01, slave_address=None, ignore_ack=False)
rx = RxData('>f')
[docs]class ReadAveragedMeasuredValue(Transfer):
"""
The command returns the average of given number of flow measurement as physical
value. A single measurement has a duration of 1ms, so the command response time
depends on the given number of measurements to average.
"""
CMD_ID = 0x8
def __init__(self, measurements):
self._measurements = measurements
[docs] def pack(self):
return self.tx_data.pack([0x11, self._measurements])
tx = TxData(CMD_ID, '>BBB', device_busy_delay=0.2, slave_address=None, ignore_ack=False)
rx = RxData('>f')
[docs]class SetSetpointAndReadMeasuredValue(Transfer):
"""
This command is a combination of the two commands set_setpoint (0x00) and
read_measured_value (0x08). It is intended for process data exchange
(setpoint and flow) and saves a lot of protocol overhead compared to separate
command usage.
"""
CMD_ID = 0x3
def __init__(self, setpoint):
self._setpoint = setpoint
[docs] def pack(self):
return self.tx_data.pack([0x1, self._setpoint])
tx = TxData(CMD_ID, '>BBf', device_busy_delay=0.01, slave_address=None, ignore_ack=False)
rx = RxData('>f')
[docs]class SetUserControllerGain(Transfer):
"""Set the user controller gain."""
CMD_ID = 0x22
def __init__(self, gain):
self._gain = gain
[docs] def pack(self):
return self.tx_data.pack([0x0, self._gain])
tx = TxData(CMD_ID, '>BBf')
[docs]class GetUserControllerGain(Transfer):
"""Get the user controller gain."""
CMD_ID = 0x22
[docs] def pack(self):
return self.tx_data.pack([0x0])
tx = TxData(CMD_ID, '>BB')
rx = RxData('>f')
[docs]class SetUserInitStep(Transfer):
"""Set the init step of flow controller."""
CMD_ID = 0x22
def __init__(self, init_step):
self._init_step = init_step
[docs] def pack(self):
return self.tx_data.pack([0x3, self._init_step])
tx = TxData(CMD_ID, '>BBf')
[docs]class GetUserInitStep(Transfer):
"""Get the user init step of flow controller."""
CMD_ID = 0x22
[docs] def pack(self):
return self.tx_data.pack([0x3])
tx = TxData(CMD_ID, '>BB')
rx = RxData('>f')
[docs]class MeasureRawFlow(Transfer):
"""Return the measured raw flow ticks from the sensor."""
CMD_ID = 0x30
[docs] def pack(self):
return self.tx_data.pack([0x0])
tx = TxData(CMD_ID, '>BB', device_busy_delay=0.01, slave_address=None, ignore_ack=False)
rx = RxData('>H')
[docs]class MeasureRawThermalConductivityWithClosedValve(Transfer):
"""
Perform a thermal conductivity measurement and return the measured raw tick
value. The valve is automatically closed during the measurement.
"""
CMD_ID = 0x30
[docs] def pack(self):
return self.tx_data.pack([0x2])
tx = TxData(CMD_ID, '>BB', device_busy_delay=0.6, slave_address=None, ignore_ack=False)
rx = RxData('>H')
[docs]class MeasureTemperature(Transfer):
"""Return the temperature of flow sensor."""
CMD_ID = 0x30
[docs] def pack(self):
return self.tx_data.pack([0x10])
tx = TxData(CMD_ID, '>BB', device_busy_delay=0.01, slave_address=None, ignore_ack=False)
rx = RxData('>f')
[docs]class GetNumberOfCalibrations(Transfer):
"""
Get the number of calibrations, i.e. how many calibration the device memory is
able to hold.
"""
CMD_ID = 0x40
[docs] def pack(self):
return self.tx_data.pack([0x0])
tx = TxData(CMD_ID, '>BB', device_busy_delay=0.01, slave_address=None, ignore_ack=False)
rx = RxData('>I')
[docs]class GetCalibrationValidity(Transfer):
"""Check whether there exists a valid calibration at a specific index or not."""
CMD_ID = 0x40
def __init__(self, index):
self._index = index
[docs] def pack(self):
return self.tx_data.pack([0x10, self._index])
tx = TxData(CMD_ID, '>BBI', device_busy_delay=0.01, slave_address=None, ignore_ack=False)
rx = RxData('>?')
[docs]class GetCalibrationGasId(Transfer):
"""Get the gas ID of a specific calibration index."""
CMD_ID = 0x40
def __init__(self, index):
self._index = index
[docs] def pack(self):
return self.tx_data.pack([0x12, self._index])
tx = TxData(CMD_ID, '>BBI', device_busy_delay=0.01, slave_address=None, ignore_ack=False)
rx = RxData('>I')
[docs]class GetCalibrationGasUnit(Transfer):
"""Get the gas unit of a specific calibration index."""
CMD_ID = 0x40
def __init__(self, index):
self._index = index
[docs] def pack(self):
return self.tx_data.pack([0x13, self._index])
tx = TxData(CMD_ID, '>BBI', device_busy_delay=0.01, slave_address=None, ignore_ack=False)
rx = RxData('>bBB')
[docs]class GetCalibrationFullscale(Transfer):
"""Get the fullscale flow of a specific calibration index."""
CMD_ID = 0x40
def __init__(self, index):
self._index = index
[docs] def pack(self):
return self.tx_data.pack([0x14, self._index])
tx = TxData(CMD_ID, '>BBI', device_busy_delay=0.01, slave_address=None, ignore_ack=False)
rx = RxData('>f')
[docs]class GetCurrentGasId(Transfer):
"""Get the gas ID of the currently active calibration."""
CMD_ID = 0x44
[docs] def pack(self):
return self.tx_data.pack([0x12])
tx = TxData(CMD_ID, '>BB', device_busy_delay=0.01, slave_address=None, ignore_ack=False)
rx = RxData('>I')
[docs]class GetCurrentGasUnit(Transfer):
"""Get the gas unit of the currently active calibration."""
CMD_ID = 0x44
[docs] def pack(self):
return self.tx_data.pack([0x13])
tx = TxData(CMD_ID, '>BB', device_busy_delay=0.01, slave_address=None, ignore_ack=False)
rx = RxData('>bBB')
[docs]class GetCurrentFullscale(Transfer):
"""Get the fullscale flow of the currently active calibration."""
CMD_ID = 0x44
[docs] def pack(self):
return self.tx_data.pack([0x14])
tx = TxData(CMD_ID, '>BB', device_busy_delay=0.01, slave_address=None, ignore_ack=False)
rx = RxData('>f')
[docs]class SetCalibration(Transfer):
"""
This command stops the controller, changes the used calibration of the flow
controller and starts the controller. The selected calibration is stored
and also used after a power-on or reset.
"""
CMD_ID = 0x45
def __init__(self, calibration_number):
self._calibration_number = calibration_number
[docs] def pack(self):
return self.tx_data.pack([self._calibration_number])
tx = TxData(CMD_ID, '>BI')
[docs]class GetCalibration(Transfer):
"""Get the actual set calibration number of flow controller."""
CMD_ID = 0x45
[docs] def pack(self):
return self.tx_data.pack([])
tx = TxData(CMD_ID, '>B')
rx = RxData('>I')
[docs]class SetCalibrationVolatile(Transfer):
"""
This command stops the controller, changes the used calibration of the flow
controller and starts the controller. The selected calibration is not stored to
a non volatile memory.
"""
CMD_ID = 0x46
def __init__(self, calibration_number):
self._calibration_number = calibration_number
[docs] def pack(self):
return self.tx_data.pack([self._calibration_number])
tx = TxData(CMD_ID, '>BI', device_busy_delay=0.02, slave_address=None, ignore_ack=False)
[docs]class SetSlaveAddress(Transfer):
"""Sets the SHDLC slave address of the device."""
CMD_ID = 0x90
def __init__(self, slave_address):
self._slave_address = slave_address
[docs] def pack(self):
return self.tx_data.pack([self._slave_address])
tx = TxData(CMD_ID, '>BB')
[docs]class GetSlaveAddress(Transfer):
"""Gets the SHDLC slave address of the device."""
CMD_ID = 0x90
[docs] def pack(self):
return self.tx_data.pack([])
tx = TxData(CMD_ID, '>B')
rx = RxData('>B')
[docs]class SetBaudrate(Transfer):
"""Sets the SHDLC baudrate of the device."""
CMD_ID = 0x91
def __init__(self, baudrate):
self._baudrate = baudrate
[docs] def pack(self):
return self.tx_data.pack([self._baudrate])
tx = TxData(CMD_ID, '>BI')
[docs]class GetBaudrate(Transfer):
"""Gets the SHDLC baudrate of the device."""
CMD_ID = 0x91
[docs] def pack(self):
return self.tx_data.pack([])
tx = TxData(CMD_ID, '>B')
rx = RxData('>I')
[docs]class GetProductType(Transfer):
"""Gets the product type from the device."""
CMD_ID = 0xd0
[docs] def pack(self):
return self.tx_data.pack([0x0])
tx = TxData(CMD_ID, '>BB', device_busy_delay=0.01, slave_address=None, ignore_ack=False)
rx = RxData('>64s')
[docs]class GetProductName(Transfer):
"""Gets the product name from the device."""
CMD_ID = 0xd0
[docs] def pack(self):
return self.tx_data.pack([0x1])
tx = TxData(CMD_ID, '>BB')
rx = RxData('>64s')
[docs]class GetArticleCode(Transfer):
"""Get the article code of the device. This information is also contained on the product label."""
CMD_ID = 0xd0
[docs] def pack(self):
return self.tx_data.pack([0x2])
tx = TxData(CMD_ID, '>BB')
rx = RxData('>64s')
[docs]class GetSerialNumber(Transfer):
"""Gets the serial number of the SFx6xxx sensor."""
CMD_ID = 0xd0
[docs] def pack(self):
return self.tx_data.pack([0x3])
tx = TxData(CMD_ID, '>BB')
rx = RxData('>64s')
[docs]class GetVersion(Transfer):
"""Gets the version information for the hardware, firmware and SHDLC protocol."""
CMD_ID = 0xd1
[docs] def pack(self):
return self.tx_data.pack([])
tx = TxData(CMD_ID, '>B', device_busy_delay=0.01, slave_address=None, ignore_ack=False)
rx = RxData('>BB?BBBB')
[docs]class DeviceReset(Transfer):
"""Executes a reset on the device. This has the same effect as a power cycle."""
CMD_ID = 0xd3
[docs] def pack(self):
return self.tx_data.pack([])
tx = TxData(CMD_ID, '>B', device_busy_delay=0.1, slave_address=None, ignore_ack=False)
post_processing_time = 0.3