Exemplo n.º 1
0
int motorControl::motorDisable()
{
	int32       error=0;
	char        errBuff[2048] = {'\0'};
    uInt32      dataDisable=0x00000000;
    int32		written;
    float64 zeroVoltages[3]={0.0,0.0,0.0};
    while(isControlling){
    }
    DAQmxErrChk (DAQmxStartTask(motorEnableHandle));
    DAQmxErrChk (DAQmxStartTask(motorTaskHandle));
    DAQmxErrChk (DAQmxWriteDigitalU32(motorEnableHandle,1,1,10.0,DAQmx_Val_GroupByChannel,&dataDisable,NULL,NULL));
    DAQmxErrChk (DAQmxWriteAnalogF64(motorTaskHandle,1,FALSE,10,DAQmx_Val_GroupByChannel,zeroVoltages,NULL,NULL));
    Sleep(500);
    DAQmxStopTask(motorTaskHandle);
    DAQmxStopTask(motorEnableHandle);
    isControlling = FALSE;
    isWindUp = FALSE;
    live = FALSE;
    isEnable = FALSE;

Error:
	if( DAQmxFailed(error) ){
		printf("DisableMotor Error: %s\n",errBuff);
        DAQmxGetExtendedErrorInfo(errBuff,2048);
        printf("DAQmx Error: %s\n",errBuff);
		DAQmxStopTask(motorEnableHandle);
        DAQmxStopTask(motorTaskHandle);
        DAQmxClearTask(motorEnableHandle);
        DAQmxClearTask(motorTaskHandle);
    }
	return 0;
}
Exemplo n.º 2
0
int motorControl::motorEnable()
{
    uInt32      dataEnable=0x00000001;
    char        errBuff[2048]={'\0'};
    int32       error=0;
    float64 zeroVoltages[3]={0.0,0.0,0.0},zeroVoltage={0.0};
    DAQmxErrChk (DAQmxStartTask(motorEnableHandle));
    DAQmxErrChk (DAQmxStartTask(motorTaskHandle));
    DAQmxErrChk (DAQmxWriteDigitalU32(motorEnableHandle,1,1,10.0,DAQmx_Val_GroupByChannel,&dataEnable,NULL,NULL));
    DAQmxErrChk (DAQmxWriteAnalogF64(motorTaskHandle,1,FALSE,10,DAQmx_Val_GroupByChannel,zeroVoltages,NULL,NULL));
    Sleep(500);
    DAQmxStopTask(motorTaskHandle);
    DAQmxStopTask(motorEnableHandle);
    isEnable = TRUE;
Error:
	if( DAQmxFailed(error) ) {
		DAQmxGetExtendedErrorInfo(errBuff,2048);
        DAQmxStopTask(motorTaskHandle);
		DAQmxClearTask(motorTaskHandle);
        DAQmxStopTask(motorEnableHandle);
		DAQmxClearTask(motorEnableHandle);

		printf("DAQmx Error: %s\n",errBuff);
        printf("Motor enable Error\n");
	}
    return 0;
}
Exemplo n.º 3
0
DAQManager::DAQManager()
{

	stateCount = 8;
	states = new uInt32[stateCount];
	states[0] = 0x8;
	states[1] = 0xC;
	states[2] = 0x4;
	states[3] = 0x6;
	states[4] = 0x2;
	states[5] = 0x3;
	states[6] = 0x1;
	states[7] = 0x9;
	stateNum = 0;
	dataAcquired = 0;
	voltageData = new float64[SAMPLE_COUNT];
#ifdef _WIN32
	DAQmxCreateTask("", &motorTaskHandle);
	DAQmxCreateTask("", &adcTaskHandle);
	DAQmxCreateTask("", &triggerTaskHandle);

	DAQmxCreateDOChan(motorTaskHandle, "Dev1/port0", "", DAQmx_Val_ChanForAllLines);
	DAQmxCreateDOChan(triggerTaskHandle, "Dev1/port1", "", DAQmx_Val_ChanForAllLines);

	DAQmxCreateAIVoltageChan(adcTaskHandle, "Dev1/ai0", "", DAQmx_Val_Cfg_Default, -10.0, 10.0, DAQmx_Val_Volts, NULL);
	DAQmxCfgSampClkTiming(adcTaskHandle, "", SAMPLE_FREQ, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, SAMPLE_COUNT);
	DAQmxCfgDigEdgeStartTrig(adcTaskHandle, "/Dev1/PFI0", DAQmx_Val_Rising);
	DAQmxRegisterEveryNSamplesEvent(adcTaskHandle, DAQmx_Val_Acquired_Into_Buffer, 1000, 0, EveryNCallbackWrapper, this);

	DAQmxStartTask(motorTaskHandle);
	DAQmxStartTask(triggerTaskHandle);

	uInt32 data;
	int32 written;
	data = states[0];
	DAQmxWriteDigitalU32(motorTaskHandle, 1, 1, 10.0, DAQmx_Val_GroupByChannel, &data, &written, NULL);
	data=0x0;
	DAQmxWriteDigitalU32(triggerTaskHandle, 1, 1, 10.0, DAQmx_Val_GroupByChannel, &data, &written, NULL);
#elif __APPLE__
    DAQmxBaseCreateTask("motorTask", &motorTaskHandle);
    DAQmxBaseCreateDOChan(motorTaskHandle, "Dev1/port0", "", DAQmx_Val_ChanForAllLines);
    DAQmxBaseStartTask(motorTaskHandle);

    DAQmxBaseCreateTask("adcTask", &adcTaskHandle);
    DAQmxBaseCreateAIVoltageChan(adcTaskHandle, "Dev1/ai0", "", DAQmx_Val_Cfg_Default, -10.0, 10.0, DAQmx_Val_Volts, NULL);
    DAQmxBaseCfgSampClkTiming(adcTaskHandle,"OnboardClock", SAMPLE_FREQ, DAQmx_Val_Rising, DAQmx_Val_ContSamps, SAMPLE_COUNT);
    DAQmxBaseCfgInputBuffer(adcTaskHandle,0);
    DAQmxBaseStartTask(adcTaskHandle);
    uInt32 data;
    int32 written;
    data = states[0];
    DAQmxBaseWriteDigitalU32(motorTaskHandle, 1, 1, 10.0, DAQmx_Val_GroupByChannel, &data, &written, NULL);
#endif
}
Exemplo n.º 4
0
int microStep(int in)
{
	uInt8 MS1Sig[2];
	uInt8 MS2Sig[2];

	// Pull to zero for active in current controller mode
	switch (in){
	case 1 : // no mirostep
		MS1Sig[0] = 0;	MS1Sig[1] = 0;
		MS2Sig[0] = 0;	MS2Sig[1] = 0;
		break;
	case 2 : // half step
		MS1Sig[0] = 1;	MS1Sig[1] = 1;
		MS2Sig[0] = 0;	MS2Sig[1] = 0;
		break;
	case 4: // quarter step
		MS1Sig[0] = 0;	MS1Sig[1] = 0;
		MS2Sig[0] = 1;	MS2Sig[1] = 1;
		break;
	case 8: // eighth step
		MS1Sig[0] = 1;	MS1Sig[1] = 1;
		MS2Sig[0] = 1;	MS2Sig[1] = 1;
		break;
	default :
		return -1;
	}

	TaskHandle microStep = 0;

	DAQmxCreateTask("MS1", &microStep);
	DAQmxCreateDOChan(microStep, "Dev1/port0/line6", "MS1", DAQmx_Val_ChanForAllLines); // MS1
	DAQmxCfgSampClkTiming(microStep, NULL, 3000.0, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, 2); // Ext. Trig
	DAQmxWriteDigitalLines(microStep, 2, 0, 1000.0, DAQmx_Val_GroupByChannel, MS1Sig, NULL, NULL); // MS1 out 
	DAQmxStartTask(microStep);
	DAQmxWaitUntilTaskDone(microStep, 1.0); // Wait for action to be completed
	DAQmxStopTask(microStep);
	DAQmxClearTask(microStep);

	microStep = 0;

	DAQmxCreateTask("MS2", &microStep);
	DAQmxCreateDOChan(microStep, "Dev1/port0/line7", "MS2", DAQmx_Val_ChanForAllLines); // MS1
	DAQmxCfgSampClkTiming(microStep, NULL, 3000.0, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, 2); // Ext. Trig
	DAQmxWriteDigitalLines(microStep, 2, 0, 1000.0, DAQmx_Val_GroupByChannel, MS2Sig, NULL, NULL); // MS1 out 
	DAQmxStartTask(microStep);
	DAQmxWaitUntilTaskDone(microStep, 1.0); // Wait for action to be completed
	DAQmxStopTask(microStep);
	DAQmxClearTask(microStep);
	
	return 0;
}
Exemplo n.º 5
0
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);
}
Exemplo n.º 6
0
	TaskHandle EXPORT_API EOGSetCallback(UnityCallback uCallback)
	{
		int32       error = 0;
		char        errBuff[2048] = { '\0' };
		//int32       read;
		//float64		data[1];

		if (uCallback) 
		{
			DAQmxErrChk(DAQmxCfgSampClkTiming(taskHandle, "", 240.0, DAQmx_Val_Rising, DAQmx_Val_ContSamps, numSamples));
			DAQmxErrChk(DAQmxRegisterEveryNSamplesEvent(taskHandle, DAQmx_Val_Acquired_Into_Buffer, 1, 0, uCallback, NULL));
			// DAQmxErrChk(DAQmxRegisterEveryNSamplesEvent(taskHandle, DAQmx_Val_Acquired_Into_Buffer, 1000, 0, EveryNSamplesCallback, NULL));
			DAQmxErrChk(DAQmxRegisterDoneEvent(taskHandle, 0, DoneCallback, NULL));
			/*********************************************/
			// DAQmx Start Code
			/*********************************************/
			DAQmxErrChk(DAQmxStartTask(taskHandle));

			return taskHandle;
		}
	Error:
		if (DAQmxFailed(error))
		{
			DAQmxGetExtendedErrorInfo(errBuff, 2048);
			Cleanup();
			printf("DAQmx Error: %s\n", errBuff);
		}

		return 0;
	}
