Пример #1
0
    def ch_disable(self, channel):
        """Disable a channel.

        Args:
            channel (int): Channel to be disabled.

        Raises:
            ILStateError: The poller is already running.
            ILValueError: Channel out of range.

        Returns:
            int: Status code.

        """

        if self.__running:
            logger.warning("Poller is running")
            raise_err(IL_ESTATE)

        if channel > self.num_channels:
            logger.error("Channel out of range")
            raise_err(IL_EINVAL)

        # Set channel required as disabled
        self.__mappings_enabled[channel] = False

        return 0
Пример #2
0
    def trigger_configure(self, mode, delay_samples=0, source=None, th_pos=0.,
                          th_neg=0., din_msk=0):
        """Configure the trigger.

        Args:
            mode (MONITOR_TRIGGER): Trigger mode.
            delay_samples (int, optional): Delay samples.
            source (str, Register, optional): Source register, required for
                MONITOR_TRIGGER.POS, MONITOR_TRIGGER.NEG and
                MONITOR_TRIGGER.WINDOW.
            th_pos (int, float, optional): Positive threshold, used for
                MONITOR_TRIGGER.POS, MONITOR_TRIGGER.WINDOW
            th_neg (int, float, optional): Negative threshold, used for
                MONITOR_TRIGGER.NEG, MONITOR_TRIGGER.WINDOW
            din_msk (int, optional): Digital input mask, used for
                MONITOR_TRIGGER.DIN

        """
        if not isinstance(mode, MONITOR_TRIGGER):
            raise TypeError('Invalid trigger mode')

        _source_required = (MONITOR_TRIGGER.POS, MONITOR_TRIGGER.NEG,
                            MONITOR_TRIGGER.WINDOW)

        if mode in _source_required:
            _reg, _id = _get_reg_id(source)
        else:
            _reg, _id = ffi.NULL, ffi.NULL

        r = lib.il_monitor_trigger_configure(
                self._monitor, mode.value, delay_samples, _reg, _id, th_pos,
                th_neg, din_msk)
        raise_err(r)
Пример #3
0
    def ch_configure(self, channel, reg):
        """Configure a poller channel mapping.

        Args:
            channel (int): Channel to be configured.
            reg (Register): Register to associate to the given channel.

        Returns:
            int: Status code.

        Raises:
            ILStateError: The poller is already running.
            ILValueError: Channel out of range.
            TypeError: If the register is not valid.

        """

        if self.__running:
            logger.warning("Poller is running")
            raise_err(IL_ESTATE)

        if channel > self.num_channels:
            logger.error("Channel out of range")
            raise_err(IL_EINVAL)

        # Obtain register
        _reg = self.servo._get_reg(reg)

        # Reg identifier obtained and set enabled
        self.__mappings[channel] = {}
        self.__mappings[channel][_reg.identifier] = int(_reg.subnode)
        self.__mappings_enabled[channel] = True

        return 0
Пример #4
0
    def configure(self, t_s, sz):
        """Configure data.

        Args:
            t_s (int, float): Polling period (s).
            sz (int): Buffer size.

        Returns:
            int: Status code.

        Raises:
            ILStateError: The poller is already running.

        """
        if self.__running:
            logger.warning("Poller is running")
            raise_err(IL_ESTATE)

        # Configure data and sizes with empty data
        self._reset_acq()
        self.__sz = sz
        self.__refresh_time = t_s
        self.__acq['t'] = [0] * sz
        for channel in range(0, self.num_channels):
            data_channel = [0] * sz
            self.__acq['d'].append(data_channel)
            self.__mappings.append('')
            self.__mappings_enabled.append(False)

        return 0
Пример #5
0
    def wait(self, timeout):
        """Wait until the current acquisition finishes.

        Args:
            timeout (int, float): Timeout (s).

        """
        r = lib.il_monitor_wait(self._monitor, to_ms(timeout))
        raise_err(r)
Пример #6
0
    def ch_disable(self, ch):
        """Disable a channel.

        Args:
            ch (int): Channel to be disabled.

        """
        r = lib.il_poller_ch_disable(self._poller, ch)
        raise_err(r)
