int32 Tweezers::CurrentRun(float64* curr, float64* indata, void* lpParam) { threadinfo* t = (threadinfo*)lpParam; // config and start analog tast DAQmxErrRtn(DAQmxCfgSampClkTiming(AOtaskHandle,"",10*float64(1/(*t->delta*1E-3)),DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,(*t->cycles*10*t->nofFrames))); DAQmxErrRtn(DAQmxCfgOutputBuffer(AOtaskHandle, t->nofFrames*10)); DAQmxErrRtn(DAQmxCfgDigEdgeStartTrig(AOtaskHandle, "PFI0", DAQmx_Val_Rising)); DAQmxErrRtn(DAQmxWriteAnalogF64(AOtaskHandle,t->nofFrames*10,0,10.0,DAQmx_Val_GroupByChannel,curr,&written,NULL)); DAQmxErrRtn(DAQmxStartTask(AOtaskHandle)); cerr << "\nTrying to allocate buffer for " << (*t->cycles * t->nofFrames) << " frames\n"; // config and start pulse channel with parameters set by user //DAQmxErrRtn(DAQmxCfgImplicitTiming(DOtaskHandle, DAQmx_Val_FiniteSamps,*t->cycles * t->nofFrames)); DAQmxErrRtn(DAQmxCfgImplicitTiming(DOtaskHandle, DAQmx_Val_ContSamps,1)); DAQmxErrRtn(DAQmxCfgDigEdgeStartTrig(DOtaskHandle, "PFI0", DAQmx_Val_Rising)); DAQmxErrRtn(DAQmxStartTask(DOtaskHandle)); // config analog in task DAQmxErrRtn(DAQmxCfgSampClkTiming(AItaskHandle,"Ctr0Out",100,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,*t->cycles * t->nofFrames)); DAQmxErrRtn(DAQmxStartTask(AItaskHandle)); // set trigger line to 1 - GO! DAQmxWriteDigitalLines(TRtaskHandle,1,1,10,DAQmx_Val_GroupByChannel,trigdata[1],&written,NULL); // wait until cam trigger task is done DAQmxWaitUntilTaskDone(AOtaskHandle,-1); // reset trigger line DAQmxWriteDigitalLines(TRtaskHandle,1,1,10,DAQmx_Val_GroupByChannel,trigdata[0],&written,NULL); // read protocol samples DAQmxReadAnalogF64(AItaskHandle,*t->cycles * t->nofFrames,5.0,DAQmx_Val_GroupByChannel,indata,*t->cycles * t->nofFrames*2,&read,NULL); //read indeed current ofstream strom; strom.open("newcurrent.txt", ofstream::app); for(int i=0;i<t->nofFrames;i++) strom<<i*(*t->delta*1E-3)<<"\t"<<indata[i]<<endl; strom.close(); // stop tasks, disable trigger DAQmxStopTask(AOtaskHandle); DAQmxStopTask(DOtaskHandle); DAQmxStopTask(AItaskHandle); DAQmxDisableStartTrig(AOtaskHandle); DAQmxDisableStartTrig(DOtaskHandle); }
void NationalInstrumentsDAQ::setupAOChannels( float64 nrecords, float64 record_frequency_Hz, float64 vmin, float64 vmax, IDAQPhysicalChannel **channels, int nchannels ) { TaskHandle ao = 0; int32 N = _config->ao_samples_per_waveform(); char terms[MAX_CHAN_STRING]= {0}; const char *dev = _config->name().c_str(), *trig = _config->trigger().c_str(); char clk[MAX_CHAN_STRING] = {0}; float64 hz = computeSampleFrequency(nrecords,record_frequency_Hz), lvl = _config->level_volts(); strcat(clk,_config->ctr().c_str()); strcat(clk,"InternalOutput"); // terminal names TRY(nchannels<countof(terms)); { const char* names[8]={0}; for(int i=0;i<nchannels;++i) names[i]=channels[i]->name(); cat_terminal_names(terms,sizeof(terms),dev,names,nchannels); } // voltage range { f64 v[4]; DAQERR(DAQmxGetDevAOVoltageRngs(_config->name().c_str(),v,4)); vmin = MAX(vmin,v[2]); vmax = MIN(vmax,v[3]); } ao=_ao.daqtask; DAQERR(DAQmxCreateAOVoltageChan (ao,terms,NULL,vmin,vmax,DAQmx_Val_Volts,NULL)); DAQERR(DAQmxCfgSampClkTiming (ao,clk,hz,DAQmx_Val_Rising,DAQmx_Val_ContSamps,N)); DAQERR(DAQmxCfgOutputBuffer (ao,10*N)); DAQERR(DAQmxSetWriteRegenMode (ao,DAQmx_Val_DoNotAllowRegen)); DAQERR(DAQmxSetWriteRelativeTo (ao,DAQmx_Val_CurrWritePos)); DAQERR(DAQmxSetAODataXferMech (ao,terms,DAQmx_Val_DMA)); DAQERR(DAQmxSetAODataXferReqCond(ao,terms,DAQmx_Val_OnBrdMemNotFull)); DAQERR(DAQmxCfgAnlgEdgeStartTrig(ao,trig,DAQmx_Val_Rising,lvl)); return; Error: UNREACHABLE; }