def prepare_modulation_buffer(self, total_samples: int, show_error=True) -> np.ndarray: memory_size_for_buffer = total_samples * 8 logger.debug("Allocating {0:.2f}MB for modulated samples".format(memory_size_for_buffer / (1024 ** 2))) try: return np.zeros(total_samples, dtype=np.complex64) except MemoryError: if show_error: Errors.not_enough_ram_for_sending_precache(memory_size_for_buffer) return None
def prepare_modulation_buffer(self, total_samples: int, show_error=True) -> np.ndarray: memory_size_for_buffer = total_samples * 8 logger.debug("Allocating {0:.2f}MB for modulated samples".format(memory_size_for_buffer / (1024 ** 2))) try: return np.zeros(total_samples, dtype=np.complex64) except MemoryError: if show_error: Errors.not_enough_ram_for_sending_precache(memory_size_for_buffer) return None
def prepare_modulation_buffer(self, total_samples: int, show_error=True) -> np.ndarray: memory_size_for_buffer = total_samples * 8 logger.debug("Allocating {0:.2f}MB for modulated samples".format(memory_size_for_buffer / (1024 ** 2))) try: # allocate it three times as we need the same amount for the sending process np.zeros(3*total_samples, dtype=np.complex64) except MemoryError: # will go into continuous mode in this case if show_error: Errors.not_enough_ram_for_sending_precache(3*memory_size_for_buffer) return None return np.zeros(total_samples, dtype=np.complex64)
def on_btn_send_clicked(self): try: total_samples = self.total_modulated_samples buffer = self.prepare_modulation_buffer(total_samples) if buffer is not None: modulated_data = self.modulate_data(buffer) else: # Enter continuous mode modulated_data = None try: if modulated_data is not None: try: dialog = SendDialog( self.project_manager, modulated_data=modulated_data, modulation_msg_indices=self.modulation_msg_indices, parent=self) except MemoryError: # Not enough memory for device buffer so we need to create a continuous send dialog del modulated_data Errors.not_enough_ram_for_sending_precache(None) dialog = ContinuousSendDialog( self.project_manager, self.table_model.protocol.messages, self.modulators, total_samples, parent=self) else: dialog = ContinuousSendDialog( self.project_manager, self.table_model.protocol.messages, self.modulators, total_samples, parent=self) except OSError as e: logger.exception(e) return if dialog.has_empty_device_list: Errors.no_device() dialog.close() return dialog.device_parameters_changed.connect( self.project_manager.set_device_parameters) dialog.show() dialog.graphics_view.show_full_scene(reinitialize=True) except Exception as e: Errors.generic_error(self.tr("Failed to generate data"), str(e), traceback.format_exc()) self.unsetCursor()
def prepare_modulation_buffer(self, total_samples: int, show_error=True) -> IQArray: dtype = Modulator.get_dtype() n = 2 if dtype == np.int8 else 4 if dtype == np.int16 else 8 memory_size_for_buffer = total_samples * n logger.debug("Allocating {0:.2f}MB for modulated samples".format(memory_size_for_buffer / (1024 ** 2))) try: # allocate it three times as we need the same amount for the sending process IQArray(None, dtype=dtype, n=3*total_samples) except MemoryError: # will go into continuous mode in this case if show_error: Errors.not_enough_ram_for_sending_precache(3*memory_size_for_buffer) return None return IQArray(None, dtype=dtype, n=total_samples)
def prepare_modulation_buffer(self, total_samples: int, show_error=True) -> np.ndarray: memory_size_for_buffer = total_samples * 8 logger.debug("Allocating {0:.2f}MB for modulated samples".format( memory_size_for_buffer / (1024**2))) try: # allocate it three times as we need the same amount for the sending process np.zeros(3 * total_samples, dtype=np.complex64) except MemoryError: # will go into continuous mode in this case if show_error: Errors.not_enough_ram_for_sending_precache( 3 * memory_size_for_buffer) return None return np.zeros(total_samples, dtype=np.complex64)
def on_btn_send_clicked(self): try: total_samples = self.total_modulated_samples buffer = self.prepare_modulation_buffer(total_samples) if buffer is not None: modulated_data = self.modulate_data(buffer) else: # Enter continuous mode modulated_data = None try: if modulated_data is not None: try: dialog = SendDialog(self.project_manager, modulated_data=modulated_data, modulation_msg_indices=self.modulation_msg_indices, parent=self) except MemoryError: # Not enough memory for device buffer so we need to create a continuous send dialog del modulated_data Errors.not_enough_ram_for_sending_precache(None) dialog = ContinuousSendDialog(self.project_manager, self.table_model.protocol.messages, self.modulators, total_samples, parent=self) else: dialog = ContinuousSendDialog(self.project_manager, self.table_model.protocol.messages, self.modulators, total_samples, parent=self) except OSError as e: logger.exception(e) return if dialog.has_empty_device_list: Errors.no_device() dialog.close() return dialog.device_parameters_changed.connect(self.project_manager.set_device_parameters) dialog.show() dialog.graphics_view.show_full_scene(reinitialize=True) except Exception as e: Errors.generic_error(self.tr("Failed to generate data"), str(e), traceback.format_exc()) self.unsetCursor()