def controls_status(self, params=None):
        """ Get status of controls (binary True if active).
        :return: Dictionary of active controls.
        """
        if params is not None:
            pass
        else:
            params = {}
            reg_start = self.ctrl_reg_start

            data = self.ctrl_device.read(self.ctrl_reg_start,
                                         self.ctrl_modbus_read_length)
            print(data)

            for reg in range(self.ctrl_modbus_read_length):
                # print('Register: %s = %s' % (reg + reg_start, data[reg * 2:2 + reg * 2]))
                try:
                    data_point = suns_util.data_to_u16(data[reg * 2:2 +
                                                            reg * 2])
                    print('Register: %s = %s' % (reg + reg_start, data_point))
                except Exception as e:
                    print('Warning: %s' % e)
            # data = self.ctrl_device.read(4790, 2)
            # print('Power: %s' % suns_util.data_to_u16(data))
            #
            # data = self.ctrl_device.read(4729, 2)
            # print('Power: %s' % suns_util.data_to_s16(data))

        return params
    def measurements(self):
        """ Get measurement data.

        Params:

        :return: Dictionary of measurement data.
        """
        params = {}
        data = self.data_device.read(self.data_reg_start,
                                     self.data_modbus_read_length)

        reg_start = self.data_reg_start
        for reg in range(self.data_modbus_read_length):
            data_point = suns_util.data_to_u16(data[reg * 2:2 + reg * 2])
            # print('Register: %s = %s' % (reg + reg_start, data_point))
            if (reg + reg_start) == 50061:
                params['Utility_V1'] = data_point
            if reg + reg_start == 50062:
                params['Utility_V2'] = data_point
            if reg + reg_start == 50063:
                params['Utility_V3'] = data_point
            if reg + reg_start == 50064:
                params['Utility_V4'] = data_point
            if reg + reg_start == 50080:
                params['Generator_V5'] = data_point
            if reg + reg_start == 50120:
                params['Generator_V7'] = data_point

            if reg + reg_start == 50073:
                params['Utility_F1'] = data_point
            if reg + reg_start == 50081:
                params['Generator_F2'] = data_point

            if reg + reg_start == 50069:
                params['Utility_I1'] = data_point
            if reg + reg_start == 50070:
                params['Utility_I2'] = data_point
            if reg + reg_start == 50071:
                params['Utility_I3'] = data_point
            if reg + reg_start == 50072:
                params['Utility_I4'] = data_point

            if reg + reg_start == 50059:
                params['Utility_kW'] = data_point

        return params
Ejemplo n.º 3
0
                    if data[:4] == 'SunS':
                        self.base_addr = addr
                        # print 'device base address = %d' % self.base_addr
                        break
                    else:
                        error = 'Device responded - not SunSpec register map'
                except SunSpecClientError, e:
                    if not error:
                        error = str(e)

                if delay is not None:
                    time.sleep(delay)

        if self.base_addr:
            # print 'base address = %s' % (self.base_addr)
            model_id = util.data_to_u16(data[4:6])
            addr = self.base_addr + 2

            while model_id != suns.SUNS_END_MODEL_ID:
                # read model and model len separately due to some devices not supplying
                # count for the end model id
                data = self.read(addr + 1, 1)
                if data and len(data) == 2:
                    if progress is not None:
                        cont = progress('Scanning model %s' % (model_id))
                        if not cont:
                            raise SunSpecClientError('Device scan terminated')
                    model_len = util.data_to_u16(data)
                    # print 'model_id = %s  model_len = %s' % (model_id, model_len)

                    # move address past model id and length
