def ellipse(self): minVolt = -10.0 maxVolt = 10.0 freq = 2000 # frequency NS = freq * 1 # total number of seconds for entire scan COUNT = 32 # 32 data points per circle DACFREQ = freq * COUNT # frequency at which data points are updated for DAC output i = np.arange(COUNT) * ( (2 * np.pi) / 32) # 2*pi*1second for 32 points => 2pi/32 x = np.cos(i) * 1 y = np.sin(i) * 1 cnt_x = ((((x + self.XSpinBox.value() - minVolt) * 65535 / (maxVolt - minVolt)))).astype(np.uint16) cnt_y = ((((y + self.YSpinBox.value() - minVolt) * 65535 / (maxVolt - minVolt)))).astype(np.uint16) daq.DacSetOutputMode(handle, daqh.DddtLocal, 1, daqh.DdomStaticWave) daq.DacWaveSetTrig(handle, daqh.DddtLocal, 1, daqh.DdtsImmediate, 0) daq.DacWaveSetClockSource(handle, daqh.DddtLocal, 1, daqh.DdcsDacClock) daq.DacWaveSetFreq(handle, daqh.DddtLocal, 1, DACFREQ) daq.DacWaveSetMode(handle, daqh.DddtLocal, 1, daqh.DdwmNShot, NS * COUNT) daq.DacWaveSetBuffer(handle, daqh.DddtLocal, 1, cnt_x, COUNT, daqh.DdtmUserBuffer) daq.DacWaveSetUserWave(handle, daqh.DddtLocal, 1) daq.DacSetOutputMode(handle, daqh.DddtLocal, 2, daqh.DdomStaticWave) daq.DacWaveSetTrig(handle, daqh.DddtLocal, 2, daqh.DdtsImmediate, 0) daq.DacWaveSetClockSource(handle, daqh.DddtLocal, 2, daqh.DdcsDacClock) daq.DacWaveSetFreq(handle, daqh.DddtLocal, 2, DACFREQ) daq.DacWaveSetMode(handle, daqh.DddtLocal, 2, daqh.DdwmNShot, NS * COUNT) daq.DacWaveSetBuffer(handle, daqh.DddtLocal, 2, cnt_y, COUNT, daqh.DdtmUserBuffer) daq.DacWaveSetUserWave(handle, daqh.DddtLocal, 2) daq.DacWaveArm(handle, daqh.DddtLocal) print("Scanning in progress") tm.sleep(NS / freq + 0.1) print("Scanning complete") daq.DacWaveDisarm(handle, daqh.DddtLocal)
def update(self): active, retCount = daq.AdcTransferGetStat(handle) bufCTR0 = self.readbuffer.reshape(-1, self.CHANCOUNT)[:, 0] self.curve1.setData(self.curvetime[:retCount], bufCTR0[:retCount]) self.curve2.setData(self.Vt[:retCount], bufCTR0[:retCount]) if retCount >= self.SCANS: # For some reason if retCount is self.SCANS: doesn't work ??? self.timer.stop() # Disarm when completed - placed inside this to avoid possible disarming even before acquiring desired data daq.AdcDisarm(handle) daq.DacWaveDisarm(handle, daqh.DddtLocal) print "Scan Completed\n" # buffer data format [CTR0, CTR1, CTR0, CTR1, CTR0, CTR1, ...] bufCTR0 = self.readbuffer.reshape(-1, self.CHANCOUNT)[:, 0] bufCTR1 = self.readbuffer.reshape(-1, self.CHANCOUNT)[:, 1] print "bufCTR0 (photon counts)", bufCTR0 print "bufCTR1 (SYNC counts)", bufCTR1 np.savetxt("PhotonCounts.csv", np.column_stack((bufCTR0, bufCTR1, self.DACwave)), delimiter=",", header="Photon Counts, SYNC, Voltage", comments=" ")
retCount, active = (0,0) while not msvcrt.kbhit(): #transfer status and transfer count can be determined here active, retCount = daq.AdcTransferGetStat(handle) time.sleep(0.5) #The signals are dynamically updated square waves which will rise in Vrms but #retain the same Vpp #see if you need to start over if buf[retCount%COUNT][0] == 60000: #update starting with the next count in buffer startindx = retCount%COUNT buf[startindx:,0] = 0 buf[startindx:,1] = 60000 buf[:startindx,0] = 0 buf[:startindx,1] = 60000 else: startindx = retCount%COUNT buf[startindx:,0] += 10000 buf[startindx:,1] -= 10000 buf[:startindx,0] += 10000 buf[:startindx,1] -= 10000 #halt output daq.DacWaveDisarm(handle, daqh.DddtLocal) #Close device connection daq.Close(handle)
def raster(self): minVolt = -10.0 maxVolt = 10.0 freq = 1 COUNT = 68 * 62 FREQ = freq * COUNT x = [] y = [] NS = freq * 1 i = 0 while i < 62: j = 0 while j < 62: x.append(j) y.append(i) j += 1 j = 61 if i is not 61: while j >= 10: j -= 10 x.append(j) y.append(i) if i is 61: # The scan now has 62+6 points in each line and when it reaches the last line, it uses the same 6 points to go to beginning point while j >= 10: # For the actual data that we are interested, we have to ignore 6 points after every 62 points j -= 10 i -= 10 x.append(j) y.append(i) i = 61 i += 1 cnt_x = ((((np.array(x) * 0.01 - minVolt) * 65535 / (maxVolt - minVolt)))).astype(np.uint16) cnt_y = ((((np.array(y) * 0.01 - minVolt) * 65535 / (maxVolt - minVolt)))).astype(np.uint16) daq.DacSetOutputMode(handle, daqh.DddtLocal, 1, daqh.DdomStaticWave) daq.DacWaveSetTrig(handle, daqh.DddtLocal, 1, daqh.DdtsImmediate, 0) daq.DacWaveSetClockSource(handle, daqh.DddtLocal, 1, daqh.DdcsAdcClock) daq.DacWaveSetFreq(handle, daqh.DddtLocal, 1, FREQ) daq.DacWaveSetMode(handle, daqh.DddtLocal, 1, daqh.DdwmNShot, NS * COUNT) daq.DacWaveSetBuffer(handle, daqh.DddtLocal, 1, cnt_x, COUNT, daqh.DdtmUserBuffer) daq.DacWaveSetUserWave(handle, daqh.DddtLocal, 1) daq.DacSetOutputMode(handle, daqh.DddtLocal, 2, daqh.DdomStaticWave) daq.DacWaveSetTrig(handle, daqh.DddtLocal, 2, daqh.DdtsImmediate, 0) daq.DacWaveSetClockSource(handle, daqh.DddtLocal, 2, daqh.DdcsAdcClock) daq.DacWaveSetFreq(handle, daqh.DddtLocal, 2, FREQ) daq.DacWaveSetMode(handle, daqh.DddtLocal, 2, daqh.DdwmNShot, NS * COUNT) daq.DacWaveSetBuffer(handle, daqh.DddtLocal, 2, cnt_y, COUNT, daqh.DdtmUserBuffer) daq.DacWaveSetUserWave(handle, daqh.DddtLocal, 2) self.rasterbuffer = np.ones(NS * COUNT, dtype=np.uint16) channels = [0] gains = [daqh.DgainDbd3kX1] flags = [daqh.DafCtr16] daq.AdcSetAcq(handle, daqh.DaamNShot, 0, NS * COUNT) daq.AdcSetScan(handle, channels, gains, flags) daq.AdcSetFreq(handle, FREQ) daq.SetOption( handle, 0, daqh.DcofChannel, daqh.DcotCounterEnhMeasurementMode, daqh.DcovCounterEnhMode_Counter + daqh.DcovCounterEnhCounter_ClearOnRead) daq.AdcTransferSetBuffer(handle, self.rasterbuffer, NS * COUNT, 1, daqh.DatmUpdateSingle + daqh.DatmCycleOff) daq.SetTriggerEvent(handle, daqh.DatsExternalTTL, daqh.DetsRisingEdge, 0, daqh.DgainDbd3kX1, daqh.DafCtr16, daqh.DaqTypeCounterLocal, 0, 0, daqh.DaqStartEvent) daq.SetTriggerEvent(handle, daqh.DatsScanCount, daqh.DetsRisingEdge, 0, daqh.DgainDbd3kX1, daqh.DafCtr16, daqh.DaqTypeCounterLocal, 0, 0, daqh.DaqStopEvent) daq.AdcTransferStart(handle) daq.AdcArm(handle) print "waiting for Scan trigger...\n" daq.DacWaveArm(handle, daqh.DddtLocal) tm.sleep(1) handle1.Ctrig() print("Scanning...\n") active, retCount = daq.DacTransferGetStat(handle, daqh.DddtLocal, 1) while active & daqh.DdafTransferActive: active, retCount = daq.DacTransferGetStat(handle, daqh.DddtLocal, 1) #print(active, retCount) tm.sleep( 0.1 ) # Sometimes Data Acquisition isn't finished yet even though the DAC output is complete. Don't know why??? (Update frequencies and # of data points are the same) daq.AdcDisarm(handle) daq.DacWaveDisarm(handle, daqh.DddtLocal) print(self.rasterbuffer, len(self.rasterbuffer)) imagedata = np.zeros((62, 62)) i = j = k = 0 while k < len(self.rasterbuffer): imagedata[j, i] = self.rasterbuffer[k] i += 1 if i % 62 is 0: k += 6 j += 1 i = 0 k += 1 print(imagedata) plt.clf() plt.imshow(imagedata, cmap=cm.Greys_r) plt.show()