UT330BUI/model/UT330.py
def write_offsets(self, offsets):

        """Set the device offsets for temperature, humidity, pressure"""

        # Check for errors in parameters
        if offsets['temperature offset'] > 6.1 or \
           offsets['temperature offset'] < -6:
            raise ValueError('Error! The temperature offset is {0} when it '
                             'must be between -6 and 6.1 C'.
                             format(offsets['temperature offset']))

        if offsets['humidity offset'] > 6.1 or offsets['humidity offset'] < -6:
            raise ValueError('Error! The humidity offset is {0} when it must '
                             'be between -6% and 6.1%'.
                             format(offsets['humidity offset']))

        if offsets['pressure offset'] > 6.1 or offsets['pressure offset'] < -6:
            raise ValueError('Error! The pressure offset is {0} when it must '
                             'be between -6hpa and 6.1hpa'.
                             format(offsets['pressure offset']))

        # The command to send, note we'll be overriding some bytes
        self._buffer = [0xab, 0xcd, 0x06, 0x16, 0, 0, 0, 0, 0]

        if offsets['temperature offset'] < 0:
            self._buffer[4] = 256 - int(offsets['temperature offset']*10)
        else:
            self._buffer[4] = int(offsets['temperature offset']*10)

        if offsets['humidity offset'] < 0:
            self._buffer[5] = 256 - int(offsets['humidity offset']*10)
        else:
            self._buffer[5] = int(offsets['humidity offset']*10)

        if offsets['pressure offset'] < 0:
            self._buffer[6] = 256 - int(offsets['pressure offset']*10)
        else:
            self._buffer[6] = int(offsets['pressure offset']*10)

        # Add the CRC bytes
        self._buffer[8], self._buffer[7] = modbusCRC(self._buffer[0:7])

        self._write_buffer()

        # Now get the response data from the buffer
        self._read_buffer(7)

        # Check the return code shows the data was correctly written
        if [171, 205, 4, 22, 0, 112, 213] != self._buffer:
            raise IOError("Error! Offset writing returned error code.")
Set the device offsets for temperature, humidity, pressure
Set the device offsets for temperature, humidity, pressure
Set the device offsets for temperature humidity pressure
def write_offsets(self, offsets):
        if offsets['temperature offset'] > 6.1 or \
           offsets['temperature offset'] < -6:
            raise ValueError('Error! The temperature offset is {0} when it '
                             'must be between -6 and 6.1 C'.
                             format(offsets['temperature offset']))
        if offsets['humidity offset'] > 6.1 or offsets['humidity offset'] < -6:
            raise ValueError('Error! The humidity offset is {0} when it must '
                             'be between -6% and 6.1%'.
                             format(offsets['humidity offset']))
        if offsets['pressure offset'] > 6.1 or offsets['pressure offset'] < -6:
            raise ValueError('Error! The pressure offset is {0} when it must '
                             'be between -6hpa and 6.1hpa'.
                             format(offsets['pressure offset']))
        self._buffer = [0xab, 0xcd, 0x06, 0x16, 0, 0, 0, 0, 0]
        if offsets['temperature offset'] < 0:
            self._buffer[4] = 256 - int(offsets['temperature offset']*10)
        else:
            self._buffer[4] = int(offsets['temperature offset']*10)
        if offsets['humidity offset'] < 0:
            self._buffer[5] = 256 - int(offsets['humidity offset']*10)
        else:
            self._buffer[5] = int(offsets['humidity offset']*10)
        if offsets['pressure offset'] < 0:
            self._buffer[6] = 256 - int(offsets['pressure offset']*10)
        else:
            self._buffer[6] = int(offsets['pressure offset']*10)
        self._buffer[8], self._buffer[7] = modbusCRC(self._buffer[0:7])
        self._write_buffer()
        self._read_buffer(7)
        if [171, 205, 4, 22, 0, 112, 213] != self._buffer:
            raise IOError("Error! Offset writing returned error code.")
def write_offsets ( self , offsets ) : if offsets [ 'temperature offset' ] > 6.1 or offsets [ 'temperature offset' ] < - 6 : raise ValueError ( 'Error! The temperature offset is {0} when it ' 'must be between -6 and 6.1 C' . format ( offsets [ 'temperature offset' ] ) ) if offsets [ 'humidity offset' ] > 6.1 or offsets [ 'humidity offset' ] < - 6 : raise ValueError ( 'Error! The humidity offset is {0} when it must ' 'be between -6% and 6.1%' . format ( offsets [ 'humidity offset' ] ) ) if offsets [ 'pressure offset' ] > 6.1 or offsets [ 'pressure offset' ] < - 6 : raise ValueError ( 'Error! The pressure offset is {0} when it must ' 'be between -6hpa and 6.1hpa' . format ( offsets [ 'pressure offset' ] ) ) self . _buffer = [ 0xab , 0xcd , 0x06 , 0x16 , 0 , 0 , 0 , 0 , 0 ] if offsets [ 'temperature offset' ] < 0 : self . _buffer [ 4 ] = 256 - int ( offsets [ 'temperature offset' ] * 10 ) else : self . _buffer [ 4 ] = int ( offsets [ 'temperature offset' ] * 10 ) if offsets [ 'humidity offset' ] < 0 : self . _buffer [ 5 ] = 256 - int ( offsets [ 'humidity offset' ] * 10 ) else : self . _buffer [ 5 ] = int ( offsets [ 'humidity offset' ] * 10 ) if offsets [ 'pressure offset' ] < 0 : self . _buffer [ 6 ] = 256 - int ( offsets [ 'pressure offset' ] * 10 ) else : self . _buffer [ 6 ] = int ( offsets [ 'pressure offset' ] * 10 ) self . _buffer [ 8 ] , self . _buffer [ 7 ] = modbusCRC ( self . _buffer [ 0 : 7 ] ) self . _write_buffer ( ) self . _read_buffer ( 7 ) if [ 171 , 205 , 4 , 22 , 0 , 112 , 213 ] != self . _buffer : raise IOError ( "Error! Offset writing returned error code." )
Set the device offsets for temperature, humidity, pressure
Set the device offsets for temperature humidity pressure
"""Set the device offsets for temperature, humidity, pressure""" # Check for errors in parameters # The command to send, note we'll be overriding some bytes # Add the CRC bytes # Now get the response data from the buffer # Check the return code shows the data was correctly written
self
offsets