Ejemplo n.º 4
0
    def scan(self, progress=None, delay=None):
        error = ''

        if delay is not None:
            time.sleep(delay)

        if self.base_addr is None:
            for addr in self.base_addr_list:
                # print('trying base address %s' % (addr))
                try:
                    data = self.read(addr, 3)
                    # print("Data: %s" % str(data))
                    if data[:4] == b'SunS':
                        self.base_addr = addr
                        # print('device base address = %d' % self.base_addr)
                        break
                    else:
                        error = 'Device responded - not SunSpec register map'
                except SunSpecClientError as e:
                    if not error:
                        error = str(e)

                if delay is not None:
                    time.sleep(delay)

        if self.base_addr is not None:
            # print('base address = %s' % (self.base_addr))
            model_id = util.data_to_u16(data[4:6])
            addr = self.base_addr + 2

            while model_id != suns.SUNS_END_MODEL_ID:
                # read model and model len separately due to some devices not supplying
                # count for the end model id
                data = self.read(addr + 1, 1)
                if data and len(data) == 2:
                    if progress is not None:
                        cont = progress('Scanning model %s' % (model_id))
                        if not cont:
                            raise SunSpecClientError('Device scan terminated')
                    model_len = util.data_to_u16(data)
                    # print('model_id = %s  model_len = %s' % (model_id, model_len))

                    # move address past model id and length
                    model = ClientModel(self, model_id, addr + 2, model_len)
                    # print('loading model %s at %d' % (model_id, addr + 2))
                    try:
                        model.load()
                    except Exception as e:
                        model.load_error = str(e)
                    self.add_model(model)

                    addr += model_len + 2
                    data = self.read(addr, 1)
                    if data and len(data) == 2:
                        model_id = util.data_to_u16(data)
                    else:
                        break
                else:
                    break

                if delay is not None:
                    time.sleep(delay)

        else:
            if not error:
                error = 'Unknown error'
            raise SunSpecClientError(error)
Ejemplo n.º 5
0
    def scan(self, progress=None, delay=None):
        """Scan all the models of the physical device and create the
        corresponding model objects within the device object based on the
        SunSpec model definitions.
        """

        error = ''

        connect = False
        if self.modbus_device and type(
                self.modbus_device) == modbus.ModbusClientDeviceTCP:
            self.modbus_device.connect()
            connect = True

            if delay is not None:
                time.sleep(delay)

        if self.base_addr is None:
            for addr in self.base_addr_list:
                # print('trying base address %s' % (addr))
                try:
                    data = self.read(addr, 3)
                    if data[:4] == b'SunS':
                        self.base_addr = addr
                        # print('device base address = %d' % self.base_addr)
                        break
                    else:
                        error = 'Device responded - not SunSpec register map'
                except SunSpecClientError as e:
                    if not error:
                        error = str(e)

                if delay is not None:
                    time.sleep(delay)

        if self.base_addr is not None:
            # print('base address = %s' % (self.base_addr))
            model_id = util.data_to_u16(data[4:6])
            addr = self.base_addr + 2

            while model_id != suns.SUNS_END_MODEL_ID:
                # read model and model len separately due to some devices not supplying
                # count for the end model id
                data = self.read(addr + 1, 1)
                if data and len(data) == 2:
                    if progress is not None:
                        cont = progress('Scanning model %s' % (model_id))
                        if not cont:
                            raise SunSpecClientError('Device scan terminated')
                    model_len = util.data_to_u16(data)
                    # print('model_id = %s  model_len = %s' % (model_id, model_len))

                    # move address past model id and length
                    model = ClientModel(self, model_id, addr + 2, model_len)
                    # print('loading model %s at %d' % (model_id, addr + 2))
                    try:
                        model.load()
                    except Exception as e:
                        model.load_error = str(e)
                    self.add_model(model)

                    addr += model_len + 2
                    data = self.read(addr, 1)
                    if data and len(data) == 2:
                        model_id = util.data_to_u16(data)
                    else:
                        break
                else:
                    break

                if delay is not None:
                    time.sleep(delay)

        else:
            if not error:
                error = 'Unknown error'
            raise SunSpecClientError(error)

        if connect:
            self.modbus_device.disconnect()
def readHz():
    data = device.read(1179, 1)
    freq = util.data_to_u16(data) * (10**-2)
    return freq
def readBaudRate():
    data = device.read(628, 1)
    return util.data_to_u16(data)
def readFreqNom():
    data = device.read(3207, 1)
    return util.data_to_u16(data)
Ejemplo n.º 9
0
def readCommitPower():
    data = device.read(0xf100, 1)  # read Commit Power Control Settings
    w_max_ena = util.data_to_u16(data)
    print 'active power ena = %s' % (w_max_ena == 0)
Ejemplo n.º 10
0
def readPower():
    data = device.read(0xf001, 1)  # read power
    w_max = util.data_to_u16(data)
    print 'active power = %s' % w_max
    return w_max
