Beispiel #1
0
 def __init__(self,
              read_only,
              point_name,
              attribute_name,
              units,
              data_type,
              station_id,
              default_value=None,
              description='',
              port_number=None,
              username=None,
              timeout=0):
     super(StationRightsRegister,
           self).__init__(read_only, point_name, attribute_name, units,
                          data_type, station_id, default_value, description,
                          port_number, username, timeout)
     if attribute_name not in StationRightsRegister.attribute_list:
         raise DriverInterfaceError(
             '{0} cannot be assigned to this register.'.format(
                 attribute_name))
     if not read_only and attribute_name not in StationRightsRegister.writeable_list:
         raise DriverInterfaceError(
             '{0} cannot be configured as a writeable register'.format(
                 attribute_name))
Beispiel #2
0
    def parse_config(self, config_dict, registry_config_str):
        """Main method to parse the CSV registry config file."""

        if registry_config_str is None:
            return

        for regDef in registry_config_str:
            # Skip lines that have no address yet.
            if not regDef['Attribute Name']:
                continue

            point_name = regDef['Volttron Point Name']
            attribute_name = regDef['Attribute Name']
            port_num = regDef['Port #']
            type_name = regDef.get("Type", 'string')
            units = regDef['Units']
            read_only = regDef['Writable'].lower() != 'true'
            description = regDef.get('Notes', '')
            register_name = regDef['Register Name']
            default_value = regDef.get('Starting Value', None)
            default_value = default_value if default_value != '' else None

            data_type = type_mapping.get(type_name, str)

            current_module = sys.modules[__name__]
            try:
                register_type = getattr(current_module, register_name)
            except AttributeError:
                _log.error('{0} is not a valid register'.format(register_name))
                raise DriverInterfaceError(
                    'Improperly configured register name')

            register = register_type(read_only,
                                     point_name,
                                     attribute_name,
                                     units,
                                     data_type,
                                     config_dict['stationID'],
                                     default_value=default_value,
                                     description=description,
                                     port_number=port_num,
                                     username=config_dict['username'],
                                     timeout=config_dict['cacheExpiration'])

            self.insert_register(register)

            if default_value is not None:
                self.set_default(point_name, register.value)
Beispiel #3
0
    def _scrape_all(self):
        result_dict = {}
        with modbus_client(self.ip_address, self.port) as client:
            try:

                result_dict.update(self.scrape_byte_registers(client, True))
                result_dict.update(self.scrape_byte_registers(client, False))

                result_dict.update(self.scrape_bit_registers(client, True))
                result_dict.update(self.scrape_bit_registers(client, False))
            except (ConnectionException, ModbusIOException,
                    ModbusInterfaceException) as e:
                raise DriverInterfaceError("Failed to scrape device at " +
                                           self.ip_address + ":" +
                                           str(self.port) + " " + "ID: " +
                                           str(self.slave_id) + str(e))

        return result_dict
Beispiel #4
0
 def value(self, x):
     # No points defined by StationRightsRegister are writeable.
     if self.read_only_check():
         raise DriverInterfaceError(
             '{0} cannot be configured as a writeable register'.format(
                 self.attribute_name))