Exemplo n.º 7
0
int motorControl::motorWindUp()
{
    char        errBuff[2048]={'\0'};
    int32       error=0;
    float64 windingUpCmnd[3]={0.5,0.5,0};
    if (isEnable){
        DAQmxErrChk (DAQmxStartTask(motorTaskHandle));
        DAQmxErrChk (DAQmxWriteAnalogF64(motorTaskHandle,1,FALSE,10,DAQmx_Val_GroupByChannel,windingUpCmnd,NULL,NULL));
        Sleep(500);
        isWindUp = TRUE;

        DAQmxStopTask(motorTaskHandle);
        
        printf("Windup Pass.\n");
    }else  printf("Motors must be first enabled prior to winding up.\n");
Error:
	if( DAQmxFailed(error) ) {
		DAQmxGetExtendedErrorInfo(errBuff,2048);
        DAQmxStopTask(motorTaskHandle);
        DAQmxClearTask(motorTaskHandle);
		printf("DAQmx Error: %s\n",errBuff);
        printf("winding up Error\n");
	}
     return 0;
}
Exemplo n.º 8
0
double QxrdNIDAQPlugin::count(int /* chan */, double /* time */)
{
  QMutexLocker lock(&m_Mutex);

  static TaskHandle counterTask = 0;
  int error;
  float64 res = 0;

  if (counterTask == 0) {
    DAQmxErrChk(DAQmxCreateTask("counter", &counterTask));
    DAQmxErrChk(DAQmxCreateCICountEdgesChan(counterTask,"Dev1/ctr2", "", DAQmx_Val_Rising, 0, DAQmx_Val_CountUp));
    DAQmxErrChk(DAQmxSetCICountEdgesTerm(counterTask, "/Dev1/ctr2", "/Dev1/100MHzTimebase"));
    DAQmxErrChk(DAQmxStartTask(counterTask));
  }

  if (counterTask) {
    DAQmxErrChk(DAQmxReadCounterScalarF64(counterTask, 0, &res, NULL));
  }

  return res;

Error:
  DAQmxClearTask(counterTask);
  return res;
}
Exemplo n.º 9
0
int32 Tweezers::TriggerFrames(unsigned int nr)
{
	//DAQmxErrRtn(DAQmxStopTask(DOtaskHandle));
	DAQmxErrRtn(DAQmxCfgImplicitTiming(DOtaskHandle, DAQmx_Val_FiniteSamps, 1));
	DAQmxErrRtn(DAQmxStartTask(DOtaskHandle));
	DAQmxErrRtn(DAQmxWaitUntilTaskDone(DOtaskHandle,-1));
	DAQmxErrRtn(DAQmxStopTask(DOtaskHandle));
}
Exemplo n.º 10
0
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);
    }
}
Exemplo n.º 11
0
int NI6211::startCapot()
{
    int error;
    taskCapot = new TaskHandle;

    /*------ DAQmx Configure Code Reading Task ------*/
    DAQmxErrChk (DAQmxCreateTask("",taskCapot));
    DAQmxErrChk (DAQmxCreateDIChan(*taskCapot,"Equilibreuse/port0/line3","",DAQmx_Val_ChanPerLine));
    DAQmxErrChk (DAQmxStartTask(*taskCapot));
Erreur:
    checkError(error);
    return error;
}
int32 ATIDAQHardwareInterface::ConfigSingleSampleTask( float64 sampleRate,
                                                       int averaging,
                                                       const std::string & deviceName,
                                                       int firstChannel,
                                                       int numChannels,
                                                       int minVoltage,
                                                       int maxVoltage )
{
    int32 retVal; /*the return value*/
    /*we have to use unmanaged c-style strings in here because that's what the NI-DAQmx
        C Library uses*/
    char channelString[WHOLE_LOTTA_CHARACTERS]; /*the channel string, of format "Dev1/ai0:5"*/
    /*set up member data*/
    m_f64SamplingFrequency = sampleRate;
    m_uiAveragingSize = ( averaging > 0 )? averaging : 1; /*averaging must be at least 1*/
    m_sDeviceName = deviceName;
    m_uiFirstChannel = firstChannel;
    m_uiNumChannels = numChannels;
    m_iMinVoltage = minVoltage;
    m_iMaxVoltage = maxVoltage;

    unsigned int numSamplesPerChannel = m_uiAveragingSize; /*the number of samples per channel that
                                                                                                                   daqmx is configured with*/
    /*in a perfect world, NI-DAQmx would allow us to set up single scan acquisitions, but they don't.
        even if we were to make the single sample task a finite sample task, they still require you to use
        at least 2 samples per channel.  Therefore, we pass daqmx a number of samples per channel that it
        will accept, and then set up our task to only read the most recent samples*/
    if ( MIN_SAMPLES_PER_CHANNEL > numSamplesPerChannel ) numSamplesPerChannel = MIN_SAMPLES_PER_CHANNEL;

    ati_Channel_Name_Format( channelString, m_sDeviceName );	/* Format the channel name for niDAQmx */

    /*if the following confuses you, I suggest you read the NI-DAQmx C Reference Help, included
        with NI-DAQmx*/
    StopCollection(); /*stop currently running task*/
    /*if any function fails (returns non-zero), don't execute any more daqmx functions*/
    /*create the daqmx task*/
    if( !( retVal = DAQmxCreateTask( "", m_thDAQTask ) ) )
        /*add the analog input channels to the task - july.22.2005 - ss - now uses m_iConnectionMode*/
        if( !( retVal = DAQmxCreateAIVoltageChan( *m_thDAQTask, channelString, "", m_iConnectionMode,
                                                  m_iMinVoltage, m_iMaxVoltage, DAQmx_Val_Volts, NULL ) ) )
            /*set up timing for the task*/
            if( !( retVal = DAQmxCfgSampClkTiming( *m_thDAQTask, NULL, m_f64SamplingFrequency,
                                                   DAQmx_Val_Rising, DAQmx_Val_ContSamps, numSamplesPerChannel ) ) )
                /*set read position relative to next sample to be read*/
                if( !( retVal = DAQmxSetReadRelativeTo( *m_thDAQTask, DAQmx_Val_MostRecentSamp ) ) )
                    /*offset of -1 from the next sample, meaning we read the most recent sample*/
                    if( !( retVal = DAQmxSetReadOffset( *m_thDAQTask, 0 ) ) )
                        /*start the task*/
                        retVal = DAQmxStartTask( *m_thDAQTask );
    return retVal;
}
Exemplo n.º 13
0
/******************************************************************************
**
** Démarage de la tache d'acquisition de la vitesse.
**
******************************************************************************/
int NI6211::startSpeed()
{
    int error;
    taskFreq = new TaskHandle;

    /*------ DAQmx Configure Code Reading Task ------*/
    DAQmxErrChk (DAQmxCreateTask("",taskFreq));
    DAQmxErrChk (DAQmxCreateCIFreqChan(*taskFreq,"/Equilibreuse/ctr0","",1,200000,DAQmx_Val_Hz,DAQmx_Val_Rising,DAQmx_Val_LowFreq1Ctr,1,1,""));
    DAQmxErrChk (DAQmxSetCIFreqTerm(*taskFreq,"","/Equilibreuse/PFI2"))
    DAQmxErrChk (DAQmxStartTask(*taskFreq));
Erreur:
    checkError(error);
    return error;
}
Exemplo n.º 14
0
void YDIR(int in)
{
	TaskHandle YDir = 0;
	uInt8 dirSig[2] = { in, in };

	DAQmxCreateTask("YDir", &YDir);
	DAQmxCreateDOChan(YDir, "Dev1/port0/line3", "YDir", DAQmx_Val_ChanForAllLines); // Ydirection
	DAQmxCfgSampClkTiming(YDir, NULL, 3000.0, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, 2); // Int. Trig
	DAQmxWriteDigitalLines(YDir, 2, 0, 1000.0, DAQmx_Val_GroupByChannel, dirSig, NULL, NULL); // turn Off 
	DAQmxStartTask(YDir);
	DAQmxWaitUntilTaskDone(YDir, 1.0); // Wait for action to be completed
	DAQmxStopTask(YDir);
	DAQmxClearTask(YDir);
}
Exemplo n.º 15
0
void YON(int in)
{
	TaskHandle YOn = 0;	
	uInt8 onSig[2] = { in, in };

	DAQmxCreateTask("YON", &YOn);
	DAQmxCreateDOChan(YOn, "Dev1/port0/line5", "YON", DAQmx_Val_ChanForAllLines); // Yon	
	DAQmxCfgSampClkTiming(YOn, NULL, 3000.0, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, 2); // Ext. Trig
	DAQmxWriteDigitalLines(YOn, 2, 0, 1000.0, DAQmx_Val_GroupByChannel, onSig, NULL, NULL); // turn Off 
	DAQmxStartTask(YOn);
	DAQmxWaitUntilTaskDone(YOn, 1.0); // Wait for action to be completed
	DAQmxStopTask(YOn);
	DAQmxClearTask(YOn);
}
Exemplo n.º 16
0
int main(void)
{
	int32       error=0;
	TaskHandle  taskHandle=0;
	int32       read;
	float64     data[1000];
	char        errBuff[2048]={'\0'};
	int	i;

	/*********************************************/
	// DAQmx Configure Code
	/*********************************************/
	DAQmxErrChk (DAQmxCreateTask("",&taskHandle));
	DAQmxErrChk (DAQmxCreateAIVoltageChan(taskHandle,"Dev1/ai0","",DAQmx_Val_Cfg_Default,-10.0,10.0,DAQmx_Val_Volts,NULL));
	DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle,"",10000.0,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,1000));

	/*********************************************/
	// DAQmx Start Code
	/*********************************************/
	DAQmxErrChk (DAQmxStartTask(taskHandle));

	/*********************************************/
	// DAQmx Read Code
	/*********************************************/
	DAQmxErrChk (DAQmxReadAnalogF64(taskHandle,1000,10.0,DAQmx_Val_GroupByChannel,data,1000,&read,NULL));

	printf("Acquired %d points\n",read);

	for (i = 0; i < 1000; i++) {
		printf ("data[%d] = %f\n", i, data[i]);
	}

