diff --git a/ldk/drivers/base.py b/ldk/drivers/base.py index 1944c61..bfa80f4 100644 --- a/ldk/drivers/base.py +++ b/ldk/drivers/base.py @@ -37,7 +37,6 @@ def reset(self): def reset_laser(self): @command('Laser') def reset(self): pass - reset(self) @command(classname='Laser') @@ -46,33 +45,32 @@ def start_laser(self): pass @command(classname='Laser') def stop_laser(self): pass - @command(classname='Laser') - def get_laser_current(self): - return (0.0001/21.) * self.client.recv_uint32() + @property + @command(classname='Laser', funcname='get_laser_current') + def laser_current(self): + self.__laser_current = (0.0001/21.) * self.client.recv_uint32() + return self.__laser_current - @command(classname='Laser') - def get_laser_power(self): - return self.client.recv_uint32() + @property + @command(classname='Laser', funcname='get_laser_power') + def laser_power(self): + self.__laser_power = self.client.recv_uint32() + return self.__laser_power @command(classname='Laser') def get_monitoring(self): return self.client.recv_tuple() - @command(classname='Laser') - def set_laser_current(self, current): + @laser_current.setter + @command(classname='Laser', funcname='set_laser_current') + def laser_current(self, current): """ current: The bias in mA """ pass - @command(classname='Common') - def get_bitstream_id(self): pass - - @command(classname='Common') - def set_led(self, value): pass - @command(classname='Common') def init(self): pass def twoint14_to_uint32(self, data): data1 = np.mod(np.floor(8192 * data[0, :]) + 8192,16384) + 8192 data2 = np.mod(np.floor(8192 * data[1, :]) + 8192,16384) + 8192 - return data1 + 65536 * data2 + return data1 + 65536 * data2 \ No newline at end of file diff --git a/ldk/drivers/base_simu.py b/ldk/drivers/base_simu.py deleted file mode 100644 index f50bc42..0000000 --- a/ldk/drivers/base_simu.py +++ /dev/null @@ -1,92 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -import numpy as np -from ..models import LaserModel -from ..signal import Sampling - - -class BaseSimu(object): - """ This class is used as a base class for `OscilloSimu` and `SpectrumSimu` - - args: - n (int): number of points in the waveform (ex: n = 8192) - - """ - - def __init__(self, n): - - self.max_current = 50 # mA - self.sampling = Sampling(n, 125e6) - self.opened = True - - self.dac = np.zeros((2, self.sampling.n)) # V - - self._laser_current = 0 - self._laser_enable = False - self._laser_power = 0 - - # Lase model - self.model = LaserModel(self.sampling) - - self._live_laser_current = np.zeros(self.sampling.n) # A - self._live_laser_power = np.zeros(self.sampling.n) # W - self._live_laser_frequency = np.zeros(self.sampling.n) # Hz - self.failed = False - - def update(self): - self.get_live_current() - self.get_live_laser_power() - self.get_live_laser_frequency() - self.get_live_mach_zehnder_power() - self._laser_power = np.mean(self._live_laser_power) - - def close(self): - self.opened = False - - def reset(self): - self.stop_laser() - self.set_laser_current(0) - - def stop_laser(self): - self._laser_enable = False - - def get_laser_current(self): - return self._laser_current - - def get_laser_power(self): - return self._laser_power - - def start_laser(self): - self._laser_enable = True - - def set_laser_current(self, current): - # Current in mA - self._laser_current = current / 1000 - - def set_dac(self, channels=[0,1]): - pass - - def get_bitstream_id(self): - return 42 - - def set_led(self, ip): - print('LED set to '+ip) - - def get_live_current(self): - self._live_laser_current = self.model.laser_current( - self._laser_enable, - self._laser_current, - self.dac[1, :]) - - def get_live_laser_frequency(self): - self._live_laser_frequency = self.model.laser_frequency( - self._live_laser_current) - - def get_live_laser_power(self): - self._live_laser_power = self.model.laser_power( - self._live_laser_current) - - def get_live_mach_zehnder_power(self): - self._live_mach_zehnder_power = self.model.mach_zehnder_power( - self._live_laser_frequency, self._live_laser_power) diff --git a/ldk/drivers/oscillo.py b/ldk/drivers/oscillo.py index 866fcb9..29f4035 100644 --- a/ldk/drivers/oscillo.py +++ b/ldk/drivers/oscillo.py @@ -16,31 +16,66 @@ def __init__(self, client, verbose=False): self.wfm_size = 8192 super(Oscillo, self).__init__(self.wfm_size, client) - self.avg_on = False + self.__period = self.wfm_size + self.__averaging = False - self.period = self.wfm_size self.adc = np.zeros((2, self.wfm_size)) self.spectrum = np.zeros((2, self.wfm_size / 2)) self.avg_spectrum = np.zeros((2, self.wfm_size / 2)) - @command() - def set_dac_periods(self, period0, period1): - """ Select the periods played on each address generator - ex: self.set_dac_periods(8192, 4096) - """ + @property + def period(self): + return self.__period + + @period.setter + @command(classname='Oscillo', funcname='set_avg_period') + def period(self, avg_period): + """ Set the period of the averaging module and reset the module. """ + self.__period = avg_period pass - @command() - def set_n_avg_min(self, n_avg_min): + @property + def dac_periods(self): + return self.__dac_periods + + @dac_periods.setter + @command(classname='Oscillo', funcname='set_dac_periods') + def dac_periods(self, dac_periods): + """ Select the periods played on each address generator """ + self.__dac_periods = dac_periods + pass + + @property + def n_avg(self, channel): + """ Get the number of averages corresponding to the last acquisition """ + @command(classname='Oscillo') + def get_num_average(self, channel): + return self.client.recv_uint32() + self.__n_avg = get_num_average(self, 0) + return self.__n_avg + + @n_avg.setter + @command(classname='Oscillo', funcname='set_n_avg_min') + def n_avg(self, n_avg_min): """ Set the minimum of averages that will be computed on the FPGA The effective number of averages is >= n_avg_min. """ pass + @property + def averaging(self): + return self.__averaging + + @averaging.setter + @command(classname='Oscillo', funcname='set_averaging') + def averaging(self, avg_status): + """ True enables averaging """ + self.__averaging = avg_status + + @command() def set_avg_period(self, avg_period): - """ Set the period of the averaging module and reset the module. - """ + """ Set the period of the averaging module and reset the module. """ self.period = avg_period pass @@ -56,17 +91,6 @@ def set_dac_buffer(self, channel, arr): data = np.uint32(np.mod(np.floor(8192 * self.dac[channel,:]) + 8192, 16384) + 8192) set_dac_buffer(self, channel, data[::2] + data[1::2] * 65536) - @command() - def set_averaging(self, avg_status): - """ self.set_averaging(True) enables averaging. """ - pass - - @command() - def get_num_average(self, channel): - """ Get the number of averages corresponding to the last acquisition. """ - n_avg = self.client.recv_uint32() - return n_avg - @command() def read_all_channels(self): return self.client.recv_array(2 * self.wfm_size, dtype='float32') @@ -105,13 +129,15 @@ def always_update(self): """ pass - @command() - def get_counter(self): + @property + @command(classname='Oscillo', funcname='get_counter') + def counter(self): """ Return a 64 bits integer that counts the number of clock cycles (8 ns) between the startup of the FPGA and the last trigger (beginning of the last acquisition). """ - return self.client.recv_int(8, fmt='Q') + self.__counter = self.client.recv(fmt='Q') + return self.__counter @command() def reset_acquisition(self): diff --git a/ldk/drivers/spectrum.py b/ldk/drivers/spectrum.py index d91a8a6..c92d2d3 100644 --- a/ldk/drivers/spectrum.py +++ b/ldk/drivers/spectrum.py @@ -155,7 +155,7 @@ def store_peak_fifo_data(self): @command(classname='Spectrum') def get_peak_fifo_data(self): - return self.client.recv_buffer(self.peak_stream_length, data_type='uint32') + return self.client.recv_array(self.peak_stream_length, dtype='uint32') return get_peak_fifo_data(self) diff --git a/ldk/gui/base_widget.py b/ldk/gui/base_widget.py index 28cdfe4..d30fce6 100644 --- a/ldk/gui/base_widget.py +++ b/ldk/gui/base_widget.py @@ -35,7 +35,7 @@ def __init__(self, driver, parent): # Initialize driver self.driver.set_dac() - self.power_offset = self.driver.get_laser_power() + self.power_offset = self.driver.laser_power # Layout self.init_layout() diff --git a/ldk/gui/connect_widget.py b/ldk/gui/connect_widget.py index 18fe4a2..d451ebd 100644 --- a/ldk/gui/connect_widget.py +++ b/ldk/gui/connect_widget.py @@ -7,7 +7,7 @@ import json import os import requests -from koheron import KoheronClient, load_instrument +from koheron import KoheronClient, connect class ConnectWidget(QtGui.QWidget): def __init__(self, parent, ip_path=None): @@ -99,8 +99,8 @@ def ip_changed(self, index): self.lines[index+1].setFocus() self.lines[index+1].selectAll() - def load_instrument(self, instrument_name): - self.client = load_instrument(self.host, instrument_name) + def koheron_connect(self, instrument_name): + self.client = connect(self.host, instrument_name) def disconnect(self): self.is_connected = False @@ -124,7 +124,7 @@ def connect(self): # Load the first instrument available by default instrument_name = (next(instr for instr in self.parent.instrument_list if instr)) - self.load_instrument(instrument_name) + self.koheron_connect(instrument_name) self.connection_info.setText('Connected to ' + self.host) self.is_connected = True diff --git a/ldk/gui/laser_widget.py b/ldk/gui/laser_widget.py index 7a078bf..8487b7c 100644 --- a/ldk/gui/laser_widget.py +++ b/ldk/gui/laser_widget.py @@ -16,8 +16,8 @@ def __init__(self, driver, laser_on=False, laser_current=0): self.laser_on = laser_on self.laser_current = laser_current - self.driver.set_laser_current(self.laser_current * - self.laser_on) + self.driver.laser_current = self.laser_current * self.laser_on + # Layout self.layout = QtGui.QHBoxLayout() # Laser ON/OFF button @@ -49,7 +49,7 @@ def stop_laser(self): def change_current(self, value): self.laser_current = value - self.driver.set_laser_current(self.laser_current) + self.driver.laser_current = self.laser_current def save_as_h5(self, f): laser_grp = f.create_group('laser') diff --git a/ldk/gui/math_widget.py b/ldk/gui/math_widget.py index 4ea1a16..5fd2c27 100644 --- a/ldk/gui/math_widget.py +++ b/ldk/gui/math_widget.py @@ -80,14 +80,13 @@ def __init__(self, driver, plot_widget): self.connect(self.n_avg_min_slider, SIGNAL("value(float)"), self.change_n_avg_min) def change_averaging(self): - self.driver.avg_on = not self.driver.avg_on - if self.driver.avg_on: + self.driver.averaging = not self.driver.averaging + if self.driver.averaging: self.avg_on_button.setStyleSheet('QPushButton {color: red;}') self.avg_on_button.setText('Stop averaging') else: self.avg_on_button.setStyleSheet('QPushButton {color: green;}') self.avg_on_button.setText('Start averaging') - self.driver.set_averaging(self.driver.avg_on) def fourier_connect(self, state): if state == QtCore.Qt.Checked: @@ -111,7 +110,7 @@ def avg_connect(self): self.n_avg_spectrum = self.avg_spin.value() def change_n_avg_min(self, value): - self.driver.set_n_avg_min(int(value)) + self.driver.n_avg = int(value) def save_as_h5(self, f): math_grp = f.create_group('math') diff --git a/ldk/gui/monitor_widget.py b/ldk/gui/monitor_widget.py index 8c6524f..d29f11e 100644 --- a/ldk/gui/monitor_widget.py +++ b/ldk/gui/monitor_widget.py @@ -11,8 +11,8 @@ def __init__(self, driver, laser_widget): self.driver = driver self.laser_widget = laser_widget - self.laser_current = self.driver.get_laser_current() - self.laser_power = self.driver.get_laser_power() + self.laser_current = self.driver.laser_current + self.laser_power = self.driver.laser_power # Layout self.layout = QtGui.QGridLayout() @@ -24,16 +24,14 @@ def __init__(self, driver, laser_widget): # Frame rate self.frame_rate_label = QtGui.QLabel() - self.frame_rate_label.setText('Frame rate (Hz) : '+"{:.1f}".format(0)) + self.frame_rate_label.setText('Frame rate (Hz) : {:.1f}'.format(0)) # Laser power self.laser_power_label = QtGui.QLabel() - self.laser_power_label.setText('Laser power (u.a.) : '+ - "{:.2f}".format(self.driver.get_laser_power())) + self.laser_power_label.setText('Laser power (u.a.) : {:.2f}'.format(self.driver.laser_power)) # Laser current measured from the XADC self.laser_current_label = QtGui.QLabel() - self.laser_current_label.setText('Measured current (mA) : '+ - "{:.2f}".format(0.01 * self.driver.get_laser_current())) + self.laser_current_label.setText('Measured current (mA) : {:.2f}'.format(0.01 * self.driver.laser_current)) self.layout.addWidget(self.close_button, 0, 0) self.layout.addWidget(self.frame_rate_label, 0, 1) @@ -45,15 +43,12 @@ def __init__(self, driver, laser_widget): def update(self, frame_rate = 0): self.frame_rate = frame_rate - self.laser_current = 0.95 * self.laser_current + 0.05 * self.driver.get_laser_current() - self.laser_power = 0.95 * self.laser_power + 0.05 * self.driver.get_laser_power() + self.laser_current = 0.95 * self.laser_current + 0.05 * self.driver.laser_current + self.laser_power = 0.95 * self.laser_power + 0.05 * self.driver.laser_power - self.laser_current_label.setText('Measured current (mA): '+ - "{:.2f}".format(1000 * self.laser_current)) - self.laser_power_label.setText('Laser power (a. u.): '+ - "{:.2f}".format(self.laser_power)) - self.frame_rate_label.setText('Frame rate (Hz): '+ - "{:.2f}".format(self.frame_rate)) + self.laser_current_label.setText('Measured current (mA): {:.2f}'.format(1000 * self.laser_current)) + self.laser_power_label.setText('Laser power (a. u.): {:.2f}'.format(self.laser_power)) + self.frame_rate_label.setText('Frame rate (Hz): {:.2f}'.format(self.frame_rate)) def close_session(self): try: diff --git a/ldk/gui/select_channel_widget.py b/ldk/gui/select_channel_widget.py index 40db3ad..da3d8bb 100644 --- a/ldk/gui/select_channel_widget.py +++ b/ldk/gui/select_channel_widget.py @@ -30,12 +30,10 @@ def add_checkbox(self, checkbox, y_pos, text, check_state=QtCore.Qt.Unchecked): def show_adc(self, index): self.plot_widget.show_adc[index] = self.adc_checkbox[index].isChecked() self.plot_widget.dataItem[index].setVisible(self.plot_widget.show_adc[index]) - self.plot_widget.enableAutoRange() def show_dac(self, index): self.plot_widget.show_dac[index] = self.dac_checkbox[index].isChecked() self.plot_widget.dataItem[2+index].setVisible(self.plot_widget.show_dac[index]) - self.plot_widget.enableAutoRange() def uncheck_all(self): for i in range(2): diff --git a/ldk/gui/welcome_widget.py b/ldk/gui/welcome_widget.py index 9973452..416745b 100644 --- a/ldk/gui/welcome_widget.py +++ b/ldk/gui/welcome_widget.py @@ -94,7 +94,7 @@ def app_onclick(self, app_idx): instrument = self.instrument_list[app_idx] if instrument != '': QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) - self.connect_widget.load_instrument(instrument) + self.connect_widget.koheron_connect(instrument) driver = globals()[app.capitalize()](self.connect_widget.client) driver.init() QApplication.restoreOverrideCursor()