def test_monitorTCP_mock(): dev = RP_PLL.RP_PLL_device() # connect mocks monitor_tcp = MonitorTCP_mock() dev.send = monitor_tcp.send_mock dev.read = monitor_tcp.read_mock # actual test check_readreg(dev)
def setup_write(self, selector, Num_samples): # input validation: if not selector in self.LOGGER_MUX.values(): raise Exception('Invalid selector value') self.Num_samples_write = int( Num_samples ) # no such restriction with the Red Pitaya implementation self.Num_samples_read = self.Num_samples_write self.last_selector = selector if self.bIntroduceCommsException['setup_write']: raise RP_PLL.CommsError('test exception')
def read_ddc_samples_from_DDR2(self): if self.bIntroduceCommsException['read_ddc_samples_from_DDR2']: raise RP_PLL.CommsError('test exception') # need to return a representative test vector (tone + noise maybe?) # samples_out = 0.1*np.cos(2*np.pi*1e6/self.fs*np.arange(0., self.Num_samples_read)) samples_out = np.zeros((self.Num_samples_read, )) # make the two test cases different a bit: if self.last_selector == self.LOGGER_MUX['DDC0']: samples_out = samples_out + 1e5 elif self.last_selector == self.LOGGER_MUX['DDC1']: samples_out = samples_out + 2e5 # # add noise, but keep the same seed everytime for repeatable results: # np.random.seed(self.random_seed) # samples_out = samples_out + 1e6 * np.diff(np.random.randn(self.Num_samples_read), prepend=(0,)) return samples_out
def __init__(self): super(controller, self).__init__() self.logger_name = 'main_gui' # Start Qt: self.app = QtCore.QCoreApplication.instance() if self.app is None: print("QCoreApplication not running yet. creating.") self.bEventLoopWasRunningAlready = False self.app = QtWidgets.QApplication(sys.argv) else: self.bEventLoopWasRunningAlready = True print("QCoreApplication already running.") self.dev = RP_PLL.RP_PLL_device() self.initialConfigUI()
def read_adc_samples_from_DDR2(self): if self.bIntroduceCommsException['read_adc_samples_from_DDR2']: raise RP_PLL.CommsError('test exception') # need to return a representative test vector (tone + noise maybe?) samples_out = 0.1 * np.cos( 2 * np.pi * 25e6 / self.fs * np.arange(0., self.Num_samples_read)) # if this is one of the dac, add an offset, different for each dac, so that we can test the reads easily: if self.last_selector == self.LOGGER_MUX['DAC0']: samples_out = samples_out + 1e-4 elif self.last_selector == self.LOGGER_MUX['DAC1']: samples_out = samples_out + 2e-4 elif self.last_selector == self.LOGGER_MUX['DAC2']: samples_out = samples_out + 3e-4 # add noise, but keep the same seed everytime for repeatable results: np.random.seed(self.random_seed) samples_out = samples_out + 1e-3 * np.random.randn( self.Num_samples_read) samples_out = np.round(2.**(16 - 1) * samples_out) ref_exp0 = 1. + 0.j return (samples_out, ref_exp0)
def main(): import RP_PLL IP = '192.168.0.150' PORT = 5000 dev = RP_PLL.RP_PLL_device(None) dev.OpenTCPConnection(IP, PORT) app = QtCore.QCoreApplication.instance() if app is None: app = QtWidgets.QApplication(sys.argv) ACQ = AcqCard(dev) # Show GUI ACQ.show() # GUI.showMaximized() # Execute application app.exec_()
def test1(): app = start_qt() mock_server = objSocketMock() time.sleep(0.1) # timerMaxTestDuration = QtCore.QTimer() # timerMaxTestDuration.singleShot(1000, mock_server.timerQuit) dev = RP_PLL.RP_PLL_device() dev.OpenTCPConnection(HOST="127.0.0.1") assert dev.valid_socket # actual test for latency in [0., 1., 4., 5.]: print("Setting reply latency = %f" % latency) mock_server.setReplyLatency.emit(latency) time.sleep(10e-3) try: check_readreg(dev) except RP_PLL.CommsLoggeableError: print("Read timed out, with latency=%f and timeout=%f" % (latency, dev.sock.gettimeout())) assert latency >= dev.sock.gettimeout()
def trigger_write(self): if self.bIntroduceCommsException['trigger_write']: raise RP_PLL.CommsError('test exception') pass
def read_Zynq_register_int64(self, address_uint32_lsb, address_uint32_msb): raise RP_PLL.CommsError()
def read_adc_samples_from_DDR2(self): raise RP_PLL.CommsError()
def get_ddc1_ref_freq_from_RAM(self): raise RP_PLL.CommsError()
def set_ddc1_ref_freq(self, dac_number): raise RP_PLL.CommsError() self.set_ddc1_ref_freq_called += 1
def get_openLoop_gain(self, dac_number): raise RP_PLL.CommsError('test exception')
def send_bus_cmd(self, bus_address, data1, data2): raise RP_PLL.CommsError('test exception')
def setDitherLockInState(self, *args, **kwargs): if self.bIntroduceCommsException['setDitherLockInState']: raise RP_PLL.CommsError('test exception') pass
def setTestOscillator(self, bEnable=1, bPolarity=1, oscillator_modulus=625, oscillator_modulus_active=62): raise RP_PLL.CommsError('test exception')
def set_dac_offset(self, dac_number, offset): if self.bIntroduceCommsException['set_dac_offset']: raise RP_PLL.CommsError('test exception') pass
from __future__ import print_function import sys import numpy as np import time import RP_PLL # Warning : For this code to work, the correct FPGA firmware and CPU software must have been updated. IP = "192.168.0.150" PORT = 5000 dev = RP_PLL.RP_PLL_device(None) dev.OpenTCPConnection(IP, PORT) #n_pts = 5 # #data = np.random.randint(0,2**14-1,n_pts) ##data = np.array([2]) ##data = data.tostring(dtype=np.int16) #print(data) # ##data_received = dev.read_Zynq_ddr(0, 2*n_pts) ##data_received = np.fromstring(data_received , dtype=np.int16) ##print(data_received) # ## #dev.write_Zynq_ddr(0, data) dev.write_file_to_ddr()