Source code for sensirion_shdlc_sfc5xxx.commands.read_measured_value

# -*- 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 Sfc5xxxCmdReadMeasuredValueBase(ShdlcCommand): """ SHDLC command 0x08: "Read Measured Value". """
[docs] def __init__(self, *args, **kwargs): """ Constructor. """ super(Sfc5xxxCmdReadMeasuredValueBase, self).__init__( 0x08, *args, **kwargs)
[docs]class Sfc5xxxCmdReadMeasuredValue(Sfc5xxxCmdReadMeasuredValueBase): """ Read Measured Value Command The command returns the latest measured flow value. The value can be read as physical or normalized value. """
[docs] def __init__(self, scaling): """ Constructor. :param int scaling: Defines with which scale resp. unit the measured flow should be returned: - 0x00: Normalized flow in range [0.0 ... 1.0] - 0x01: Flow represents a physical value. The range depends on the flow unit and calibration range. - 0x02: Flow represents a value in the user defined medium unit. Requires at least firmware version 1.40. """ super(Sfc5xxxCmdReadMeasuredValue, self).__init__( data=b"".join([pack(">B", scaling)]), max_response_time=0.005, post_processing_time=0.0, min_response_length=4, max_response_length=4 )
[docs] @staticmethod def interpret_response(data): """ :return: The latest measured flow with the specified scaling. :rtype: float """ measured_value = float(unpack(">f", data[0:4])[0]) # float return measured_value