Source code for sensirion_shdlc_sfc5xxx.commands.get_calibration_information

# -*- coding: utf-8 -*-
# (c) Copyright 2020 Sensirion AG, Switzerland

##############################################################################
##############################################################################
#                 _____         _    _ _______ _____ ____  _   _
#                / ____|   /\  | |  | |__   __|_   _/ __ \| \ | |
#               | |       /  \ | |  | |  | |    | || |  | |  \| |
#               | |      / /\ \| |  | |  | |    | || |  | | . ` |
#               | |____ / ____ \ |__| |  | |   _| || |__| | |\  |
#                \_____/_/    \_\____/   |_|  |_____\____/|_| \_|
#
#     THIS FILE IS AUTOMATICALLY GENERATED AND MUST NOT BE EDITED MANUALLY!
#
# Generator:    sensirion-shdlc-interface-generator 0.8.2
# Product:      SFC5xxx
# Version:      0.1.0
#
##############################################################################
##############################################################################

# flake8: noqa

from __future__ import absolute_import, division, print_function
from sensirion_shdlc_driver.command import ShdlcCommand
from struct import pack, unpack

import logging
log = logging.getLogger(__name__)


[docs]class Sfc5xxxCmdGetCalibrationInformationBase(ShdlcCommand): """ SHDLC command 0x40: "Get Calibration Information". """
[docs] def __init__(self, *args, **kwargs): """ Constructor. """ super(Sfc5xxxCmdGetCalibrationInformationBase, self).__init__( 0x40, *args, **kwargs)
[docs]class Sfc5xxxCmdGetNumberOfCalibrations(Sfc5xxxCmdGetCalibrationInformationBase): """ Get Number Of Calibrations Command Get the number of calibrations, i.e. how many calibration blocks the device memory is able to hold. .. note:: Not all calibration blocks actually contain a valid gas calibration. Use the command *Get Calibration Validity* to check which calibrations are valid and thus can be activated. """
[docs] def __init__(self): """ Constructor. """ super(Sfc5xxxCmdGetNumberOfCalibrations, self).__init__( data=b"".join([bytes(bytearray([0x00]))]), max_response_time=0.01, post_processing_time=0.0, min_response_length=4, max_response_length=4 )
[docs] @staticmethod def interpret_response(data): """ :return: Number of calibrations. :rtype: int """ number_of_calibrations = int(unpack(">I", data[0:4])[0]) # uint32 return number_of_calibrations
[docs]class Sfc5xxxCmdGetCalibrationValidity(Sfc5xxxCmdGetCalibrationInformationBase): """ Get Calibration Validity Command Check whether there exists a valid calibration at a specific index or not. """
[docs] def __init__(self, index): """ Constructor. :param int index: The index to check whether there is a valid calibration or not. """ super(Sfc5xxxCmdGetCalibrationValidity, self).__init__( data=b"".join([bytes(bytearray([0x10])), pack(">I", index)]), max_response_time=0.01, post_processing_time=0.0, min_response_length=1, max_response_length=1 )
[docs] @staticmethod def interpret_response(data): """ :return: Whether there exists a valid calibration at the specified index or not. :rtype: bool """ validity = bool(unpack(">?", data[0:1])[0]) # bool return validity
[docs]class Sfc5xxxCmdGetCalibrationGasDescription(Sfc5xxxCmdGetCalibrationInformationBase): """ Get Calibration Gas Description Command Get the gas description string of a specific calibration index. """
[docs] def __init__(self, index): """ Constructor. :param int index: The calibration index to read the requested information from. """ super(Sfc5xxxCmdGetCalibrationGasDescription, self).__init__( data=b"".join([bytes(bytearray([0x11])), pack(">I", index)]), max_response_time=0.01, post_processing_time=0.0, min_response_length=0, max_response_length=255 )
[docs] @staticmethod def interpret_response(data): """ :return: The read gas description string. :rtype: str """ gas_description = str(data[0:].decode('utf-8').rstrip('\0')) # string return gas_description
[docs]class Sfc5xxxCmdGetCalibrationGasId(Sfc5xxxCmdGetCalibrationInformationBase): """ Get Calibration Gas Id Command Get the gas ID of a specific calibration index. """
[docs] def __init__(self, index): """ Constructor. :param int index: The calibration index to read the requested information from. """ super(Sfc5xxxCmdGetCalibrationGasId, self).__init__( data=b"".join([bytes(bytearray([0x12])), pack(">I", index)]), max_response_time=0.01, post_processing_time=0.0, min_response_length=4, max_response_length=4 )
[docs] @staticmethod def interpret_response(data): """ :return: The read gas ID. :rtype: int """ gas_id = int(unpack(">I", data[0:4])[0]) # uint32 return gas_id
[docs]class Sfc5xxxCmdGetCalibrationGasUnit(Sfc5xxxCmdGetCalibrationInformationBase): """ Get Calibration Gas Unit Command Get the gas unit of a specific calibration index. """
[docs] def __init__(self, index): """ Constructor. :param int index: The calibration index to read the requested information from. """ super(Sfc5xxxCmdGetCalibrationGasUnit, self).__init__( data=b"".join([bytes(bytearray([0x13])), pack(">I", index)]), max_response_time=0.01, post_processing_time=0.0, min_response_length=3, max_response_length=3 )
[docs] @staticmethod def interpret_response(data): """ :return: - prefix (int) - Medium unit prefix, see appendix for encoding. - unit (int) - Medium unit, see appendix for encoding. - timebase (int) - Timebase, see appendix for encoding. :rtype: tuple """ prefix = int(unpack(">b", data[0:1])[0]) # int8 unit = int(unpack(">B", data[1:2])[0]) # uint8 timebase = int(unpack(">B", data[2:3])[0]) # uint8 return prefix,\ unit,\ timebase
[docs]class Sfc5xxxCmdGetCalibrationFullscale(Sfc5xxxCmdGetCalibrationInformationBase): """ Get Calibration Fullscale Command Get the fullscale flow of a specific calibration index. """
[docs] def __init__(self, index): """ Constructor. :param int index: The calibration index to read the requested information from. """ super(Sfc5xxxCmdGetCalibrationFullscale, self).__init__( data=b"".join([bytes(bytearray([0x14])), pack(">I", index)]), max_response_time=0.01, post_processing_time=0.0, min_response_length=4, max_response_length=4 )
[docs] @staticmethod def interpret_response(data): """ :return: The read fullscale flow in the unit of the corresponding calibration. :rtype: float """ fullscale = float(unpack(">f", data[0:4])[0]) # float return fullscale
[docs]class Sfc5xxxCmdGetCalibrationInitialConditions(Sfc5xxxCmdGetCalibrationInformationBase): """ Get Calibration Initial Conditions Command Get the initial calibration conditions of a specific calibration index. """
[docs] def __init__(self, index): """ Constructor. :param int index: The calibration index to read the requested information from. """ super(Sfc5xxxCmdGetCalibrationInitialConditions, self).__init__( data=b"".join([bytes(bytearray([0x15])), pack(">I", index)]), max_response_time=0.01, post_processing_time=0.0, min_response_length=127, max_response_length=127 )
[docs] @staticmethod def interpret_response(data): """ :return: - company (str) - The company which has created the calibration. - operator (str) - The operator who has created the calibration. - year (int) - Year of the calibration date. - month (int) - Month of the calibration date. - day (int) - Day of the calibration date. - hour (int) - Hour of the calibration time. - minute (int) - Minute of the calibration time. - temperature (float) - System/gas temperature [°C] of calibration. - inlet_pressure (float) - Absolute pressure of gas inlet [bar]. - differential_pressure (float) - Pressure difference between inlet and outlet [bar]. - is_real_gas_calibration (bool) - Whether the calibration was performed with the real process gas (true) or if it was calculated from a different gas (false). - accuracy_setpoint (float) - Calibration accuracy in percent of the setpoint. This accuracy is valid if larger than the accuracy of fullscale. - accuracy_fullscale (float) - Calibration accuracy in percent of fullscale. This value is valid if larger than the accuracy of the setpoint. :rtype: tuple """ company = str(data[0:50].decode('utf-8').rstrip('\0')) # string<50> operator = str(data[50:100].decode('utf-8').rstrip('\0')) # string<50> year = int(unpack(">H", data[100:102])[0]) # uint16 month = int(unpack(">B", data[102:103])[0]) # uint8 day = int(unpack(">B", data[103:104])[0]) # uint8 hour = int(unpack(">B", data[104:105])[0]) # uint8 minute = int(unpack(">B", data[105:106])[0]) # uint8 temperature = float(unpack(">f", data[106:110])[0]) # float inlet_pressure = float(unpack(">f", data[110:114])[0]) # float differential_pressure = float(unpack(">f", data[114:118])[0]) # float is_real_gas_calibration = bool(unpack(">?", data[118:119])[0]) # bool accuracy_setpoint = float(unpack(">f", data[119:123])[0]) # float accuracy_fullscale = float(unpack(">f", data[123:127])[0]) # float return company,\ operator,\ year,\ month,\ day,\ hour,\ minute,\ temperature,\ inlet_pressure,\ differential_pressure,\ is_real_gas_calibration,\ accuracy_setpoint,\ accuracy_fullscale
[docs]class Sfc5xxxCmdGetCalibrationRecalibrationConditions(Sfc5xxxCmdGetCalibrationInformationBase): """ Get Calibration Recalibration Conditions Command Get the recalibration conditions of a specific calibration index. """
[docs] def __init__(self, index): """ Constructor. :param int index: The calibration index to read the requested information from. """ super(Sfc5xxxCmdGetCalibrationRecalibrationConditions, self).__init__( data=b"".join([bytes(bytearray([0x16])), pack(">I", index)]), max_response_time=0.01, post_processing_time=0.0, min_response_length=127, max_response_length=127 )
[docs] @staticmethod def interpret_response(data): """ :return: - company (str) - The company which has created the recalibration. - operator (str) - The operator who has created the recalibration. - year (int) - Year of the recalibration date. - month (int) - Month of the recalibration date. - day (int) - Day of the recalibration date. - hour (int) - Hour of the recalibration time. - minute (int) - Minute of the recalibration time. - temperature (float) - System/gas temperature [°C] of recalibration. - inlet_pressure (float) - Absolute pressure of gas inlet [bar]. - differential_pressure (float) - Pressure difference between inlet and outlet [bar]. - is_real_gas_calibration (bool) - Whether the recalibration was performed with the real process gas (true) or if it was calculated from a different gas (false). - accuracy_setpoint (float) - Calibration accuracy in percent of the setpoint. This accuracy is valid if larger than the accuracy of fullscale. - accuracy_fullscale (float) - Calibration accuracy in percent of fullscale. This value is valid if larger than the accuracy of the setpoint. :rtype: tuple """ company = str(data[0:50].decode('utf-8').rstrip('\0')) # string<50> operator = str(data[50:100].decode('utf-8').rstrip('\0')) # string<50> year = int(unpack(">H", data[100:102])[0]) # uint16 month = int(unpack(">B", data[102:103])[0]) # uint8 day = int(unpack(">B", data[103:104])[0]) # uint8 hour = int(unpack(">B", data[104:105])[0]) # uint8 minute = int(unpack(">B", data[105:106])[0]) # uint8 temperature = float(unpack(">f", data[106:110])[0]) # float inlet_pressure = float(unpack(">f", data[110:114])[0]) # float differential_pressure = float(unpack(">f", data[114:118])[0]) # float is_real_gas_calibration = bool(unpack(">?", data[118:119])[0]) # bool accuracy_setpoint = float(unpack(">f", data[119:123])[0]) # float accuracy_fullscale = float(unpack(">f", data[123:127])[0]) # float return company,\ operator,\ year,\ month,\ day,\ hour,\ minute,\ temperature,\ inlet_pressure,\ differential_pressure,\ is_real_gas_calibration,\ accuracy_setpoint,\ accuracy_fullscale
[docs]class Sfc5xxxCmdGetCalibrationThermalConductivityReference(Sfc5xxxCmdGetCalibrationInformationBase): """ Get Calibration Thermal Conductivity Reference Command Get the thermal conductivity reference value of a specific calibration index. """
[docs] def __init__(self, index): """ Constructor. :param int index: The calibration index to read the requested information from. """ super(Sfc5xxxCmdGetCalibrationThermalConductivityReference, self).__init__( data=b"".join([bytes(bytearray([0x17])), pack(">I", index)]), max_response_time=0.01, post_processing_time=0.0, min_response_length=2, max_response_length=2 )
[docs] @staticmethod def interpret_response(data): """ :return: Thermal conductivity reference value for the gas. :rtype: int """ reference_value = int(unpack(">H", data[0:2])[0]) # uint16 return reference_value