Source code for sensirion_shdlc_sfc5xxx.commands.set_setpoint_and_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 Sfc5xxxCmdSetSetpointAndReadMeasuredValueBase(ShdlcCommand): """ SHDLC command 0x03: "Set Setpoint And Read Measured Value". """
[docs] def __init__(self, *args, **kwargs): """ Constructor. """ super(Sfc5xxxCmdSetSetpointAndReadMeasuredValueBase, self).__init__( 0x03, *args, **kwargs)
[docs]class Sfc5xxxCmdSetSetpointAndReadMeasuredValue(Sfc5xxxCmdSetSetpointAndReadMeasuredValueBase): """ Set Setpoint And Read Measured Value Command 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 safes a lot of protocol overhead compared to separate command usage. .. note:: If the "setpoint persists" feature is enabled, the setpoint will be stored in non-volatile memory and re-applied after a device reset. """
[docs] def __init__(self, scaling, setpoint): """ Constructor. :param int scaling: Defines with which scale resp. unit the setpoint and measured flow are transmitted: - 0x00: Normalized setpoint/flow in range [0.0 ... 1.0] - 0x01: Setpoint/flow represents physical values. The range depends on the flow unit and calibration range. - 0x02: Setpoint/flow represent values in the user defined medium unit. Requires at least firmware version 1.40. :param float setpoint: The new setpoint with the specified scaling. """ super(Sfc5xxxCmdSetSetpointAndReadMeasuredValue, self).__init__( data=b"".join([pack(">B", scaling), pack(">f", setpoint)]), 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