def _get_next(self):
        if self._measure_on_call:
            self._write_reg("main_control", "clear_status")

        poll_t = time()

        while True:
            status = self._read_reg("status")

            if status & regmap.STATUS_MASKS.ERROR_MASK:
                raise ClientError("server error: " + str(status).split(".")[1])
            elif status & regmap.STATUS_FLAGS.DATA_READY:
                break
            else:
                if (time() - poll_t) > self._poll_timeout:
                    raise ClientError("gave up polling")

                continue

        buffer = self._read_buf_raw()

        info = {}
        info_regs = regmap.get_data_info_regs(self._config.mode)
        for reg in info_regs:
            k = reg.stripped_name
            k = regmap.STRIPPED_NAME_TO_INFO_REMAP.get(k, k)

            if k is None:
                continue

            info[k] = self._read_reg(reg)

        if not self._measure_on_call:
            self._write_reg("main_control", "clear_status")

        sweeps_per_frame = getattr(self._config, "sweeps_per_frame", None)
        data = protocol.decode_output_buffer(buffer, self._mode,
                                             sweeps_per_frame)

        if self.squeeze:
            return info, data
        else:
            return [info], np.expand_dims(data, 0)
Exemple #2
0
    def get_next(self):
        poll_t = time()

        while True:
            status = self.read_reg("status", do_log=False)

            if status & regmap.STATUS_MASKS.ERROR_MASK:
                raise ClientError("server error: " + str(status).split(".")[1])
            elif status & regmap.STATUS_FLAGS.DATA_READY:
                break
            else:
                if (time() - poll_t) > self.poll_timeout:
                    raise ClientError("gave up polling")

                continue

        buffer_size = self.fixed_buf_size or self.read_reg(
            "output_buffer_length")
        if buffer_size > 0:
            buffer = self.read_buf_raw(protocol.MAIN_BUFFER_ADDR, buffer_size)
        else:
            buffer = bytearray()

        info = {}
        info_regs = regmap.get_data_info_regs(self.mode)
        for reg in info_regs:
            k = reg.stripped_name
            k = regmap.STRIPPED_NAME_TO_INFO_REMAP.get(k, k)

            if k is None:
                continue

            info[k] = self.read_reg(reg, do_log=False)

        self.write_reg("main_control", "clear_status", do_log=False)

        return info, buffer