def app_onclick(self, app_idx): app = self.app_list[app_idx] instrument = self.instrument_list[app_idx] if instrument != '': QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor)) self.connect_widget.client = connect(self.connect_widget.host, name=instrument) driver = globals()[app.capitalize()](self.connect_widget.client) driver.init() QtGui.QApplication.restoreOverrideCursor() index = self.parent.stacked_widget.addWidget(globals()[app.capitalize()+'Widget'](driver, self.parent)) self.parent.stacked_widget.setCurrentIndex(index)
def __init__(self): self.state = 'idle' # filling, exhaust, pumping out, shot, manual control self.targetPressure = None self.pumpoutRefill = False self.gotFirstQueue = False logging.basicConfig(filename=LOG_FILE, format='%(message)s', level=logging.DEBUG) # Arrays to store a 10x downsampled version of the pressure readings self.downsamplingQueue = None self.pressuresDownsampled = [] # Queue of (time to execute, function, args) objects like threading.Timer does. We want to # avoid threading for Koheron interactions because of potential bugs self.taskQueue = [] # Queue of strings to send to GUI for logging self.messageQueue = [] # Used for pump/fill logic and shot data self.pressureTimes = [] self.absPressures = [] self.diffPressures = [] self.pressures = None # Keep track of server health self.mainloopTimes = [] # Variables to record times to return appropriate data to GUI post-puff self.lastT1 = None self.lastTdone = None # Variable used to store time and pressure data from the latest shot self.lastShotData = None # Create new xmlrpc server and register RPServer with it to expose RPServer functions address = ('0.0.0.0', 50000) self.RPCServer = xmlrpc.server.SimpleXMLRPCServer(address, allow_none=True, logRequests=False) self.RPCServer.register_instance(self) # This timeout is how long handle_request() blocks the main thread even when there are no requests self.RPCServer.timeout = .001 rpConnection = koheron.connect(RP_HOSTNAME, name='GPI_RP') self.RPKoheron = GPI_RP(rpConnection) self.addToLog('Server setting default state') self.setDefault() if ANNOUNCE_HEALTH: self.addTask(10, self.announceServerHealth, []) self.mainloop()
def connect(self): QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor)) self.connection_info.setText('Connecting to ' + self.host + ' ...') self.local_instruments = requests.get('http://{}/api/instruments/local'.format(self.host)).json() for i, app in enumerate(self.app_list): try: instrument = next(instr for instr in self.local_instruments if app in instr) self.parent.instrument_list[i] = instrument except StopIteration: self.parent.instrument_list[i] = '' # Load the first instrument available by default instrument_name = (next(instr for instr in self.parent.instrument_list if instr)) self.client = connect(self.host, name=instrument_name) self.connection_info.setText('Connected to ' + self.host) self.is_connected = True self.connect_button.setStyleSheet('QPushButton {color: red;}') self.connect_button.setText('Disconnect') self.parent.update_buttons() QtGui.QApplication.restoreOverrideCursor()
def speed_test(host, n_pts=1000): time_array = np.zeros(n_pts) client = connect(host, name='oscillo') driver = Oscillo(client) driver.set_average(False) t0 = time.time() t_prev = t0 for i in range(n_pts): if cmd == 'get_decimated_data': driver.get_decimated_data(decimation_factor, index_low, index_high) elif cmd == 'get_num_average': driver.get_num_average(0) t = time.time() time_array[i] = t - t_prev print host, i, time_array[i] t_prev = t print '{} us'.format(1E6 * np.median(time_array)) # assert(np.median(time_array) < 0.003) return time_array
def speed_test(host, n_pts=1000): time_array = np.zeros(n_pts) client = connect(host, name="oscillo") driver = Oscillo(client) driver.set_averaging(False) t0 = time.time() t_prev = t0 for i in range(n_pts): if cmd == "get_adc": driver.get_adc() elif cmd == "get_num_average": driver.get_num_average(0) t = time.time() time_array[i] = t - t_prev print host, i, time_array[i] t_prev = t print "{} us".format(1e6 * np.median(time_array)) # assert(np.median(time_array) < 0.003) return time_array
def getPressureData(self): now = time.time() delta = 1 / PRESSURE_HZ newData = None try: # Get data from RP # This may raise an exception due to network timeout combined_pressure_history = self.RPKoheron.get_GPI_data() # Show warning if the RP data queue is full, which means some data has been lost if len(combined_pressure_history) == 50000: # Show this message except during program startup, when the FPGA queue is normally full if self.gotFirstQueue: self.addToLog('Lost some data due to network lag') else: self.gotFirstQueue = True # Add fast readings pAbs = abs_mbar(combined_pressure_history) pDiff = diff_mbar(combined_pressure_history) pNewTimes = np.arange(-len(pAbs) + 1, 1) * delta + now newData = np.column_stack((pNewTimes, pAbs, pDiff)) if self.pressures is None: self.pressures = newData else: self.pressures = np.vstack((self.pressures, newData)) pTimes = np.arange(-len(self.pressures) + 1, 1) * delta + now self.pressures[:, 0] = pTimes except Exception as e: # Log disconnection and attempt to reconnect self.addToLog(str(e)) self.addToLog( 'Get pressure data failed. Attempting to reconnect to RP...') rpConnection = koheron.connect(RP_HOSTNAME, name='GPI_RP') self.RPKoheron = GPI_RP(rpConnection) if newData is not None: self.downsamplePressureData(now, newData) self.prunePressureData(now)
#!/usr/bin/env python # -*- coding: utf-8 -*- import numpy as np import os import time from adc_bram import AdcBram from koheron import connect import matplotlib matplotlib.use('TKAgg') from matplotlib import pyplot as plt from matplotlib.lines import Line2D host = os.getenv('HOST', '192.168.1.50') client = connect(host, 'adc-bram', restart=False) driver = AdcBram(client) print('ADC size = {}'.format(driver.adc_size)) driver.set_reference_clock(0) # External time.sleep(5) clk_200MHz = {'idx': 0, 'fs': 200E6} clk_250MHz = {'idx': 1, 'fs': 250E6} clock = clk_250MHz driver.set_sampling_frequency(clock['idx']) # driver.phase_shift(0) t = np.arange(driver.adc_size) / clock['fs']
# -*- coding: utf-8 -*- import init_example import os import time import numpy as np import matplotlib.pyplot as plt import csv import time from scipy import signal from koheron import connect from ldk.drivers import Oscillo host = os.getenv('HOST','192.168.1.100') client = connect(host, name='oscillo') driver = Oscillo(client) current = 30 #mA freq = 1 mod_amp = 0.2 # Modulate with a triangle waveform of period 8192 x 8 ns n = driver.wfm_size driver.dac[1,:] = mod_amp * signal.sawtooth(2 * np.pi * freq / n * np.arange(n), width=0.5) driver.set_dac() driver.start_laser() driver.set_averaging(True) driver.set_laser_current(current) time.sleep(0.1)
root = dirname(dirname(dirname(realpath(__file__)))) sys.path.insert(0, root + "/instruments") sys.path.insert(0, root + "/python") import koheron from GPI_RP.GPI_RP import GPI_RP import time import numpy import subprocess import signal serverd = root + '/tmp/instruments/GPI_RP/serverd' p = subprocess.Popen(serverd) print(serverd) time.sleep(.1) c = koheron.connect('localhost', name='GPI_RP') rp = GPI_RP(c) times = [] start = time.time() try: while True: time.sleep(time.time() - start + .1) start = time.time() data = rp.get_GPI_data() print(hex(data[0]) if data.size else [], len(data)) finally: p.terminate() p.wait()
def stop_dma(self): pass @command() def get_adc_data(self): return self.client.recv_array(self.n / 2, dtype='uint32') def get_adc(self): data = self.get_adc_data() self.adc[::2] = (np.int32(data % 65536) - 32768) % 65536 - 32768 self.adc[1::2] = (np.int32(data >> 16) - 32768) % 65536 - 32768 if __name__ == "__main__": host = os.getenv('HOST', '192.168.1.16') client = connect(host, name='adc-dac-dma') driver = AdcDacDma(client) adc_channel = 0 driver.select_adc_channel(adc_channel) fs = 250e6 fmin = 1e3 # Hz fmax = 1e6 # Hz t = np.arange(driver.n) / fs chirp = (fmax - fmin) / (t[-1] - t[0]) print("Set DAC waveform (chirp between {} and {} MHz)".format( 1e-6 * fmin, 1e-6 * fmax)) driver.dac = 0.9 * np.cos(2 * np.pi * (fmin + chirp * t) * t)
import init_example import os import time import numpy as np import matplotlib matplotlib.use("GTKAgg") from matplotlib import pyplot as plt from koheron import connect from ldk.drivers import Spectrum # Load the spectrum instrument host = os.getenv("HOST", "192.168.1.100") client = connect(host, name="spectrum") driver = Spectrum(client) # Enable laser driver.start_laser() # Set laser current current = 30 # mA driver.set_laser_current(current) # Plot parameters fig = plt.figure() ax = fig.add_subplot(111) x = 1e-6 * np.fft.fftshift(driver.sampling.f_fft) y = 10 * np.log10(np.fft.fftshift(driver.spectrum)) li, = ax.plot(x, y)
import os from koheron import connect from test_memory import TestMemory host = os.getenv('HOST','192.168.1.100') instrument = os.getenv('NAME','') client = connect(host, name=instrument) test_memory = TestMemory(client) def test_write_read_u32(): assert(test_memory.write_read_u32()) def test_write_read_reg_u32(): assert(test_memory.write_read_reg_u32(0)) def test_write_read_u64(): assert(test_memory.write_read_u64()) def test_write_read_reg_u64(): assert(test_memory.write_read_reg_u64(0)) def test_write_read_i16(): assert(test_memory.write_read_i16()) def test_write_read_reg_i16(): assert(test_memory.write_read_reg_i16(0)) def test_write_read_float(): assert(test_memory.write_read_float())
#!/usr/bin/env python # -*- coding: utf-8 -*- import numpy as np import matplotlib matplotlib.use("GTKAgg") from matplotlib import pyplot as plt import os import time from pulse import Pulse from koheron import connect host = os.getenv("HOST", "192.168.1.7") client = connect(host, name="pulse_generator") driver = Pulse(client) pulse_width = 128 n_pulse = 64 pulse_frequency = 1000 pulse_period = np.uint32(driver.fs / pulse_frequency) # Send Gaussian pulses to DACs t = np.arange(driver.n_pts) / driver.fs # time grid (s) driver.dac[0, :] = 0.6 * np.exp(-(t - 500e-9) ** 2 / (150e-9) ** 2) driver.dac[1, :] = 0.6 * np.exp(-(t - 500e-9) ** 2 / (150e-9) ** 2) driver.set_dac() driver.set_pulse_generator(pulse_width, pulse_period)
#!/usr/bin/env python # -*- coding: utf-8 -*- import numpy as np import matplotlib matplotlib.use('TKAgg') from matplotlib import pyplot as plt import os import time from pulse import Pulse from koheron import connect host = os.getenv('HOST', '192.168.1.7') client = connect(host, name='pulse-generator') driver = Pulse(client) pulse_width = 256 n_pulse = 64 pulse_frequency = 2000 pulse_period = np.uint32(driver.fs / pulse_frequency) # Send Gaussian pulses to DACs t = np.arange(driver.n_pts) / driver.fs # time grid (s) driver.dac[0,:] = 0.6 * np.exp(-(t - 500e-9)**2/(150e-9)**2) driver.dac[1,:] = 0.6 * np.exp(-(t - 500e-9)**2/(150e-9)**2) driver.set_dac() driver.set_pulse_width(pulse_width) driver.set_pulse_period(pulse_period)
#!/usr/bin/env python # -*- coding: utf-8 -*- from koheron import connect import os import time from led_blinker import LedBlinker host = os.getenv('HOST', '192.168.1.100') client = connect(host, name='led-blinker') driver = LedBlinker(client) print(driver.get_forty_two()) print('Start blinking...') for i in range(255): driver.set_leds(i) time.sleep(0.01)
import sys class LedBlinker(object): def __init__(self, client): self.client = client @command(classname='LedBlinker') def set_leds(self, led_value): pass @command(classname='LedBlinker') def get_leds(self, led_value): return self.client.recv_uint32() @command(classname='LedBlinker') def set_led(self, index, status): pass @command(classname='LedBlinker') def get_forty_two(self): return self.client.recv_uint32() if __name__ == "__main__": host = os.getenv('HOST', '10.211.3.133') client = connect(host, name='trenz_teb080x_te803_dma_example') driver = LedBlinker(client) print("Printing DNA: {}".format(driver.get_forty_two()))
def stop_dma(self): pass @command() def get_adc_data(self): return self.client.recv_array(self.n / 2, dtype='uint32') def get_adc(self): data = self.get_adc_data() self.adc[::2] = (np.int32(data % 65536) - 32768) % 65536 - 32768 self.adc[1::2] = (np.int32(data >> 16) - 32768) % 65536 - 32768 if __name__ == "__main__": host = os.getenv('HOST', '192.168.1.82') client = connect(host, name='mars_zx3_DMA') driver = DmaExample(client) print("Printing forty_two: {}".format(driver.get_forty_two())) print("Printing DNA: {}".format(driver.get_dna())) fs = 250e6 fmin = 1e3 # Hz fmax = 1e6 # Hz t = np.arange(driver.n) / fs chirp = (fmax - fmin) / (t[-1] - t[0]) print("Set DAC waveform (chirp between {} and {} MHz)".format( 1e-6 * fmin, 1e-6 * fmax)) driver.dac = 0.9 * np.cos(2 * np.pi * (fmin + chirp * t) * t)
# -*- coding: utf-8 -*- import os import time from koheron import command, connect class LedBlinker(object): def __init__(self, client): self.client = client @command() def set_leds(self, led_value): pass @command() def get_forty_two(self): return self.client.recv_uint32() if __name__ == "__main__": host = os.getenv('HOST', '192.168.1.100') client = connect(host, 'led-blinker') driver = LedBlinker(client) print(driver.get_forty_two()) print('Start blinking...') for i in range(255): driver.set_leds(i) time.sleep(0.01)
#!/usr/bin/env python # -*- coding: utf-8 -*- import numpy as np import os import time from PCS import PCS from koheron import connect host = os.getenv('HOST', 'rp4') client = connect(host, name='Template') driver = Template(client) driver.set_reg_1(500) driver.set_reg_2(2) driver.get_reg_1()
pass def get_adc0(self): data = self.get_s2mm0_data() self.adc0 = (np.int16(data & 0xFFFF)) #- 32768) % 65536 - 32768 self.adc1 = (np.int16((data >> 16) & 0xFFFF) ) #- 32768) % 65536 - 32768 @command(classname="DmaSG") def print_dma_log(self): pass if __name__ == "__main__": host = os.getenv('HOST', '192.168.1.90') client = connect(host, name='fmc104adc-dma-pcie') driver = TopLevel(client) print("Printing DNA: {}".format(driver.get_dna())) print("Printing forty_two: {}".format(driver.get_fortytwo())) print("Printing AdcClocks (MHz): {}".format(driver.get_adc_clocks() / 1000000.)) print("Printing PCIeGPIO: {}".format(driver.get_gpiopcie())) print("Printing ADC error: {}".format(driver.get_adc_error())) print("Printing ADC Valid: {}".format(driver.get_adc_valid())) print("Printing ADC raw: {}".format((driver.get_adc_raw_data()))) print("Printing FifoVacancy: {}".format((driver.fifo_vacancy_rx()))) driver.start_fifo_acquisition(True) time.sleep(2.4)
#!/usr/bin/env python # -*- coding: utf-8 -*- import os import time import numpy as np import matplotlib matplotlib.use('GTKAgg') from matplotlib import pyplot as plt from koheron import connect from drivers import Spectrum host = os.getenv('HOST','192.168.1.100') client = connect(host, name='spectrum') driver = Spectrum(client) fs = 125e6 # Hz fft_size = 4096 doppler_shift = 1.29e6 # Hz / (m/s) driver.set_address_range(1,fft_size/2) n = np.uint32(fs/fft_size) time = np.arange(n) / fs * fft_size time = time[::-1] velocity = np.zeros(n) fig = plt.figure()
return self.client.recv_string() @command() def get_json(self): return self.client.recv_json() @command() def get_tuple(self): return self.client.recv_tuple('Idd?') # Unit Tests host = os.getenv('HOST', '192.168.1.100') client = connect(host, name='test') tests = Tests(client) def test_get_server_version(): server_version = tests.get_server_version() server_version_ = server_version.split('.') client_version_ = __version__.split('.') assert client_version_[0] >= server_version_[0] assert client_version_[1] >= server_version_[1] def test_set_scalars(): assert tests.set_scalars(429496729, -2048, np.pi, True, np.exp(1), 42)
class Agilent33220A: def __init__(self, ip): import visa rm = visa.ResourceManager('@py') self.inst = rm.open_resource('TCPIP0::' + ip + '::INSTR') def set_sinus(self, freq, v_pp, offset): self.inst.write('APPL:SIN ' + str(freq / 1E3) + ' KHZ, ' + str(v_pp / 2) + ' VPP, ' + str(offset) + ' V\n') gene = Agilent33220A('192.168.1.22') host = os.getenv('HOST', '192.168.1.100') client = connect(host, 'decimator') driver = Decimator(client) n = 8192 fs = 125e6 ffft = np.fft.fftfreq(n) * fs / 512 fidx = np.arange(1, 4096, 1) freqs = ffft[fidx] print freqs gain = 0 * freqs window = 0.5 * (1 + np.cos(2 * np.pi * np.arange(n) / n)) for i, idx in enumerate(fidx):
@command(classname='SSFifoController') def get_vector_rx(self): return self.client.recv_array(2048, dtype='uint32', check_type=False) def get_adc0(self): data = self.get_adc0_data() self.adc0 = (np.int32(data % 65536) & 0x3FFF ) #- 32768) % 65536 - 32768 self.adc1 = (np.int32( (data >> 16)) & 0x3FFF) #- 32768) % 65536 - 32768 if __name__ == "__main__": host = os.getenv('HOST', '192.168.1.89') client = connect(host, name='adc-dma-triggered') driver = AdcDma(client) driver.start_fifo_acquisition(True) time.sleep(2.4) ret = driver.get_vector_rx() driver.stop_fifo_acquisition() ret0 = (np.int32(ret % 0x3FFF)) # % 65536) - 32768) % 65536 - 32768 ret1 = (np.int32((ret >> 16) & 0x3FFF)) # - 32768) % 65536 - 32768 adc0 = np.zeros(driver.n / 2) adc1 = np.zeros(driver.n / 2) adc_channel = 0 driver.fifo_reset_rx()
@command() def set_freq(self, freq): pass @command() def get_adc(self): return self.client.recv_tuple('ii') if __name__=="__main__": # Define the IP addresses of the 4 Red Pitayas hosts = ['192.168.1.14', '192.168.1.5', '192.168.1.13', '192.168.1.6'] clients = [] drivers = [] for i, host in enumerate(hosts): clients.append(connect(host, 'cluster', restart=False)) drivers.append(Cluster(clients[i])) for driver in drivers: driver.set_freq(10e6) driver.set_clk_source('crystal') driver.cfg_sata(1, 0) driver.set_pulse_generator(100, 200) for i in [1,2,3]: drivers[i].set_clk_source('sata') drivers[0].cfg_sata(1, 0) drivers[1].cfg_sata(0, 7) drivers[2].cfg_sata(0, 4) drivers[3].cfg_sata(0, 2)
#!/usr/bin/env python # -*- coding: utf-8 -*- import numpy as np import os import time from PCS import PCS from koheron import connect host = os.getenv('HOST', 'rp4') client = connect(host, name='plasma-current-response') driver = PCS(client) driver.set_Temperature(500) driver.set_ISat(2) driver.set_Vfloating(0) driver.set_Resistence(100) driver.set_Switch(1)
def __init__(self, client): self.client = client @command(classname="Dds") def set_dds_freq(self, channel, freq): pass @command(classname='Dma') def get_data(self): return self.client.recv_array(1000000, dtype='int32') host = os.getenv('HOST', '192.168.1.24') freq = 40e6 driver = PhaseNoiseAnalyzer(connect(host, 'phase-noise-analyzer')) driver.set_dds_freq(0, freq) n = 1000000 n = 1000000 fs = 125e6 cic_rate = 20 n_avg = 100 ffft = np.fft.fftfreq(n) * fs / (cic_rate * 2) y = np.ones(n) # Dynamic plot fig = plt.figure()
@command() def reset(self): pass @command() def set_input(self, value): pass @command() def get_output(self): return self.client.recv_uint32() host = os.getenv('HOST', '192.168.1.23') client = connect(host, name='picoblaze') driver = Picoblaze(client) code = """ input s0, 0 add s0, {:x} output s0, 0 """ for i in range(100): with open("test.psm", "w") as f: f.write(code.format(i)) # Compile test.psm with opbasm subprocess.call([
#!/usr/bin/env python # -*- coding: utf-8 -*- import os import time from koheron import command, connect class LedBlinker(object): def __init__(self, client): self.client = client @command() def set_led(self, led_value): pass @command() def get_forty_two(self): return self.client.recv_uint32() if __name__=="__main__": host = os.getenv('HOST','192.168.1.100') client = connect(host, name='led_blinker') driver = LedBlinker(client) print(driver.get_forty_two()) print('Start blinking...') for i in range(255): driver.set_led(i) time.sleep(0.01)
Program for making the RedPitaya / Koheron laser development work as a morsecode emitter. Code is scanned from the command line by the program, and transmitted as short and long laser-pulses. """ import os import time import numpy as np import matplotlib.pyplot as plt from koheron import connect from drivers import Oscillo from drivers import Laser # Enter board IP host = os.getenv('HOST','10.42.0.53') client = connect(host, name='oscillo') driver = Oscillo(client) laser = Laser(client) decimation_factor = 1 index_low = 0 index_high = 8191 # Making a method for text input. Only small letters, commas, and punctuation marks allowed. phrase = str(raw_input("Please type text to be translated, using only UTF-8 characters:")) phrase = list(phrase) #Arranges all the leters in a list. # Set laser current current = float(raw_input("Please enter laser current (0ma - 40ma):")) # mA
def stop_dma(self): pass @command() def get_adc_data(self): return self.client.recv_array(self.n / 2, dtype='uint32') def get_adc(self): data = self.get_adc_data() self.adc[::2] = (np.int32(data & 0xFFFF)) self.adc[1::2] = (np.int32(data >> 16) & 0xffff) if __name__ == "__main__": host = os.getenv('HOST', '192.168.1.114') client = connect(host, name='mars_logic_analyser') driver = DmaExample(client) print("Printing forty_two: {}".format(driver.get_forty_two())) print("Printing DNA: {}".format(driver.get_dna())) fs = 250e6 fmin = 1e3 # Hz fmax = 1e6 # Hz t = np.arange(driver.n) / fs chirp = (fmax - fmin) / (t[-1] - t[0]) print("Set DAC waveform (chirp between {} and {} MHz)".format( 1e-6 * fmin, 1e-6 * fmax)) driver.dac = 0.9 * np.cos(2 * np.pi * (fmin + chirp * t) * t)
print('get_goto_target{0}: {1}'.format(i, self.get_goto_target(i))) print('=========================') for j in range(0, 2): print('get_spped_ratio{0}-{1}: {2}'.format( i, j, self.get_speed_ratio(i, j))) print('get_motor_highspeedmode{0}-{1}: {2}'.format( i, j, self.get_motor_highspeedmode(i, j))) print('get_motor_mode{0}-{1}: {2}'.format( i, j, self.get_motor_mode(i, j))) print('get_motor_direction{0}-{1}: {2}'.format( i, j, self.get_motor_direction(i, j))) print('get_motor_period_usec{0}-{1}: {2}'.format( i, j, self.get_motor_period_usec(i, j))) print('get_motor_period_ticks{0}-{1}: {2}'.format( i, j, self.get_motor_period_ticks(i, j))) def apply_siderail(self, axis): SKYWATCHER_STELLAR_DAY = 86164.098903691 SKYWATCHER_STELLAR_SPEED = 15.041067179 if __name__ == '__main__': host = os.getenv('HOST', '192.168.1.122') client = connect(host, name='mars_star_tracker') driver = SkyTrackerInterface(client) driver.PrintAll() print('set_led_pwm{0} : {1}'.format(0, driver.set_led_pwm(20))) print('open_shutter{0} : {1}'.format(0, driver.open_shutter())) time.sleep(1) print('open_shutter{0} : {1}'.format(0, driver.close_shutter()))
type=int_or_str, help='input device (numeric ID or substring)') parser.add_argument('-r', '--samplerate', type=int, help='sampling rate') parser.add_argument('-c', '--channels', type=int, default=1, help='number of input channels') parser.add_argument('-t', '--subtype', type=str, help='sound file subtype (e.g. "PCM_24")') args = parser.parse_args(remaining) host = os.getenv('HOST', '127.0.0.1') client = connect(host, name='nicola4z', restart=True) driver = Nicola4Z(client) time.sleep(1) n = 32768 freq0 = 86950 ARRAY_SIZE = 1024 mic_boost = 5e9 driver.set_led(2 + 8 * 4) print(driver.set_dds_freq(freq0)) driver.reset_fifo() driver.reset_tx_fifo() driver.set_control(0) #1 for USB, 0 for LSB driver.set_TX_Mode() driver.set_data_fifo_in_val(1)
#!/usr/bin/env python # -*- coding: utf-8 -*- import os from koheron import command, connect class AdcDac(object): def __init__(self, client): self.client = client @command() def set_dac(self, dac_value, dac_channel): pass @command() def get_adc(self): return self.client.recv_tuple('ii') if __name__=="__main__": host = os.getenv('HOST','192.168.1.100') client = connect(host, name='adc_dac') driver = AdcDac(client) # driver.set_dac_0(0) # driver.set_dac_1(1000) adc1, adc2 = driver.get_adc() print('adc1 = {}, adc2 = {}'.format(adc1, adc2))
@command() def get_measured_power(self): return self.client.recv_float() @command() def get_measured_current(self): return self.client.recv_float() @command() def set_current(self, current): ''' Laser current in mA ''' pass @command(classname='Eeprom', funcname='write') def write_eeprom(self, address, value): pass @command(classname='Eeprom', funcname='read') def read_eeprom(self, address): return self.client.recv_uint32() if __name__=="__main__": host = os.getenv('HOST','192.168.1.100') client = connect(host, 'laser-controller') laser = Laser(client) laser.start() for i in range(40): laser.set_current(i) time.sleep(0.01) print(laser.get_measured_current(), laser.get_measured_power())
#!/usr/bin/env python # -*- coding: utf-8 -*- from koheron import connect from oscillo import Oscillo import os, time import numpy as np import matplotlib.pyplot as plt import allantools host = os.getenv('HOST', '192.168.1.18') client = connect(host, name='oscillo', restart=False) driver = Oscillo(client) driver.set_average(True) driver.set_num_average_min(0) driver.set_waveform_type(0, 1) driver.set_dac_amplitude(0, 0.8) driver.set_dac_frequency(0, 125e6 / 8192) driver.set_dac_offset(0, 0.0) data = driver.get_decimated_data(1, 0, 4096) n = 10000 t = np.arange(n) frequency = np.zeros(n) fig = plt.figure() ax = fig.add_subplot(111)
@command() def start(self): pass @command() def stop(self): pass @command() def get_power(self): return self.client.recv_uint32() @command() def get_current(self): return self.client.recv_uint32() @command() def set_current(self, current): ''' Laser current in mA ''' pass if __name__=="__main__": host = os.getenv('HOST','192.168.1.100') client = connect(host, 'laser_controller') laser = Laser(client) laser.start() for i in range(40): laser.set_current(i) print(laser.get_current, laser.get_power())
data = np.zeros((2, n)) for i in range(n): print i driver.phase_shift(1) driver.get_adc() data[0, i] = np.std(np.diff(driver.adc[0])) data[1, i] = np.std(np.diff(driver.adc[1])) plt.plot(data[0, :], label='ADC0') plt.plot(data[1, :], label='ADC1') plt.legend(loc='upper right') plt.title(config['name']) plt.show() if __name__ == "__main__": host = os.getenv('HOST', '192.168.1.16') client = connect(host, 'adc-dac-bram', restart=True) driver = AdcDacBram(client) print('DAC size = {}'.format(driver.dac_size)) print('ADC size = {}'.format(driver.adc_size)) set_dac_modulation() clk_200MHz = {'name': '200 MHz', 'idx': 0, 'fs': 200E6} clk_250MHz = {'name': '250 MHz', 'idx': 1, 'fs': 250E6} test_phase_shift(clk_200MHz) #test_phase_shift(clk_250MHz)
def stop_dma(self): pass @command() def get_adc_data(self): return self.client.recv_array(self.n / 2, dtype='uint32') def get_adc(self): data = self.get_adc_data() self.adc[::2] = (np.int32(data % 65536) - 32768) % 65536 - 32768 self.adc[1::2] = (np.int32(data >> 16) - 32768) % 65536 - 32768 if __name__ == "__main__": host = os.getenv('HOST', '192.168.1.90') client = connect(host, name='PE1_XZ1_7030_DMA') driver = DmaExample(client) print("Printing DNA: {}".format(driver.get_dna())) print("Printing forty_two: {}".format(driver.get_forty_two())) fs = 250e6 fmin = 1e3 # Hz fmax = 1e6 # Hz t = np.arange(driver.n) / fs chirp = (fmax - fmin) / (t[-1] - t[0]) print("Set DAC waveform (chirp between {} and {} MHz)".format( 1e-6 * fmin, 1e-6 * fmax)) driver.dac = 0.9 * np.tan(2 * np.pi * (fmin + chirp * t) * t)
# -*- coding: utf-8 -*- import os from koheron import command, connect class AdcDac(object): def __init__(self, client): self.client = client @command() def set_dac(self, dac0, dac1): pass @command() def get_adc(self): return self.client.recv_tuple('ii') if __name__=="__main__": host = os.getenv('HOST','192.168.1.100') client = connect(host, name='adc_dac') driver = AdcDac(client) driver.set_dac(0, 1000) adc1, adc2 = driver.get_adc() print('adc1 = {}, adc2 = {}'.format(adc1, adc2))
#!/usr/bin/env python # -*- coding: utf-8 -*- import numpy as np import os import time import matplotlib.pyplot as plt from fft import FFT from koheron import connect host = os.getenv('HOST', '192.168.1.11') client = connect(host, 'fft', restart=False) driver = FFT(client) print('Start test.py') n_pts = driver.n_pts fs = 250e6 psd = driver.read_psd() #plt.plot(10*np.log10(psd)) plt.plot(psd) plt.show() #freqs = np.array([0.01, 0.02, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.5, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 22, 25, 27, 30, 33, 35, 37, 40, 43, 45, 47, 50, 53, 55, 57, 60, 63, 65, 67, 70, 73, 75, 77, 80, 83, 85, 87, 90, 93, 95, 97, 100, 103, 105, 107, 110, 113, 115, 117, 120, 123, 124]) * 1e6 freqs = np.linspace(0.01e6, 40e6,num=200) freqs = np.round(freqs / fs * n_pts) * fs / n_pts
#!/usr/bin/env python # -*- coding: utf-8 -*- import numpy as np import matplotlib matplotlib.use('GTKAgg') from matplotlib import pyplot as plt import os import time from decimator import Decimator from koheron import connect host = os.getenv('HOST', '192.168.1.7') client = connect(host, 'decimator') driver = Decimator(client) n = 8192 # Dynamic plot fig = plt.figure() ax = fig.add_subplot(111) x = np.arange(n) y = np.zeros(n) li, = ax.plot(x, y) ax.set_ylim((-2**31, 2**31)) fig.canvas.draw() while True: try:
import context import os import numpy as np from koheron import connect from drivers.spectrum import Spectrum host = os.getenv('HOST','192.168.1.100') client = connect(host, name='spectrum') spectrum = Spectrum(client) spectrum.reset_acquisition() class TestsSpectrum: def test_set_dac(self): data_send = np.arange(spectrum.wfm_size, dtype='uint32') spectrum.set_dac(data_send, 1) data_read = spectrum.get_dac_buffer(1) data_tmp = np.uint32(np.mod(np.floor(8192 * data_send) + 8192, 16384) + 8192) data_read_expect = data_tmp[::2] + (data_tmp[1::2] << 16) assert np.array_equal(data_read, data_read_expect)