Ejemplo n.º 11
0
def readPF_Ena():
    data = device.read(0xf104, 1)  # read power factor enable
    pf_ena = util.data_to_u16(data)
    print 'power factor ena = %s' % (pf_ena == 0)
    return (pf_ena == 0)
Ejemplo n.º 12
0
def readRestorePowerControl():
    data = device.read(0xf100,
                       1)  # read Restore Power Control Default Settings
    restore = util.data_to_u16(data)
    print 'active power ena = %s' % restore
    return restore
Ejemplo n.º 13
0
 def test_data_to_u16(self):
     self.assertEqual(util.data_to_u16(b'\x12\x34'), int(4660))
     self.assertEqual(util.data_to_u16(b'\x92\x34'), int(37428))
Ejemplo n.º 14
0
    def scan(self, progress=None, delay=None):
        """Scan all the models of the physical device and create the
        corresponding model objects within the device object based on the
        SunSpec model definitions.
        """

        error = ''

        connect = False
        if self.modbus_device and type(self.modbus_device) == modbus.ModbusClientDeviceTCP:
            self.modbus_device.connect()
            connect = True

            if delay is not None:
                time.sleep(delay)

        if self.base_addr is None:
            for addr in self.base_addr_list:
                # print('trying base address %s' % (addr))
                try:
                    data = self.read(addr, 3)
                    if data[:4] == b'SunS':
                        self.base_addr = addr
                        # print('device base address = %d' % self.base_addr)
                        break
                    else:
                        error = 'Device responded - not SunSpec register map'
                except SunSpecClientError as e:
                    if not error:
                        error = str(e)

                if delay is not None:
                    time.sleep(delay)

        if self.base_addr is not None:
            # print('base address = %s' % (self.base_addr))
            model_id = util.data_to_u16(data[4:6])
            addr = self.base_addr + 2

            while model_id != suns.SUNS_END_MODEL_ID:
                # read model and model len separately due to some devices not supplying
                # count for the end model id
                data = self.read(addr + 1, 1)
                if data and len(data) == 2:
                    if progress is not None:
                        cont = progress('Scanning model %s' % (model_id))
                        if not cont:
                            raise SunSpecClientError('Device scan terminated')
                    model_len = util.data_to_u16(data)
                    # print('model_id = %s  model_len = %s' % (model_id, model_len))

                    # move address past model id and length
                    model = ClientModel(self, model_id, addr + 2, model_len)
                    # print('loading model %s at %d' % (model_id, addr + 2))
                    try:
                        model.load()
                    except Exception as e:
                        model.load_error = str(e)
                    self.add_model(model)

                    addr += model_len + 2
                    data = self.read(addr, 1)
                    if data and len(data) == 2:
                        model_id = util.data_to_u16(data)
                    else:
                        break
                else:
                    break

                if delay is not None:
                    time.sleep(delay)

        else:
            if not error:
                error = 'Unknown error'
            raise SunSpecClientError(error)

        if connect:
            self.modbus_device.disconnect()
Ejemplo n.º 15
0
                    if data[:4] == 'SunS':
                        self.base_addr = addr
                        # print 'device base address = %d' % self.base_addr
                        break
                    else:
                        error = 'Device responded - not SunSpec register map'
                except SunSpecClientError, e:
                    if not error:
                        error = str(e)

                if delay is not None:
                    time.sleep(delay)

        if self.base_addr is not None:
            # print 'base address = %s' % (self.base_addr)
            model_id = util.data_to_u16(data[4:6])
            addr = self.base_addr + 2

            while model_id != suns.SUNS_END_MODEL_ID:
                # read model and model len separately due to some devices not supplying
                # count for the end model id
                data = self.read(addr + 1, 1)
                if data and len(data) == 2:
                    if progress is not None:
                        cont = progress('Scanning model %s' % (model_id))
                        if not cont:
                            raise SunSpecClientError('Device scan terminated')
                    model_len = util.data_to_u16(data)
                    # print 'model_id = %s  model_len = %s' % (model_id, model_len)

                    # move address past model id and length
Ejemplo n.º 16
0
 def test_data_to_u16(self):
     self.assertEqual(util.data_to_u16(b'\x12\x34'), int(4660))
     self.assertEqual(util.data_to_u16(b'\x92\x34'), int(37428))