Source code for sensirion_shdlc_sfc5xxx.commands.read_measured_value_buffer

# -*- 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 Sfc5xxxCmdReadMeasuredValueBufferBase(ShdlcCommand): """ SHDLC command 0x09: "Read Measured Value Buffer". """
[docs] def __init__(self, *args, **kwargs): """ Constructor. """ super(Sfc5xxxCmdReadMeasuredValueBufferBase, self).__init__( 0x09, *args, **kwargs)
[docs]class Sfc5xxxCmdReadMeasuredValueBuffer(Sfc5xxxCmdReadMeasuredValueBufferBase): """ Read Measured Value Buffer Command The MFC has an internal ring buffer in which the measured flow values are automatically stored in a regular interval. The size of the buffer is between 85 and 256 (depends on the specific device configuration). With this command you can readout the buffered values (maximum 60 values per transfer, due to the limited space in the data part of the SHDLC frame). If you do not readout the buffer or you are too slow with reading, the oldest values will be lost. .. note:: The values which have been read will automatically be cleared from the ring buffer. """
[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(Sfc5xxxCmdReadMeasuredValueBuffer, self).__init__( data=b"".join([pack(">B", scaling)]), max_response_time=0.005, post_processing_time=0.0, min_response_length=12, max_response_length=255 )
[docs] @staticmethod def interpret_response(data): """ :return: - lost_value_count (int) - If the time between the "Read Measured Value Buffer" command calls is to large, the internal ring buffer will overrun. In this case, the oldest value in the buffer is cleared when a new value enters. This number is a counter which counts the missing values between the function calls (number of values which were not readout by the bus master). - remaining_value_count (int) - The number of values which remains in the buffer after this command call (the number of returned values is limited to 60 values because the maximum allowed data part in the SHDLC frame is 255 bytes). - sampling_time (float) - Time between the measured values in Seconds. - measured_values (list(float)) - The measured values read from the ring buffer (0...60 values) with the specified scaling. :rtype: tuple """ lost_value_count = int(unpack(">I", data[0:4])[0]) # uint32 remaining_value_count = int(unpack(">I", data[4:8])[0]) # uint32 sampling_time = float(unpack(">f", data[8:12])[0]) # float measured_values = [float(ii) for ii in unpack(">{}f".format(len(data[12:]) // 4), data[12:])] # list(float) return lost_value_count,\ remaining_value_count,\ sampling_time,\ measured_values