def __getitem__(self, index):
        """
        Indexes a subset of custom scales on this collection.

        Args:
            index: The value of the index. The following index types
                are supported:
                - str: Name of the custom scale. You also can specify
                    a string that contains a list or range of names to
                    this input. If you have a list of names, use the
                    DAQmx Flatten Channel String function to convert
                    the list to a string.
                - int: Index/position of the custom scale in the
                    collection.
                - slice: Range of the indexes/positions of custom scales
                    in the collection.
        Returns:
            List[nidaqmx.system.storage.persisted_scale.PersistedScale]:
            
            Indicates the subset of custom scales indexed.
        """
        if isinstance(index, six.integer_types):
            return PersistedScale(self.scale_names[index])
        elif isinstance(index, slice):
            return [PersistedScale(name) for name in self.scale_names[index]]
        elif isinstance(index, six.string_types):
            names = unflatten_channel_string(index)
            if len(names) == 1:
                return PersistedScale(names[0])
            return [PersistedScale(name) for name in names]
        else:
            raise DaqError(
                'Invalid index type "{0}" used to access collection.'.format(
                    type(index)), DAQmxErrors.UNKNOWN.value)
Ejemplo n.º 2
0
 def make(cls, scale_type) -> Dict[str, Union[int, str]]:
     assert Scale.From.supports(
         scale_type), f'value {scale_type} not supported for scaling.'
     if cls._should_make():
         if not hasattr(cls, 'made_scales'):
             cls.made_scales = set()
         if not cls.name() in cls.made_scales:
             try:
                 PersistedScale(cls.name()).delete()
             except nidaqmx.DaqError:
                 pass
             cls._make()
             cls.made_scales.add(cls.name())
         return dict(units=scale_type, custom_scale_name=cls.name())
     return {}
    def __reversed__(self):
        scale_names = self.scale_names
        scale_names.reverse()

        for scale_name in scale_names:
            yield PersistedScale(scale_name)
 def __iter__(self):
     for scale_name in self.scale_names:
         yield PersistedScale(scale_name)