Error:
	if( DAQmxFailed(error) )
		DAQmxGetExtendedErrorInfo(errBuff,2048);
	if( taskHandle!=0 )  {
		/*********************************************/
		// DAQmx Stop Code
		/*********************************************/
		DAQmxStopTask(taskHandle);
		DAQmxClearTask(taskHandle);
	}
	if( DAQmxFailed(error) )
		printf("DAQmx Error: %s\n",errBuff);
	printf("End of program, press Enter key to quit\n");
	getchar();
	return 0;
}
Exemplo n.º 17
0
BOOL CForceChartDlg::DAQ(CString changeDeviceName, short changeFirstChannel)
{
	TaskHandle  taskHandle = 0;
	int32       read;
	CString cstrChannelList;
	cstrChannelList.Format( _T("/ai%d"), changeFirstChannel );
	DAQmxCreateTask("AAencoderTask", &taskHandle);
	DAQmxCreateAIVoltageChan(taskHandle, changeDeviceName+cstrChannelList, "AAencoderChannel", DAQmx_Val_RSE, 0, 5, DAQmx_Val_Volts, NULL);
	//UpdateData(TRUE);
	DAQmxCfgSampClkTiming(taskHandle, "OnboardClock", 100, DAQmx_Val_Rising, DAQmx_Val_ContSamps, 20);
	//UpdateData(TRUE);
	DAQmxStartTask(taskHandle);
	DAQmxReadAnalogF64(taskHandle, 10, 0.2, DAQmx_Val_GroupByChannel, G0, 10, &read, NULL);
	DAQmxStopTask(taskHandle);
	DAQmxClearTask(taskHandle);
	return TRUE;
}
Exemplo n.º 18
0
bool create_DO_channel(uInt32 port)
{
	#ifdef _USE_REAL_KIT_
		char taskName[100];
		char portName[100];
		TaskHandle task_handle;	
		sprintf(taskName,"task_di__%d",port);
		sprintf(portName,"Dev3/port%d",port);   
		DAQmxCreateTask(taskName,&task_handle);
		DAQmxCreateDOChan(task_handle,portName,"",DAQmx_Val_ChanForAllLines);
		DAQmxStartTask(task_handle);		
		tasks[port]=task_handle;
#else
		return sim_create_DO_channel(port);
#endif
   return(true);	
}
Exemplo n.º 19
0
/******************************************************************************
**
** Fonction de démarage du comptage de la voie A du compteur incrémentale.
**
******************************************************************************/
bool NI6211::startCounter()
{
    int32       error=0;
    taskCounter = new TaskHandle;

    /*------ DAQmx Configure Code Reading Task ------*/
    DAQmxErrChk (DAQmxCreateTask("",taskCounter));
    DAQmxErrChk (DAQmxCreateCIAngEncoderChan(*taskCounter,"Equilibreuse/ctr0","",DAQmx_Val_X1,TRUE,999,DAQmx_Val_AHighBLow,DAQmx_Val_Ticks,1000,0,NULL));
    DAQmxErrChk (DAQmxSetArmStartTrigType(*taskCounter,DAQmx_Val_DigEdge));
    DAQmxErrChk (DAQmxSetDigEdgeArmStartTrigSrc(*taskCounter,"/Equilibreuse/PFI2"));

    /*------ DAQmx Start Code ------*/
    DAQmxErrChk (DAQmxStartTask(*taskCounter));

Erreur:
    checkError(error);
    return 0;
}
Exemplo n.º 20
0
/******************************************************************************
**
** Démarage de la tache d'acquisition sur la voie passé en paramètre.
**
******************************************************************************/
int NI6211::startAquisition(char* _Voie)
{
    int32       error=0;
    taskRead = new TaskHandle;


    /*------ DAQmx Configure Code Reading Task ------*/
    DAQmxErrChk (DAQmxCreateTask("",taskRead));
    DAQmxErrChk (DAQmxCreateAIVoltageChan(*taskRead,_Voie,"",DAQmx_Val_Diff,-0.2,0.2,DAQmx_Val_Volts,NULL));
    //DAQmxErrChk (DAQmxCreateAIVoltageChan(*taskRead,_VoieO,"",DAQmx_Val_Diff,-0.2,0.2,DAQmx_Val_Volts,NULL));
    DAQmxErrChk (DAQmxCfgSampClkTiming(*taskRead,"/Equilibreuse/PFI0",1000,DAQmx_Val_Rising,DAQmx_Val_ContSamps,1000));
    DAQmxErrChk (DAQmxCfgDigEdgeStartTrig(*taskRead,"/Equilibreuse/PFI2",DAQmx_Val_Rising));

    /*------ DAQmx Start Code ------*/
    DAQmxErrChk (DAQmxStartTask(*taskRead));
Erreur:
    checkError(error);
    return error;
}
Exemplo n.º 21
0
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;
}
Exemplo n.º 22
0
int32 Tweezers::SetCurrent(float current)
{
	// init output data array
	float64 out_data[1];
	out_data[0] = current;

	// setup HTSP timing and deactivate onboard memory
	DAQmxErrRtn(DAQmxCfgSampClkTiming(AOtaskHandle,"",Srate_HTSP,DAQmx_Val_Rising,DAQmx_Val_HWTimedSinglePoint,1));

	// start task
	DAQmxErrRtn(DAQmxStartTask(AOtaskHandle));

	// write single sample
	DAQmxErrRtn(DAQmxWriteAnalogF64(AOtaskHandle,1,true,-1,DAQmx_Val_GroupByChannel,out_data,&written,NULL));

	// stop task
	DAQmxErrRtn(DAQmxStopTask(AOtaskHandle));

	residual = (abs(current) > abs(residual) ? current : residual);
}
Exemplo n.º 23
0
void TriggerFrames(unsigned int nr, double extime)
{

	char        errBuff[2048];
//	int32       error;

	TaskHandle DOtaskHandle;
	DAQmxCreateTask("DO",&DOtaskHandle);
	//cerr<<"sending trigger pulse: "<<extime*1E-3<<" secs!\n";
	DAQmxCreateCOPulseChanTime(DOtaskHandle,"Dev1/Ctr0","",DAQmx_Val_Seconds,DAQmx_Val_Low,0.0,extime*1E-3,extime*1E-3);
	//DAQmxCfgImplicitTiming(DOtaskHandle, DAQmx_Val_ContSamps, 1);
	DAQmxCfgImplicitTiming(DOtaskHandle, DAQmx_Val_FiniteSamps, 1);
	DAQmxStartTask(DOtaskHandle);
	DAQmxWaitUntilTaskDone(DOtaskHandle,-1);
	DAQmxStopTask(DOtaskHandle);
	DAQmxClearTask(DOtaskHandle);

	DAQmxGetExtendedErrorInfo(errBuff,2048);
	cerr<<errBuff;
}
Exemplo n.º 24
0
/******************************************************************************
**
** 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;
}
int32 ATIDAQHardwareInterface::ConfigBufferTask( float64 sampleRate, int averaging,const std::string &deviceName, int firstChannel,
                                                 int numChannels, int minVoltage, int maxVoltage, int bufferSize )
{
    int32 retVal; /*the return value*/
    /*we have to use unmanaged c-style strings in here because that's what the NI-DAQmx
        C Library uses*/
    char channelString[1024]; /*the channel string, of format "Dev1/ai0:5"*/
    /*set up member data*/
    m_f64SamplingFrequency = sampleRate;
    m_uiAveragingSize = ( averaging > 0 )? averaging : 1; /*averaging must be at least 1*/
    m_sDeviceName = deviceName;
    m_uiFirstChannel = firstChannel;
    m_uiNumChannels = numChannels;
    m_iMinVoltage = minVoltage;
    m_iMaxVoltage = maxVoltage;
    m_ulBufferedSize = bufferSize;
    unsigned int numSamplesPerChannel = m_uiAveragingSize * m_ulBufferedSize; /*the number of samples per channel that
                                                                                                                   daqmx is configured with*/
    /*NI-DAQmx requires a minimum number of samples per channel*/
    if ( MIN_SAMPLES_PER_CHANNEL > numSamplesPerChannel ) numSamplesPerChannel = MIN_SAMPLES_PER_CHANNEL;

    ati_Channel_Name_Format( channelString, m_sDeviceName );	/* Format the channel name for niDAQmx */

    /*if the following confuses you, I suggest you read the NI-DAQmx C Reference Help, included
        with NI-DAQmx*/
    StopCollection(); /*stop any currently running task*/
    /*if any function fails (returns non-zero), don't execute any more daqmx functions*/
    /*create the daqmx task*/
    if( !( retVal = DAQmxCreateTask( "", m_thDAQTask ) ) )
        /*add the analog input channels to the task - july.22.2005 - ss - now uses m_iConnectionMode*/
        if( !( retVal = DAQmxCreateAIVoltageChan( *m_thDAQTask, channelString, "", m_iConnectionMode,
                                                  m_iMinVoltage, m_iMaxVoltage, DAQmx_Val_Volts, NULL ) ) )
            /*set up timing for the task*/
            if( !( retVal = DAQmxCfgSampClkTiming( *m_thDAQTask, NULL, m_f64SamplingFrequency,
                                                   DAQmx_Val_Rising, DAQmx_Val_ContSamps, numSamplesPerChannel ) ) )
                /*start the task*/
                retVal = DAQmxStartTask( *m_thDAQTask );
    return retVal;
}
Exemplo n.º 26
0
void moveXStage(int steps, uInt8 clockSig[])
{
	int bits = steps * 2;

	TaskHandle	XClockOut = 0;
	uInt8 *signal = new uInt8[bits];
	for (int i = 0; i < bits; i += 2) {
		signal[i] = clockSig[0];
		signal[i + 1] = clockSig[1];
	}

	DAQmxCreateTask("X", &XClockOut);
	DAQmxCreateDOChan(XClockOut, "Dev1/port0/line0", "X", DAQmx_Val_ChanForAllLines); // Xmotor
	DAQmxCfgSampClkTiming(XClockOut, NULL, motorSpeed, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, bits); // Ext. Trig
	DAQmxWriteDigitalLines(XClockOut, bits, 0, 1000.0, DAQmx_Val_GroupByChannel, signal, NULL, NULL); // X Motor signal	
	DAQmxStartTask(XClockOut); // Pulse motor
	DAQmxWaitUntilTaskDone(XClockOut, 1000.0); // Wait for action to be completed
	DAQmxStopTask(XClockOut);
	DAQmxClearTask(XClockOut);

	delete signal;
}
Exemplo n.º 27
0
int 
StartStartle(void)
{

	int			i=0;
	int32   	written;


	/*********************************************/
	// DAQmx Write Code
	/*********************************************/
	DAQmxWriteAnalogF64(startleDaqHandle,400,0,10.0,DAQmx_Val_GroupByChannel,gStartleData,&written,NULL);

	/*********************************************/
	// DAQmx Start Code
	/*********************************************/
	DAQmxStartTask(startleDaqHandle);
	/*********************************************/
	// DAQmx Wait Code
	/*********************************************/
	//DAQmxWaitUntilTaskDone(startleDaqHandle,10.0);
	return 0;
}
Exemplo n.º 28
0
double DAQManager::getVoltage(){

    float64 sum;
    int32 read;
#ifdef _WIN32
	DAQmxStartTask(adcTaskHandle);
	trigger();
	while(!dataAcquired);
	dataAcquired=0;
	DAQmxStopTask(adcTaskHandle);
#elif __APPLE__
    /*bool32 isDone;
    DAQmxBaseIsTaskDone(adcTaskHandle,&isDone);*/
    DAQmxBaseReadAnalogF64(adcTaskHandle, SAMPLE_COUNT, 10.0, DAQmx_Val_GroupByScanNumber, data, SAMPLE_COUNT, &read, NULL);
    /*while(!isDone);
    DAQmxBaseStopTask(adcTaskHandle);
    DAQmxBaseClearTask(adcTaskHandle);*/
#endif
    sum = 0;
    for (int i = 0; i < SAMPLE_COUNT; ++i){
        sum += voltageData[i];
    }
    return sum / SAMPLE_COUNT;
}
Exemplo n.º 29
0
int SetDaqStart()
{
    int32 error = 0;
    char errBuff[2048];
    int32 read;

    epicsPrintf("**** DAQmxStartTask ****\n");

    DAQmxErrChk(DAQmxStartTask(daq6220pvt.taskHandle));

    return 0;
Error:
    if( DAQmxFailed(error) )
        DAQmxGetExtendedErrorInfo(errBuff,2048);

    if( daq6220pvt.taskHandle!=0 ) {
        DAQmxStopTask(daq6220pvt.taskHandle);
        DAQmxClearTask(daq6220pvt.taskHandle);
    }
    if( DAQmxFailed(error) )
        epicsPrintf("DAQmx Error(6220): %s\n",errBuff);

    return -1;
}
Exemplo n.º 30
0
void QxrdNIDAQPlugin::triggerAnalogWaveform()
{
  QMutexLocker lock(&m_Mutex);
//  printf("triggerAnalogWaveform()\n");

  int error;

  if (m_AOTaskHandle) {
    //    DAQmxErrChk(
    //      DAQmxWaitUntilTaskDone(m_AOTaskHandle, -1)
    //    )

    DAQmxErrChk(
          DAQmxStopTask(m_AOTaskHandle)
          );

    DAQmxErrChk(
          DAQmxStartTask(m_AOTaskHandle)
          );
  }

Error:
  return;
}