Пример #7
0
    def save(self, filename):
        """Save dictionary.

        Args:
            filename (str): Output file name/path.

        """
        r = lib.il_dict_save(self._cffi_dictionary, cstr(filename))
        raise_err(r)
Пример #8
0
    def ch_disable(self, ch):
        """Disable a channel.

        Args:
            ch (int): Channel identifier.

        """
        r = lib.il_monitor_ch_disable(self._monitor, ch)
        raise_err(r)
Пример #9
0
    def configure(self, t_s, sz):
        """Configure the poller.

        Args:
            t_s (int, float): Polling period (s).
            sz (int): Buffer size.

        """
        r = lib.il_poller_configure(self._poller, to_ms(t_s), sz)
        raise_err(r)
Пример #10
0
    def ch_configure(self, ch, reg):
        """Configure a channel mapping.

        Args:
            ch (int): Channel.
            reg (str, Register): Register to be mapped to the channel.

        """
        _reg, _id = _get_reg_id(reg)
        r = lib.il_monitor_ch_configure(self._monitor, ch, _reg, _id)
        raise_err(r)
Пример #11
0
    def configure(self, t_s, delay_samples=0, max_samples=0):
        """Configure the monitor parameters.

        Args:
            t_s (int, float): Sampling period (s, resolution: 1e-4 s).
            delay_samples (int, optional): Delay samples.
            max_samples (int, optional): Maximum acquisition samples.

        """
        r = lib.il_monitor_configure(self._monitor, int(t_s * 1e6),
                                     delay_samples, max_samples)
        raise_err(r)
Пример #12
0
    def ch_disable_all(self):
        """Disable all channels.

        Returns:
            int: Status code.

        """
        for channel in range(self.num_channels):
            r = self.ch_disable(channel)
            if r < 0:
                raise_err(r)
        return 0
Пример #13
0
    def labels(self, category_id):
        """Obtain labels for a certain category ID.

        Returns:
            dict: Labels dictionary.

        """
        labels_p = ffi.new('il_dict_labels_t **')
        r = lib.il_dict_cat_get(self.__ipb_dictionary._cffi_dictionary,
                                cstr(category_id), labels_p)
        raise_err(r)

        return LabelsDictionary._from_labels(labels_p[0])
Пример #14
0
    def labels(self, scat_id):
        """Obtain labels for a certain sub-category identifiers.

        Returns:
            dict: Labels dictionary.

        """
        labels_p = ffi.new('il_dict_labels_t **')
        r = lib.il_dict_scat_get(self._dict, cstr(self._cat_id), cstr(scat_id),
                                 labels_p)
        raise_err(r)

        return LabelsDictionary._from_labels(labels_p[0])
Пример #15
0
    def ch_configure(self, ch, reg):
        """Configure a poller channel mapping.

        Args:
            ch (int): Channel to be configured.
            reg (Register): Register to associate to the given channel.

        Raises:
            TypeError: If the register is not valid.

        """
        _reg, _id = _get_reg_id(reg)
        r = lib.il_poller_ch_configure(self._poller, ch, _reg, _id)
        raise_err(r)
Пример #16
0
    def start(self):
        """Start the poller."""

        if self.__running:
            logger.warning("Poller already running")
            raise_err(IL_EALREADY)

        # Activate timer
        self.__timer = PollerTimer(self.__refresh_time,
                                   self._acquire_callback_poller_data)
        self.__timer.start()
        self.__time_start = datetime.now()

        self.__running = True

        return 0
Пример #17
0
 def start(self):
     """Start the monitor."""
     r = lib.il_monitor_start(self._monitor)
     raise_err(r)
Пример #18
0
 def ch_disable_all(self):
     """Disable all channels."""
     r = lib.il_poller_ch_disable_all(self._poller)
     raise_err(r)
Пример #19
0
 def stop(self):
     """Stop the monitor."""
     r = lib.il_monitor_stop(self._monitor)
     raise_err(r)
Пример #20
0
 def ch_disable_all(self):
     """Disable all channels."""
     r = lib.il_monitor_ch_disable_all(self._monitor)
     raise_err(r)
Пример #21
0
 def start(self):
     """Start poller."""
     r = lib.il_poller_start(self._poller)
     raise_err(r)