def run(self): """ Starts writing a waveform continuously while reading the buffer periodically """ #DAQ with nidaqmx.Task() as slave_Task3, nidaqmx.Task() as master_Task: #slave_Task3 = nidaqmx.Task() slave_Task3.ao_channels.add_ao_voltage_chan("/Dev1/ao0:1") master_Task.ai_channels.add_ai_voltage_chan("/Dev1/ai0") slave_Task3.timing.cfg_samp_clk_timing( rate=self.sampleRate, source='ai/SampleClock', sample_mode=nidaqmx.constants.AcquisitionType.CONTINUOUS) # Analoginput master_Task.timing.cfg_samp_clk_timing( rate=self.sampleRate, sample_mode=nidaqmx.constants.AcquisitionType.CONTINUOUS, samps_per_chan=self.readNumber) reader = AnalogSingleChannelReader(master_Task.in_stream) writer = AnalogMultiChannelWriter(slave_Task3.out_stream) reader.auto_start = False writer.auto_start = False writer.write_many_sample(self.wave) """Reading data from the buffer in a loop. The idea is to let the task read more than could be loaded in the buffer for each iteration. This way the task will have to wait slightly longer for incoming samples. And leaves the buffer entirely clean. This way we always know the correct numpy size and are always left with an empty buffer (and the buffer will not slowly fill up).""" output = np.zeros(self.readNumber) slave_Task3.start( ) #Will wait for the readtask to start so it can use its clock master_Task.start() while not self.isInterruptionRequested(): reader.read_many_sample( data=output, number_of_samples_per_channel=self.readNumber) #Emiting the data just received as a signal Dataholder_average = np.mean(output.reshape( self.averagenumber, -1), axis=0) self.data_PMT = np.reshape( Dataholder_average, (self.ypixelnumber, self.ScanArrayXnum)) if self.ypixelnumber == 500: self.data_PMT = self.data_PMT[:, 50:550] * -1 elif self.ypixelnumber == 256: self.data_PMT = self.data_PMT[:, 70:326] * -1 self.measurement.emit(self.data_PMT)
def run(self): """ Starts writing a waveform continuously while reading the buffer periodically """ with nidaqmx.Task() as slave_Task, nidaqmx.Task() as master_Task: slave_Task.ao_channels.add_ao_voltage_chan("/Dev1/ao0:1") master_Task.ai_channels.add_ai_voltage_chan("/Dev1/ai0") if self.flag_continuous == False: # Timing of analog output channels slave_Task.timing.cfg_samp_clk_timing( rate=self.Daq_sample_rate, source='ai/SampleClock', sample_mode=AcquisitionType.FINITE, samps_per_chan=self.Totalscansamples) # Timing of recording channels master_Task.timing.cfg_samp_clk_timing( rate=self.Daq_sample_rate, sample_mode=AcquisitionType.FINITE, samps_per_chan=self.Totalscansamples) else: # Timing of analog output channels slave_Task.timing.cfg_samp_clk_timing( rate=self.Daq_sample_rate, source='ai/SampleClock', sample_mode=AcquisitionType.CONTINUOUS) # Timing of recording channels master_Task.timing.cfg_samp_clk_timing( rate=self.Daq_sample_rate, sample_mode=AcquisitionType.CONTINUOUS, samps_per_chan=self.Totalscansamples) reader = AnalogSingleChannelReader(master_Task.in_stream) writer = AnalogMultiChannelWriter(slave_Task.out_stream) reader.auto_start = False writer.auto_start = False writer.write_many_sample(self.Galvo_samples) """Reading data from the buffer in a loop. The idea is to let the task read more than could be loaded in the buffer for each iteration. This way the task will have to wait slightly longer for incoming samples. And leaves the buffer entirely clean. This way we always know the correct numpy size and are always left with an empty buffer (and the buffer will not slowly fill up).""" output = np.zeros(self.Totalscansamples) slave_Task.start( ) #Will wait for the readtask to start so it can use its clock master_Task.start() # while not self.isInterruptionRequested(): reader.read_many_sample( data=output, number_of_samples_per_channel=self.Totalscansamples) Dataholder_average = np.mean(output.reshape(self.averagenum, -1), axis=0) if self.flag_return_image == True: # Calculate the mean of average frames. self.data_PMT = np.reshape( Dataholder_average, (self.pixel_number, self.total_X_sample_number)) # Cut off the flying back part. if self.pixel_number == 500: self.image_PMT = self.data_PMT[:, 50:550] * -1 elif self.pixel_number == 256: self.image_PMT = self.data_PMT[:, 70:326] * -1 return self.image_PMT