UT330BUI/model/UT330.py
def write_config(self, config):

        """Sets the configuration information on the device"""

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

        # Check config parameters
        # -----------------------
        if len(config['device name']) > 10:
            raise ValueError('Error! device name {0} is {1} characters when '
                             'it can be a maximum of 10'.
                             format(config['device name'],
                                    len(config['device name'])))

        if len(config['device name']) == 0:
            raise ValueError('Error! device name is length zero, it needs '
                             'to be more than zero characters')

        if config['sampling interval'] < 0 or \
           config['sampling interval'] > 86400:
            raise ValueError('Error! sampling interval is {0} but it must be '
                             'between 0 and 86400'.
                             format(config['sampling interval']))

        if config['delay timing'] < 0 or config['delay timing'] > 604800:
            raise ValueError('Error! delay timing is {0} but it must be '
                             'between 0 and 604800'.
                             format(config['delay timing']))

        # Prepare the data for writing
        # ----------------------------

        # Add the device name - pad to 10 characters with spaces
        for idx, val in enumerate(config['device name'][0:10].rjust(10, ' ')):
            self._buffer[4 + idx] = ord(val)

        # Add the sampling interval
        self._buffer[14] = config['sampling interval'] & 0xff
        self._buffer[15] = (config['sampling interval'] & 0x00ff00) >> 8
        self._buffer[16] = (config['sampling interval'] & 0xff0000) >> 16

        self._buffer[17] = int(config['overwrite records'])
        self._buffer[18] = int(config['delay start'])

        # Delay timing
        self._buffer[19] = config['delay timing'] & 0xff
        self._buffer[20] = (config['delay timing'] & 0x00ff00) >> 8
        self._buffer[21] = (config['delay timing'] & 0xff0000) >> 16

        self._buffer[22] = 0  # I don't know what this byte is

        if config['high temperature alarm'] >= 0:
            self._buffer[23] = config['high temperature alarm']
        else:
            self._buffer[23] = 256 + config['high temperature alarm']

        if config['low temperature alarm'] < 0:
            self._buffer[24] = 256 + config['low temperature alarm']
        else:
            self._buffer[24] = config['low temperature alarm']

        self._buffer[25] = config['high humidity alarm']
        self._buffer[26] = config['low humidity alarm']

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

        # Write the buffer
        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, 16, 0, 115, 117] != self._buffer:
            raise IOError("Error! Config writing returned error code.")
