// from ScanEngineConfigDAQmxTask(ScanStruct& scanEngine, bool bTriggered, bool bContinuous); int ScanEngine::configDAQmxTask(bool bTriggered, bool bContinuous) { int error; //extern Trig_Channel; //_____DAQmx Configure Code________________________________________________________________ if (!scanTaskHandle) DAQmxErrChk (DAQmxCreateTask("Scan",&(scanTaskHandle))); DAQmxErrChk (DAQmxCreateAOVoltageChan(scanTaskHandle,xChan,"",xMinVOScan,xMaxVOScan,DAQmx_Val_Volts, NULL)); DAQmxErrChk (DAQmxCreateAOVoltageChan(scanTaskHandle,yChan,"",yMinVOScan,yMaxVOScan, DAQmx_Val_Volts, NULL)); if(!bParkBeam) { if (bContinuous) { if (bLineScan) DAQmxErrChk (DAQmxCfgSampClkTiming(scanTaskHandle,"/Dev1/PFI13",Samp_Rate, DAQmx_Val_Rising,DAQmx_Val_ContSamps,numSampsPerFrame_LS)) else DAQmxErrChk (DAQmxCfgSampClkTiming(scanTaskHandle,"/Dev1/PFI13",Samp_Rate, DAQmx_Val_Rising,DAQmx_Val_ContSamps,numSampsPerFrame)); } else { if (bLineScan) DAQmxErrChk (DAQmxCfgSampClkTiming(scanTaskHandle,"/Dev1/PFI13",Samp_Rate, DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,numSampsTotal_LS)) else DAQmxErrChk (DAQmxCfgSampClkTiming(scanTaskHandle,"/Dev1/PFI13",Samp_Rate, DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,numSampsTotal)); } if (bTrigger) { //DAQmxErrChk (DAQmxCfgAnlgEdgeStartTrig (scanTaskHandle, trigChan, DAQmx_Val_RisingSlope , 2.0)); DAQmxErrChk (DAQmxCfgDigEdgeStartTrig(scanTaskHandle, trigChan, DAQmx_Val_Rising)); } }
void QxrdNIDAQPlugin::setAnalogWaveform(QString chan, double rate, double wfm[], int size) { QMutexLocker lock(&m_Mutex); // printf("setAnalogWaveform(%g,%g...,%d)\n", rate, wfm[0], size); int error; int32 nsampwrt; if (m_AOTaskHandle) { DAQmxStopTask(m_AOTaskHandle); DAQmxClearTask(m_AOTaskHandle); m_AOTaskHandle = 0; } if (chan >= 0) { DAQmxErrChk(DAQmxCreateTask("qxrd-output", &m_AOTaskHandle)); DAQmxErrChk(DAQmxCreateAOVoltageChan (m_AOTaskHandle, qPrintable(chan), NULL, -10.0, 10.0, DAQmx_Val_Volts, NULL)); if (m_AOTaskHandle) { DAQmxErrChk( DAQmxCfgSampClkTiming(m_AOTaskHandle, NULL, rate, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, size) ); DAQmxErrChk( DAQmxWriteAnalogF64(m_AOTaskHandle, size, false, -1, DAQmx_Val_GroupByChannel, wfm, &nsampwrt, NULL) ); } } // printf("%d samples written\n", nsampwrt); Error: return; }
void QxrdNIDAQPlugin::setAnalogOutput(int chan, double value) { QMutexLocker lock(&m_Mutex); int error; if (m_AOTaskHandle) { DAQmxStopTask(m_AOTaskHandle); DAQmxClearTask(m_AOTaskHandle); m_AOTaskHandle = 0; } if (chan >= 0) { DAQmxErrChk(DAQmxCreateTask("qxrd-output", &m_AOTaskHandle)); DAQmxErrChk(DAQmxCreateAOVoltageChan (m_AOTaskHandle, qPrintable(tr("Dev1/ao%1").arg(chan)), NULL, -10.0, 10.0, DAQmx_Val_Volts, NULL)); if (m_AOTaskHandle) { DAQmxErrChk(DAQmxWriteAnalogScalarF64(m_AOTaskHandle, true, 10.0, value, NULL)); } } Error: return; }
// constructor Tweezers::Tweezers(double iF0,double id0,double ic1,double ic2,double ic3,double Anti_Voltage, void* lpParam) { threadinfo* t = (threadinfo*)lpParam; // set calibration parameters F0 = iF0; d0 = id0; c1 = ic1; c2 = ic2; c3 = ic3; AV = Anti_Voltage; x4 = *t->x4; x3 = *t->x3; x2 = *t->x2; x1 = *t->x1; x0 = *t->x0; done = false; islate = false; residual = AV; tmp_residual = AV; trigdata[0][0] = 0; trigdata[1][0] = 1; // initialize device DAQmxResetDevice("Dev1"); // create and setup analog task DAQmxCreateTask("AO",&AOtaskHandle); DAQmxCreateAOVoltageChan(AOtaskHandle,"Dev1/ao0","",-10.0,10.0,DAQmx_Val_Volts,NULL); DAQmxGetExtendedErrorInfo(errBuff,2048); cerr<<errBuff; // create and reset start trigger // implicit timing => no start task... (?) DAQmxCreateTask("TR",&TRtaskHandle); DAQmxCreateDOChan(TRtaskHandle,"Dev1/port0/line7","TR",DAQmx_Val_ChanForAllLines); DAQmxWriteDigitalLines(TRtaskHandle,1,1,10,DAQmx_Val_GroupByChannel,trigdata[0],&written,NULL); // create pulse channel for trigger DAQmxCreateTask("DO",&DOtaskHandle); DAQmxCreateCOPulseChanTime(DOtaskHandle,"Dev1/Ctr0","",DAQmx_Val_Seconds,DAQmx_Val_Low,1E-3*(*t->wait),1E-3*(*t->delta)/2.0,1E-3*(*t->delta/2.0)); DAQmxCreateTask("AI",&AItaskHandle); DAQmxCreateAIVoltageChan(AItaskHandle,"Dev1/ai0,Dev1/ai2","",DAQmx_Val_RSE,-10,+10,DAQmx_Val_Volts,NULL); DAQmxGetExtendedErrorInfo(errBuff,2048); cerr<<errBuff; // set to zero force Reset(); }
void DaqMagControl::set_volts(double this_volts) { DAQmxCreateTask("",&taskHandle); DAQmxCreateAOVoltageChan (taskHandle, chan_char, "", -10.0, 10.0, DAQmx_Val_Volts , NULL); DAQmxStartTask(taskHandle); double volts=this_volts; DAQmxWriteAnalogF64(taskHandle,1,1,10.0,DAQmx_Val_GroupByChannel,&volts,NULL,NULL); if( taskHandle!=0 ) { DAQmxStopTask(taskHandle); DAQmxClearTask(taskHandle); } }
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; }
int32 Tweezers::Degauss(float U, float duration) { clock_t startTime; float freq = 100; int bufferSize = (int)(5000 * duration); float64 *data = new float64[bufferSize]; // fill buffer with data for(int i=0;i<bufferSize;i++) { float64 amp = U * (1 - (double)i/(double)(bufferSize-1)); data[i] = amp * cos( 2.0 * PI * freq * (double)i/5000.0); // degauss Srate must be independent of run!! } DAQmxErrRtn(DAQmxClearTask(AOtaskHandle)); // create and setup analog task DAQmxErrRtn(DAQmxCreateTask("AO",&AOtaskHandle)); DAQmxErrRtn(DAQmxCreateAOVoltageChan(AOtaskHandle,"Dev1/ao0","",-10.0,10.0,DAQmx_Val_Volts,NULL)); // configure sample clock for buffered write DAQmxErrRtn(DAQmxCfgSampClkTiming(AOtaskHandle,"",5000,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,(int)(duration*5000))); // write data and start task DAQmxErrRtn(DAQmxWriteAnalogF64(AOtaskHandle,bufferSize,0,10.0,DAQmx_Val_GroupByChannel,data,&written,NULL)); startTime = clock(); DAQmxErrRtn(DAQmxStartTask(AOtaskHandle)); while(!done) { DAQmxErrRtn(DAQmxIsTaskDone(AOtaskHandle,&done)); if (!done) Sleep(100); } done = false; DAQmxErrRtn(DAQmxStopTask(AOtaskHandle)); residual = 0.0; delete data; }
int ConfigStartle(void) { int i; for(i = 0;i<250;i++) { gStartleData[i] = 5.0 ;//* sin(i / 5000.0 * 1400.0 * 2.0 * PI);//(i / 1000 * 400 * 2 * PI); // printf("%lf, ", gStartleData[i]); } for (i = 250; i < 400; i++) gStartleData[i] = 0.0; /*********************************************/ // DAQmx Configure Code /*********************************************/ DAQmxErrChk (DAQmxCreateTask("",&startleDaqHandle)); DAQmxErrChk (DAQmxCreateAOVoltageChan(startleDaqHandle,"Dev1/ao0","",-10.0,10.0,DAQmx_Val_Volts,NULL)); DAQmxErrChk (DAQmxCfgSampClkTiming(startleDaqHandle,"",5000.0,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,400)); Error: return 0; }
//Gateway routine void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { TaskHandle task,task2; float64 sampleRate = 100000; float64 acqTime = 5; uInt64 numSamples = (uInt64) sampleRate * acqTime; char chanName[128]; int32 sampsWritten; //Create the task DAQmxCreateTask("",&task); DAQmxCreateTask("",&task2); //Add AI channels to task DAQmxCreateAIVoltageChan(task, "Dev1/ai0:2", "ScanImageAcq", -1, -1, 1, DAQmx_Val_Volts, NULL); DAQmxCreateAOVoltageChan(task2, "Dev1/ao0:2", "ScanImageControl", -1, 1, DAQmx_Val_Volts, NULL); //Configure task timing DAQmxCfgSampClkTiming(task, NULL, 100000, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, numSamples); DAQmxCfgSampClkTiming(task2, NULL, 100000, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, numSamples); //Configure some task properties for (int i=0; i<2; i++) { sprintf_s(chanName, "Dev1/ai%d", i); DAQmxSetAIMax(task, chanName, 10); DAQmxSetAIMax(task, chanName, -10); } //Write some data DAQmxWriteAnalogF64(task, (int32) numSamples, false, -1, DAQmx_Val_GroupByChannel, outputData, &sampsWritten, NULL); //Screw it DAQmxClearTask(task); }
/****************************************************************************** ** ** Fonction de démarage de la tache d'alimentation du moteur ** La vitesse du moteur est défini à 50% ** ******************************************************************************/ int NI6211::startMotor() { int error=0; taskVOut = new TaskHandle; float64 data[1] = {0}; /*------ DAQmx Configure Code ------*/ DAQmxErrChk (DAQmxCreateTask("",taskVOut)); DAQmxErrChk (DAQmxCreateAOVoltageChan(*taskVOut,"/Equilibreuse/ao0","",-10.0,10.0,DAQmx_Val_Volts,"")); /*------ DAQmx Start Code ------*/ DAQmxErrChk (DAQmxStartTask(*taskVOut)); /*------ DAQmx Write Code ------*/ DAQmxErrChk (DAQmxWriteAnalogF64(*taskVOut,1,1,-1,DAQmx_Val_GroupByChannel,data,NULL,NULL)); Erreur: checkError(error); return 0; }
void QxrdNIDAQPlugin::setAnalogOutput(QString channelName, double value) { QMutexLocker lock(&m_Mutex); int error; if (m_AOTaskHandle) { DAQmxStopTask(m_AOTaskHandle); DAQmxClearTask(m_AOTaskHandle); m_AOTaskHandle = 0; } DAQmxErrChk(DAQmxCreateTask("qxrd-analog-out", &m_AOTaskHandle)); DAQmxErrChk(DAQmxCreateAOVoltageChan (m_AOTaskHandle, qPrintable(channelName), NULL, -10.0, 10.0, DAQmx_Val_Volts, NULL)); DAQmxErrChk(DAQmxWriteAnalogScalarF64(m_AOTaskHandle, true, 10.0, value, NULL)); Error: return; }
int main() { //////////////////////////////// // Program settings /////////////////////////////// float stageStepSize = 5.0/2; // in um int stepTotalX = 1600;//2000/stageStepSize; int stepTotalY = 600;//2000/stageStepSize; int stepX = 1; int stepY = 1; int stageLocation[2] = { 0, 0 }; int16 *stageLocationSave[2]; // Ensure that this is made large enough for some spillover int stageCount = 0; stageLocationSave[0] = new int16[NUMSTAGELOCATIONS]; stageLocationSave[1] = new int16[NUMSTAGELOCATIONS]; // Motors off XON(0); YON(0); //////////////////////////////// // Initialize DAQ settings /////////////////////////////// TaskHandle directionX = 0; TaskHandle directionY = 0; DAQmxCreateTask("XDir", &directionX); DAQmxCreateTask("YDir", &directionY); DAQmxCreateAOVoltageChan(directionX, "Dev1/ao1", "XDir", 0.0, 5.0, DAQmx_Val_Volts, NULL); // X Direction DAQmxCreateAOVoltageChan(directionY, "Dev1/ao0", "YDir", 0.0, 5.0, DAQmx_Val_Volts, NULL); // Y Direction float64 fiveVoltOut[2] = { 5.0, 5.0 }; // 5.0 V float64 zeroVoltOut[2] = { 0.0, 0.0 }; // 0.0 V //Must be 2 bits uInt8 outClock[2] = { 0 , 1 }; uInt8 onSig[2] = { 1, 1 }; //////////////////////////////// // Initialize Gage card /////////////////////////////// if (initializeGage(stageStepSize)) { fprintf(stdout, ("Error initializing Gage card, please check settings\n\n")); getchar(); return -1; } fprintf(stdout, ("Gage card sucessfully initialized.\n\n")); //////////////////////////////// // Initial settings checks /////////////////////////////// // Check program buffer sizes int currBufferSize = checkBufferSize(); int totalNumStageMoves = (stepTotalX / stepX)*(stepTotalY / stepY); if (currBufferSize >= totalNumStageMoves && NUMSTAGELOCATIONS >= totalNumStageMoves) { fprintf(stdout, ("Buffer sizes appear correct.\n\n")); } else { fprintf(stdout, ("Buffer size is not set correctly. Stage locations (%d) and segment count (%d) must be greater than %d.\n\n"), (int)NUMSTAGELOCATIONS, currBufferSize, totalNumStageMoves); getchar(); return -1; } //////////////////////////////// // Print scan settings /////////////////////////////// fprintf(stdout, ("\n\n Scan Settings\n---------------\n\n")); fprintf(stdout, ("X stage step size: %3.2f um\nY stage step size: %3.2f um\n"), (float)stepX*stageStepSize, (float)stepY*stageStepSize); fprintf(stdout, ("X range: %3.2f mm\nY range: %3.2f mm\n\n"), (float)stepTotalX * stageStepSize / 1000.0, (float)stepTotalY * stageStepSize / 1000.0); //fprintf(stdout, ("Total stage moves: %d\nStage clock speed: %d Hz\n\n---------------\n\n"), (stepTotalX / stepX)*(stepTotalY / stepY),getStageClockSpeed()); fprintf(stdout, ("Total stage moves: %d\nStage clock speed: %d Hz\n"), (stepTotalX / stepX)*(stepTotalY / stepY), getStageClockSpeed()); fprintf(stdout, ("Set trigger holdoff bettween %d us and %d us\n\n"), (int)(1.0 / (float)getStageClockSpeed()*1e6), (int)(2.0 / (float)getStageClockSpeed()*1e6)); fprintf(stdout, ("---------------\n\n")); //////////////////////////////// // Prep for scan /////////////////////////////// // Ready to start scan fprintf(stdout, ("Ensure stage is centered.\nPress any key to start scan.\n\n")); getchar(); fprintf(stdout, ("Moving stage to start location.\n\n")); // Motors on XON(1); YON(1); // Scan variables int steps; //int gageCollectStatus; int XDir = 1; int saveCount = 1; // Move to start position steps = stepTotalX / 2; DAQmxWriteAnalogF64(directionX, 1, 1, 0.0, DAQmx_Val_GroupByChannel, zeroVoltOut, NULL, NULL); // dir moveXStage(steps, outClock); stageLocation[0] -= steps; steps = stepTotalY / 2; DAQmxWriteAnalogF64(directionY, 1, 1, 0.0, DAQmx_Val_GroupByChannel, zeroVoltOut, NULL, NULL); // dir moveYStage(steps, outClock); // Move stageLocation[1] -= steps; //////////////////////////////// // Scan /////////////////////////////// moveXStage(1, onSig); // hold on // Start data collection if (collectData()) { fprintf(stdout, ("Data Collection Failed")); getchar(); return (-1); } // Scan along Y for (int countY = 0; countY < stepTotalY; countY += stepY) { if (countY != 0) { // Step Y DAQmxWriteAnalogF64(directionY, 1, 1, 0.0, DAQmx_Val_GroupByChannel, fiveVoltOut, NULL, NULL); // dir moveYStage(stepY, outClock); // Move-- stageLocation[1] += stepY; } if (countY > 0) { _ftprintf(stdout, ("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b")); } _ftprintf(stdout, _T("%04.0f um remaining in Y"), (float)(stepTotalY - countY) * stageStepSize); // Scan along X if (XDir == 1) { DAQmxWriteAnalogF64(directionX, 1, 1, 0.0, DAQmx_Val_GroupByChannel, fiveVoltOut, NULL, NULL); // dir stageLocation[0] += stepTotalX; } else { DAQmxWriteAnalogF64(directionX, 1, 1, 0.0, DAQmx_Val_GroupByChannel, zeroVoltOut, NULL, NULL); // dir stageLocation[0] -= stepTotalX; } moveXStage(stepTotalX, outClock); // Move // Save stage data and change direction if (XDir == 1) { XDir = 0; } else { XDir = 1; } } _ftprintf(stdout, _T("\nScan complete. Returning to start position.\n\n")); // Move stage to center (0,0) if (stageLocation[0] > 0){ steps = stageLocation[0]; DAQmxWriteAnalogF64(directionX, 1, 1, 0.0, DAQmx_Val_GroupByChannel, zeroVoltOut, NULL, NULL); // dir moveXStage(steps, outClock); // Move stageLocation[0] -= steps; } else{ steps = -stageLocation[0]; DAQmxWriteAnalogF64(directionX, 1, 1, 0.0, DAQmx_Val_GroupByChannel, fiveVoltOut, NULL, NULL); // dir moveXStage(steps, outClock); // Move stageLocation[0] += steps; } if (stageLocation[1] > 0){ steps = stageLocation[1]; DAQmxWriteAnalogF64(directionY, 1, 1, 0.0, DAQmx_Val_GroupByChannel, zeroVoltOut, NULL, NULL); // dir moveYStage(steps, outClock); // Move stageLocation[1] -= steps; } else{ steps = -stageLocation[1]; DAQmxWriteAnalogF64(directionY, 1, 1, 0.0, DAQmx_Val_GroupByChannel, fiveVoltOut, NULL, NULL); // dir moveYStage(steps, outClock); // Move stageLocation[1] += steps; } moveXStage(2, onSig); // Move // Motors off XON(0); YON(0); //moveXStage(4, onSig); // hold on // Stage stage data int countX = 0; int countY = 0; XDir = 1; for (countY = 0; countY < stepTotalY; countY += stepY) { if (countY != 0) { stageLocationSave[0][stageCount] = countX; stageLocationSave[1][stageCount++] = countY; } if (XDir == 1) { for (countX = 0; countX < stepTotalX; countX += stepX) { stageLocationSave[0][stageCount] = countX; stageLocationSave[1][stageCount++] = countY; } XDir = 0; } else { for (countX = stepTotalX-1; countX > -1; countX -= stepX) { stageLocationSave[0][stageCount] = countX; stageLocationSave[1][stageCount++] = countY; } XDir = 1; } } // Check if aquisition is completed checkScanComplete(); // Transfer and save data int nSaveError = saveGageData(); if (nSaveError) { fprintf(stdout, ("Data Save Failed")); getchar(); return (-1); } // Save stage data TCHAR StageFileName[MAX_PATH]; FILE *fidStage; // Open Save files int nCount = 0; while (1) { nCount++; _stprintf(StageFileName, _T("E:\\GageData\\MechStageDataScan%d.txt"), nCount); fidStage = fopen(StageFileName, "r"); if (fidStage) { fclose(fidStage); } else { fidStage = fopen(StageFileName, "w"); break; } } //_stprintf(StageFileName, _T("E:\\GageData\\MechStageData.txt")); //fidStage = fopen(StageFileName, "w"); for (int n = 0; n < stageCount; n++) { _ftprintf(fidStage, _T("%d %d\n"), stageLocationSave[0][n], stageLocationSave[1][n]); // print peakData } fclose(fidStage); fidStage = NULL; delete stageLocationSave[0]; delete stageLocationSave[1]; return 0; }
void ScanThreadLinear::InitializeSyncAndScan(void) { //CLEAR TASKS DAQmxClearTask(taskClock); DAQmxClearTask(taskTrig); DAQmxClearTask(taskTrA); DAQmxClearTask(taskAnalog); Samps = globalOptions->IMAGEHEIGHT+NumPtsDw; LineRate = Samps*FrameRate; //CREATE TASKS DAQmxCreateTask("",&taskAnalog); DAQmxCreateTask("",&taskTrig); DAQmxCreateTask("",&taskTrA); DAQmxCreateTask("",&taskClock); /************************* CLOCK SOURCE *************************/ //CREATE INTERNAL CLOCK SOURCE DAQmxCreateCOPulseChanFreq(taskClock, "Dev1/ctr0", "", DAQmx_Val_Hz, DAQmx_Val_Low, __DDELAY, FrameRate, .2); /************************* DIGITAL PULSE TRAIN *************************/ //CREATE DIGITAL LINE DAQmxCreateDOChan(taskTrig,"Dev1/port0/line0","",DAQmx_Val_ChanPerLine); //SET TIMING AND STATE CLOCK SOURCE //Clock source is based off the analog sample clock DAQmxCfgSampClkTiming(taskTrig,"ao/SampleClock",FrameRate*Samps, DAQmx_Val_Rising,DAQmx_Val_ContSamps,Samps); /************************* ANALOG SAW TOOTH *************************/ //CREATE ANALOG CHANNEL DAQmxCreateAOVoltageChan(taskAnalog,"Dev1/ao0", "",-10,10.0,DAQmx_Val_Volts,NULL); DAQmxCreateAOVoltageChan(taskAnalog,"Dev1/ao1", "",-10,10.0,DAQmx_Val_Volts,NULL); //SET TIMING DAQmxCfgSampClkTiming(taskAnalog,"",FrameRate*Samps, DAQmx_Val_Rising,DAQmx_Val_ContSamps,Samps); //GET TERMINAL NAME OF THE TRIGGER SOURCE GetTerminalNameWithDevPrefix(taskTrig, "Ctr0InternalOutput",trigName); //TRIGGER THE ANALOG DATA BASED OFF INTERNAL TRIGGER (CLOCK SOURCE) DAQmxCfgDigEdgeStartTrig(taskAnalog,trigName,DAQmx_Val_Rising); if (globalOptions->bVolumeScan == false) { GenSawTooth(Samps,XScanVolts_mV,XScanOffset_mV,ScanBuff); for (int i = 0; i< Samps; i++) VolBuff[i] = ScanBuff[i]; for (int i = Samps; i < 2*Samps; i++) VolBuff[i] = YScanOffset_mV/1000; DAQmxWriteAnalogF64(taskAnalog, Samps, false ,10 ,DAQmx_Val_GroupByChannel, VolBuff,NULL,NULL); //GENERATE PULSE TRAIN TO TRIGGER CAMERA GenPulseTrain(Samps,digiBuff); DAQmxWriteDigitalLines(taskTrig,Samps,false,10.0,DAQmx_Val_GroupByChannel,digiBuff,NULL,NULL); } else { int frameCount; GenSawTooth(Samps,XScanVolts_mV,XScanOffset_mV,ScanBuff); for (frameCount = 0; frameCount < globalOptions->NumFramesPerVol; frameCount++) { for (int i = 0; i< Samps; i++) VolumeBuff[i+frameCount*Samps] = ScanBuff[i]; } GenStairCase(Samps,globalOptions->NumFramesPerVol,YScanVolts_mV, YScanOffset_mV, tempBuff); for (int i = 0; i < Samps*globalOptions->NumFramesPerVol; i++) VolumeBuff[i + Samps*globalOptions->NumFramesPerVol] = tempBuff[i]; DAQmxWriteAnalogF64(taskAnalog, Samps*globalOptions->NumFramesPerVol, false ,10 ,DAQmx_Val_GroupByChannel, VolumeBuff,NULL,NULL); //GENERATE PULSE TRAIN TO TRIGGER CAMERA for (int frameCount = 0; frameCount < globalOptions->NumFramesPerVol; frameCount++) { GenPulseTrain(Samps,digiBuff); for (int i = 0; i< Samps; i++) digiVolBuff[i+frameCount*Samps] = digiBuff[i]; } DAQmxWriteDigitalLines(taskTrig,Samps*globalOptions->NumFramesPerVol,false,10.0,DAQmx_Val_GroupByChannel,digiVolBuff,NULL,NULL); } //GENERATE PULSE TRAIN TO TRIGGER CAMERA DAQmxCreateCOPulseChanFreq(taskTrA,"Dev1/ctr1","",DAQmx_Val_Hz,DAQmx_Val_Low,0.0,LineRate,0.2); DAQmxCfgImplicitTiming(taskTrA,DAQmx_Val_FiniteSamps,globalOptions->IMAGEHEIGHT); DAQmxCfgDigEdgeStartTrig(taskTrA,"/Dev1/PFI4",DAQmx_Val_Rising); DAQmxSetStartTrigRetriggerable(taskTrA, 1); DAQmxConnectTerms ("/Dev1/Ctr1InternalOutput", "/Dev1/RTSI0", DAQmx_Val_DoNotInvertPolarity); //START TASKS //IMPORTANT - Need to arm analog task first to make sure that the digital and analog waveforms are in sync DAQmxStartTask(taskAnalog); DAQmxStartTask(taskTrA); DAQmxStartTask(taskTrig); DAQmxStartTask(taskClock); }
motorControl::motorControl(double offset1, double offset2) { encoderBias[0] = encoderBias[1] = 0; encoderGain[0] = encoderGain[1] = 0; I = 4; cortexVoluntaryAmp = 10000; cortexVoluntaryFreq = 0.25; char errBuff[2048]={'\0'}; int32 error=0; angle = 0; velocity = 0; trialTrigger = 0; gammaStatic1 = 0; gammaDynamic1 = 0; gammaStatic2 = 0; gammaDynamic2 = 0; cortexDrive[0] = 0; cortexDrive[1] = 0; spindleIa[0] = 0; spindleII[0] = 0; spindleIa[1] = 0; spindleII[1] = 0; isEnable = FALSE; isWindUp = FALSE; isControlling = FALSE; live = FALSE; loadCellOffset1 = offset1; loadCellOffset2 = offset2; loadCellData[0] = 0; loadCellData[1] = 0; motorRef[0] = 4; motorRef[1] = 4; encoderData1[0] = 0; encoderData2[0] = 0; resetMuscleLength = TRUE; muscleLengthPreviousTick[0] = 1; muscleLengthPreviousTick[1] = 1; muscleLengthOffset [0] = 0; muscleLengthOffset [1] = 0; strcpy(header,"Time, Exp Prot, Len1, Len2, ForcMeas1, ForcMeas2,"); if (dataAcquisitionFlag[0]){ strcat (header, ", ForceDes1, ForceDes2"); } if (dataAcquisitionFlag[1]){ strcat (header, ", EMG1, EMG2"); } if (dataAcquisitionFlag[2]){ strcat (header, ", Ia1, Ia2"); } if (dataAcquisitionFlag[3]){ strcat (header, ", II1, II2"); } if (dataAcquisitionFlag[4]){ strcat (header, ", Spike Count1, Spike Count2"); } if (dataAcquisitionFlag[5]){ strcat (header, ", Raster 1-1, Raster 2-1"); } if (dataAcquisitionFlag[6]){ strcat (header, ", Raster 1-2, Raster 2-2"); } if (dataAcquisitionFlag[7]){ strcat (header, ", Raster 1-3, Raster 2-3"); } if (dataAcquisitionFlag[8]){ strcat (header, ", Raster 1-4, Raster 2-4"); } if (dataAcquisitionFlag[9]){ strcat (header, ", Raster 1-5, Raster 2-5"); } if (dataAcquisitionFlag[10]){ strcat (header, ", Raster 1-6, Raster 2-6"); } char dataTemp[100]=""; strcat(header,"\n"); sprintf(dataTemp,"%d,%d,%d,%d,",dataAcquisitionFlag[0],dataAcquisitionFlag[1],dataAcquisitionFlag[2],dataAcquisitionFlag[3]); strcat(header,dataTemp); sprintf(dataTemp,"%d,%d,%d,%d,",dataAcquisitionFlag[4],dataAcquisitionFlag[5],dataAcquisitionFlag[6],dataAcquisitionFlag[7]); strcat(header,dataTemp); sprintf(dataTemp,"%d,%d,%d,%d\n",dataAcquisitionFlag[8],dataAcquisitionFlag[9],dataAcquisitionFlag[10],dataAcquisitionFlag[11]); strcat(header,dataTemp); DAQmxErrChk (DAQmxCreateTask("",&loadCelltaskHandle)); DAQmxErrChk (DAQmxCreateAIVoltageChan(loadCelltaskHandle,"PXI1Slot5/ai8","loadCell1",DAQmx_Val_RSE,loadCellMinVoltage,loadCellMaxVoltage,DAQmx_Val_Volts,NULL)); DAQmxErrChk (DAQmxCreateAIVoltageChan(loadCelltaskHandle,"PXI1Slot5/ai9","loadCell2",DAQmx_Val_RSE,loadCellMinVoltage,loadCellMaxVoltage,DAQmx_Val_Volts,NULL)); //DAQmxErrChk (DAQmxCreateAIVoltageChan(loadCelltaskHandle,"PXI1Slot5/ai16","ACC z",DAQmx_Val_RSE,loadCellMinVoltage,loadCellMaxVoltage,DAQmx_Val_Volts,NULL)); //DAQmxErrChk (DAQmxCreateAIVoltageChan(loadCelltaskHandle,"PXI1Slot5/ai17","ACC y",DAQmx_Val_RSE,loadCellMinVoltage,loadCellMaxVoltage,DAQmx_Val_Volts,NULL)); //DAQmxErrChk (DAQmxCreateAIVoltageChan(loadCelltaskHandle,"PXI1Slot5/ai18","ACC x",DAQmx_Val_RSE,loadCellMinVoltage,loadCellMaxVoltage,DAQmx_Val_Volts,NULL)); //DAQmxErrChk (DAQmxCreateAIVoltageChan(loadCelltaskHandle,"PXI1Slot5/ai19","Side LoadCell1",DAQmx_Val_RSE,loadCellMinVoltage,loadCellMaxVoltage,DAQmx_Val_Volts,NULL)); //DAQmxErrChk (DAQmxCreateAIVoltageChan(loadCelltaskHandle,"PXI1Slot5/ai20","Side LoadCell2",DAQmx_Val_RSE,loadCellMinVoltage,loadCellMaxVoltage,DAQmx_Val_Volts,NULL)); DAQmxErrChk (DAQmxCfgSampClkTiming(loadCelltaskHandle,"",controlFreq,DAQmx_Val_Rising,DAQmx_Val_HWTimedSinglePoint,NULL)); DAQmxErrChk (DAQmxSetRealTimeConvLateErrorsToWarnings(loadCelltaskHandle,1)); DAQmxErrChk (DAQmxCreateTask("",&motorTaskHandle)); DAQmxErrChk (DAQmxCreateAOVoltageChan(motorTaskHandle,"PXI1Slot2/ao9","motor1",motorMinVoltage,motorMaxVoltage,DAQmx_Val_Volts,NULL)); DAQmxErrChk (DAQmxCreateAOVoltageChan(motorTaskHandle,"PXI1Slot2/ao11","motor2",motorMinVoltage,motorMaxVoltage,DAQmx_Val_Volts,NULL)); DAQmxErrChk (DAQmxCreateAOVoltageChan(motorTaskHandle,"PXI1Slot2/ao31","speaker",motorMinVoltage,motorMaxVoltage,DAQmx_Val_Volts,NULL)); DAQmxErrChk (DAQmxCfgSampClkTiming(motorTaskHandle,"",controlFreq,DAQmx_Val_Rising,DAQmx_Val_HWTimedSinglePoint,1)); DAQmxErrChk (DAQmxCreateTask("",&motorEnableHandle)); DAQmxErrChk (DAQmxCreateDOChan(motorEnableHandle,"PXI1Slot2/port0","motorEnable",DAQmx_Val_ChanForAllLines)); DAQmxErrChk (DAQmxCreateTask("",&encodertaskHandle[0])); DAQmxErrChk (DAQmxCreateCIAngEncoderChan(encodertaskHandle[0],"PXI1Slot3/ctr7","Enoder 1",DAQmx_Val_X4,0,0.0,DAQmx_Val_AHighBHigh,DAQmx_Val_Degrees,encoderPulsesPerRev,0.0,"")); DAQmxErrChk (DAQmxCfgSampClkTiming(encodertaskHandle[0],"/PXI1Slot5/ai/SampleClock",controlFreq,DAQmx_Val_Rising,DAQmx_Val_HWTimedSinglePoint,1)); DAQmxErrChk (DAQmxCreateTask("",&encodertaskHandle[1])); DAQmxErrChk (DAQmxCreateCIAngEncoderChan(encodertaskHandle[1],"PXI1Slot3/ctr3","Enoder 2",DAQmx_Val_X4,0,0.0,DAQmx_Val_AHighBHigh,DAQmx_Val_Degrees,encoderPulsesPerRev,0.0,"")); DAQmxErrChk (DAQmxCfgSampClkTiming(encodertaskHandle[1],"/PXI1Slot5/ai/SampleClock",controlFreq,DAQmx_Val_Rising,DAQmx_Val_HWTimedSinglePoint,1)); Error: if( DAQmxFailed(error) ) { DAQmxGetExtendedErrorInfo(errBuff,2048); DAQmxClearTask(motorTaskHandle); DAQmxClearTask(loadCelltaskHandle); DAQmxClearTask(motorEnableHandle); printf("DAQmx Error: %s\n",errBuff); printf("Motor, load cell or encoder initialization error\n"); } }
int _tmain(int argc, _TCHAR* argv[]) { TaskHandle task; int acqTime = 6; float64 sampleRate = 500000.0; float64 linePeriod = .002; int lineSamples = (int)(linePeriod * sampleRate); int numLines = (int) (acqTime / (lineSamples/sampleRate)); int acqSamples = numLines * lineSamples; int32 sampsWritten; bool32 taskDone; //Create the task DAQmxCreateTask("a task", &task); //Add AO channels DAQmxCreateAOVoltageChan(task, "Dev1/ao0", "", -10, 10, DAQmx_Val_Volts, NULL); //Configure timing DAQmxCfgSampClkTiming(task, NULL, sampleRate, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, acqSamples); //Write output data float64 *outputData = (float64*) calloc(acqSamples, sizeof(float64)); for (int i=0;i<numLines;i++) { for (int j=0;j<lineSamples;j++) { outputData[i*lineSamples + j] = ((float64) j/(float64)lineSamples) * 10.0; } } DAQmxWriteAnalogF64(task, acqSamples, false, 10.0, DAQmx_Val_GroupByChannel, outputData, &sampsWritten, NULL); printf("Wrote %d samples of data!\n", sampsWritten); printf("Sample #33: %g\n", outputData[32]); printf("Sample #121: %g\n", outputData[120]); printf("Sample #6032: %g\n", outputData[6031]); //Start Task DAQmxStartTask(task); printf("Started task...\n"); while (true) { DAQmxIsTaskDone(task,&taskDone); if (taskDone) break; else Sleep(1000); } //Clear Task DAQmxClearTask(task); return 0; }
// from ConfigDAQmxTasks(float xVolts, float yVolts, ScanStructure scanStructure); int LifetimeAcq::configDAQmxTasks(float xVolts, float yVolts, ScanEngine* scanStruct) { int error; int retVal; char errBuff[2048]; double voltagePair[2]; //extern Trig_Channel; voltagePair[0] = (double)xVolts; voltagePair[1] = (double)yVolts; //_____DAQmx Configure Code________________________________________________________________ //_____Setup analog output task_____ DAQmxErrChk (DAQmxCreateTask("AnalogOuput",&aoTaskHandle)); DAQmxErrChk (DAQmxCreateAOVoltageChan (aoTaskHandle, scanStruct->getXChan(), "xChan", -2.0, 2.0, DAQmx_Val_Volts, NULL)); DAQmxErrChk (DAQmxCreateAOVoltageChan (aoTaskHandle, scanStruct->getYChan(), "yChan", -2.0, 2.0, DAQmx_Val_Volts, NULL)); DAQmxErrChk (DAQmxWriteAnalogF64 (aoTaskHandle, 1, 1, 10, DAQmx_Val_GroupByChannel, voltagePair, DAQmx_Val_GroupByChannel, NULL)); //_____Setup Analog input task_____ DAQmxErrChk (DAQmxCreateTask("TrigAcq",&acqTaskHandle)); /*Add analog input channel to acqtask*/ DAQmxErrChk (DAQmxCreateAIVoltageChan(acqTaskHandle, ACQ_CHANNEL, "PMT", DAQmx_Val_RSE,ACQMIN, ACQMAX, DAQmx_Val_Volts,NULL)); /*config analog input to use counter output as sample clock and continuous samps*/ DAQmxErrChk (DAQmxCfgSampClkTiming (acqTaskHandle, SAMPCLK_CHANNEL, SAMP_RATE, DAQmx_Val_Rising, DAQmx_Val_ContSamps, totSamps)); /*Make buffer size slightly larger than default*/ DAQmxErrChk (DAQmxSetBufferAttribute (acqTaskHandle, DAQmx_Buf_Input_BufSize, totSamps+1000)); //_____Setup counter task_____ DAQmxErrChk (DAQmxCreateTask ("couterOutTask", &ctrTaskHandle)); /*Add counter clock to counter task*/ DAQmxErrChk (DAQmxCreateCOPulseChanFreq (ctrTaskHandle, COUNTER_CHANNEL, "coChannel", DAQmx_Val_Hz,DAQmx_Val_Low, 0, SAMP_RATE, 0.5)); /*config clock for counter output task to generate correct numSamps*/ DAQmxErrChk (DAQmxCfgImplicitTiming (ctrTaskHandle, DAQmx_Val_FiniteSamps, numSamps)); /*Config triggering of counter task*/ DAQmxErrChk (DAQmxCfgDigEdgeStartTrig (ctrTaskHandle, TRIG_CHANNEL, DAQmx_Val_Rising)); DAQmxErrChk (DAQmxSetTrigAttribute (ctrTaskHandle, DAQmx_StartTrig_Retriggerable, TRUE)); return 1; Error: if( DAQmxFailed(error) ) DAQmxGetExtendedErrorInfo(errBuff,2048); retVal = this->stopTasks(); //if( DAQmxFailed(error) ) // MessagePopup("DAQmx Error",errBuff); return 0; }