Sets the configuration information on the device
Sets the configuration information on the device
Sets the configuration information on the device
def write_config(self, config):
        self._buffer = [0xab, 0xcd, 0x1a, 0x10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
        if len(config['device name']) > 10:
            raise ValueError('Error! device name {0} is {1} characters when '
                             'it can be a maximum of 10'.
                             format(config['device name'],
                                    len(config['device name'])))
        if len(config['device name']) == 0:
            raise ValueError('Error! device name is length zero, it needs '
                             'to be more than zero characters')
        if config['sampling interval'] < 0 or \
           config['sampling interval'] > 86400:
            raise ValueError('Error! sampling interval is {0} but it must be '
                             'between 0 and 86400'.
                             format(config['sampling interval']))
        if config['delay timing'] < 0 or config['delay timing'] > 604800:
            raise ValueError('Error! delay timing is {0} but it must be '
                             'between 0 and 604800'.
                             format(config['delay timing']))
        -----
        for idx, val in enumerate(config['device name'][0:10].rjust(10, ' ')):
            self._buffer[4 + idx] = ord(val)
        self._buffer[14] = config['sampling interval'] & 0xff
        self._buffer[15] = (config['sampling interval'] & 0x00ff00) >> 8
        self._buffer[16] = (config['sampling interval'] & 0xff0000) >> 16
        self._buffer[17] = int(config['overwrite records'])
        self._buffer[18] = int(config['delay start'])
        self._buffer[19] = config['delay timing'] & 0xff
        self._buffer[20] = (config['delay timing'] & 0x00ff00) >> 8
        self._buffer[21] = (config['delay timing'] & 0xff0000) >> 16
        self._buffer[22] = 0  
        if config['high temperature alarm'] >= 0:
            self._buffer[23] = config['high temperature alarm']
        else:
            self._buffer[23] = 256 + config['high temperature alarm']
        if config['low temperature alarm'] < 0:
            self._buffer[24] = 256 + config['low temperature alarm']
        else:
            self._buffer[24] = config['low temperature alarm']
        self._buffer[25] = config['high humidity alarm']
        self._buffer[26] = config['low humidity alarm']
        self._buffer[28], self._buffer[27] = modbusCRC(self._buffer[0:27])
        self._write_buffer()
        self._read_buffer(7)
        if [171, 205, 4, 16, 0, 115, 117] != self._buffer:
            raise IOError("Error! Config writing returned error code.")
def write_config ( self , config ) : self . _buffer = [ 0xab , 0xcd , 0x1a , 0x10 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] if len ( config [ 'device name' ] ) > 10 : raise ValueError ( 'Error! device name {0} is {1} characters when ' 'it can be a maximum of 10' . format ( config [ 'device name' ] , len ( config [ 'device name' ] ) ) ) if len ( config [ 'device name' ] ) == 0 : raise ValueError ( 'Error! device name is length zero, it needs ' 'to be more than zero characters' ) if config [ 'sampling interval' ] < 0 or config [ 'sampling interval' ] > 86400 : raise ValueError ( 'Error! sampling interval is {0} but it must be ' 'between 0 and 86400' . format ( config [ 'sampling interval' ] ) ) if config [ 'delay timing' ] < 0 or config [ 'delay timing' ] > 604800 : raise ValueError ( 'Error! delay timing is {0} but it must be ' 'between 0 and 604800' . format ( config [ 'delay timing' ] ) ) for idx , val in enumerate ( config [ 'device name' ] [ 0 : 10 ] . rjust ( 10 , ' ' ) ) : self . _buffer [ 4 + idx ] = ord ( val ) self . _buffer [ 14 ] = config [ 'sampling interval' ] & 0xff self . _buffer [ 15 ] = ( config [ 'sampling interval' ] & 0x00ff00 ) >> 8 self . _buffer [ 16 ] = ( config [ 'sampling interval' ] & 0xff0000 ) >> 16 self . _buffer [ 17 ] = int ( config [ 'overwrite records' ] ) self . _buffer [ 18 ] = int ( config [ 'delay start' ] ) self . _buffer [ 19 ] = config [ 'delay timing' ] & 0xff self . _buffer [ 20 ] = ( config [ 'delay timing' ] & 0x00ff00 ) >> 8 self . _buffer [ 21 ] = ( config [ 'delay timing' ] & 0xff0000 ) >> 16 self . _buffer [ 22 ] = 0 if config [ 'high temperature alarm' ] >= 0 : self . _buffer [ 23 ] = config [ 'high temperature alarm' ] else : self . _buffer [ 23 ] = 256 + config [ 'high temperature alarm' ] if config [ 'low temperature alarm' ] < 0 : self . _buffer [ 24 ] = 256 + config [ 'low temperature alarm' ] else : self . _buffer [ 24 ] = config [ 'low temperature alarm' ] self . _buffer [ 25 ] = config [ 'high humidity alarm' ] self . _buffer [ 26 ] = config [ 'low humidity alarm' ] self . _buffer [ 28 ] , self . _buffer [ 27 ] = modbusCRC ( self . _buffer [ 0 : 27 ] ) self . _write_buffer ( ) self . _read_buffer ( 7 ) if [ 171 , 205 , 4 , 16 , 0 , 115 , 117 ] != self . _buffer : raise IOError ( "Error! Config writing returned error code." )
Sets the configuration information on the device
Sets the configuration information on the device
"""Sets the configuration information on the device""" # The command to send, note we'll be overriding some bytes # Check config parameters # ----------------------- # Prepare the data for writing # ---------------------------- # Add the device name - pad to 10 characters with spaces # Add the sampling interval # Delay timing # I don't know what this byte is # Add the CRC bytes # Write the buffer # Now get the response data from the buffer # Check the return code shows the data was correctly written
self
config