Esempio n. 1
0
int main(int argc, char *argv[])
{
	int32		error=0;
	TaskHandle	taskHandle=0;
	uInt8		data[100];
	char		errBuff[2048]={'\0'};
	int32		i;
	char		ch;

	DAQmxErrChk (Configure_ReadDigChan("Dev1/port0/line0:7",&taskHandle));
	DAQmxErrChk (Start_ReadDigChan(taskHandle));
	DAQmxErrChk (Read_ReadDigChan(taskHandle,data,100));

Error:
	if( DAQmxFailed(error) )
		DAQmxGetExtendedErrorInfo(errBuff,2048);
	if( taskHandle!=0 )
		Stop_ReadDigChan(taskHandle);
	if( DAQmxFailed(error) )
		printf("DAQmx Error: %s\n",errBuff);
	else
		// assuming 8 channels acquired
		for(i=0;i<8;++i)
			printf("Data acquired, channel %d: 0x%X\n",i,data[i]);
	printf("End of program, press any key to quit\n");
	while( !_kbhit() ) {}
	ch = _getch();
return 0;
}
Esempio n. 2
0
int SetDaqAbort()
{
    int32 error = 0;
    char errBuff[2048];

    epicsPrintf("**** DAQmx Task Abort****\n");

    DAQmxErrChk(DAQmxStopTask(daq6220pvt.taskHandle));
    DAQmxErrChk(DAQmxClearTask(daq6220pvt.taskHandle));

    daq6220pvt.status = DAQ_STATUS_STOP;

    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;
}
Esempio n. 3
0
/******************************************************************************
**
** Fonction de vérification d'erreur
** Le texte décrivant l'erreur est noté dans le débug.
**
******************************************************************************/
void NI6211::checkError(int _error)
{
    char        errBuff[2048]={'\0'};

    if( DAQmxFailed(_error) )
        DAQmxGetExtendedErrorInfo(errBuff,2048);
    if( DAQmxFailed(_error) )
        printf("DAQmx Error: %s\n",errBuff);
}
Esempio n. 4
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;
}
Esempio n. 5
0
	int EXPORT_API EOGStopTask(TaskHandle taskHandle)
	{
		int32       error = 0;
		char		errBuff[2048] = { '\0' };

		if (taskHandle != 0)
		{
			DAQmxErrChk(DAQmxStopTask(taskHandle));
			DAQmxClearTask(taskHandle);
			return 1;
		}
		else
		{
			return 2;
		}
		

	Error:

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

		return 0;
	}
void DexNiDaqTargets::Quit( void ) {

	int32 error_code;
	if( taskHandle!=0 )  {
		// I think that the task stops itself after the read, but I'm not sure.
		// In any case, it doesn't seem to hurt to do this.
		error_code = DAQmxStopTask(taskHandle);
		if( DAQmxFailed( error_code )) ReportNiDaqError();
		// I don't know what happens if you don't clear a task before leaving,
		// but the NI examples says to do it, so I do it.
		error_code = DAQmxClearTask(taskHandle);
		if( DAQmxFailed( error_code ) ) ReportNiDaqError();
	}
	screen_targets->Quit();

}
Esempio n. 7
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;
}
Esempio n. 8
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;
}
Esempio n. 9
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;
	}
Esempio n. 10
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;
}
Esempio n. 11
0
int main (int argc, char *argv[])
{
    // Task parameters
    int32       error = 0;
    TaskHandle  taskHandle = 0;
    char        errBuff[2048]= {'\0'};
    int32       i;

    // Channel parameters
    char        chan[] = "Dev1/ai0";
    float64     min = -10.0;
    float64     max = 10.0;

    // Timing parameters
    char        source[] = "OnboardClock";
    uInt64      samplesPerChan = 100;
    float64     sampleRate = 1200.0;

    // Data read parameters
#define     bufferSize (uInt32)1000
    float64     data[bufferSize];
    int32       pointsToRead = -1;
    int32       pointsRead;
    float64     timeout = 10.0;

    while(1) {
        printf("new task\n\n");
        DAQmxErrChk (DAQmxBaseCreateTask ("", &taskHandle));
        DAQmxErrChk (DAQmxBaseCreateAIVoltageChan (taskHandle, chan, "", DAQmx_Val_NRSE, min, max, DAQmx_Val_Volts, NULL));
        DAQmxErrChk (DAQmxBaseCfgSampClkTiming (taskHandle, source, sampleRate, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, samplesPerChan));

        DAQmxErrChk (DAQmxBaseStartTask (taskHandle));

        DAQmxErrChk (DAQmxBaseReadAnalogF64 (taskHandle, pointsToRead, timeout, 0, data, bufferSize, &pointsRead, NULL));

        printf("pointsRead: %d\n",pointsRead);
        // Just print out the first 10 points
        for (i = 0; i < 8; ++i) {
            printf ("%f\n", data[i]);
        }
        DAQmxBaseStopTask (taskHandle);
        DAQmxBaseClearTask (taskHandle);
    }

Error:
    if (DAQmxFailed (error))
        DAQmxBaseGetExtendedErrorInfo (errBuff, 2048);

    if (taskHandle != 0)
    {
        DAQmxBaseStopTask (taskHandle);
        DAQmxBaseClearTask (taskHandle);
    }

    if (error)
        printf ("DAQmxBase Error %d: %s\n", error, errBuff);

    return 0;
}
Esempio n. 12
0
void errorCheck(JNIEnv *env, jobject obj, int32 error) {
    if (DAQmxFailed(error)) {
        char errBuff[2048] = {'\0'};
        DAQmxGetExtendedErrorInfo(errBuff, 2048);
        env->ThrowNew(env->FindClass("java/lang/Exception"), errBuff);
        printf("DAQmx Error: %s\n", errBuff);
    }
}
void ECmx(int32 error){
  char errBuff[2048];
  if( DAQmxFailed(error) ){
    std::cout << "Caught a DAQmx error..." << std::endl;
    fflush(stdout);
    DAQmxGetExtendedErrorInfo(errBuff,2048);
    std::cout << "util.cpp saw the daqmx error num: " << error << " with message: " << errBuff << std::endl;
    fflush(stdout);
  }else{
    //    std::cout << "No daqmx error." << std::endl;
  }
}
Esempio n. 14
0
int NiPci6220Config()
{
    int32 error = 0;
    char errBuff[2048];

    daq6220pvt.sampsPerChan = (uInt64)((daq6220pvt.t1 - daq6220pvt.t0) * daq6220pvt.rate);

    epicsPrintf("**** Initialize Task 6220 ****\n");
    epicsPrintf("**** 6220 : sampsPerChan = %d****\n", daq6220pvt.sampsPerChan);
    DAQmxErrChk(DAQmxCreateTask("", &daq6220pvt.taskHandle));
    DAQmxErrChk(DAQmxCreateAIVoltageChan(daq6220pvt.taskHandle, "Dev3/ai0:15","", daq6220pvt.terminalConfig, -10.0, 10.0, DAQmx_Val_Volts, NULL));

    if(daq6220pvt.extMode == 1) {
        DAQmxErrChk(DAQmxCfgSampClkTiming(daq6220pvt.taskHandle, "/Dev3/PFI7", daq6220pvt.rate, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, daq6220pvt.sampsPerChan));
    }
    else {
        DAQmxErrChk(DAQmxCfgSampClkTiming(daq6220pvt.taskHandle, "", daq6220pvt.rate, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, daq6220pvt.sampsPerChan));
    }

    if(daq6220pvt.trigMode == 1) {
        DAQmxErrChk (DAQmxCfgDigEdgeStartTrig(daq6220pvt.taskHandle,"/Dev3/PFI0",DAQmx_Val_Rising));
        DAQmxErrChk (DAQmxRegisterEveryNSamplesEvent(daq6220pvt.taskHandle,DAQmx_Val_Acquired_Into_Buffer,daq6220pvt.sampsPerChan,0,EveryNCallback,NULL));
        DAQmxErrChk (DAQmxRegisterDoneEvent(daq6220pvt.taskHandle,0,DoneCallback,NULL));
    }

    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;
}
static int32 Guarded_DAQmx_( int32 error, const char* expression, const char* file, const int line, const char* function )
{	
  char  errBuff[UTIL_NIDAQ_ERROR_BUFFER_SIZE]={'\0'},      
        errBuffEx[UTIL_NIDAQ_ERROR_BUFFER_SIZE]={'\0'};
  if( error == DAQmxSuccess)
	  return error;
  DAQmxGetErrorString(error, errBuff ,UTIL_NIDAQ_ERROR_BUFFER_SIZE);  // get error message
  DAQmxGetExtendedErrorInfo(errBuffEx,UTIL_NIDAQ_ERROR_BUFFER_SIZE);  // get error message
  mexPrintf( "(%s:%d) %s\n\t%s\n\t%s\n\t%s\n",file, line, function, (expression), errBuff, errBuffEx );// report
  if( DAQmxFailed(error) )
    mexErrMsgTxt("DAQmx call failed.");
  return error;
}
Esempio n. 16
0
int32 CVICALLBACK EveryNCallback(TaskHandle taskHandle, int32 everyNsamplesEventType, uInt32 nSamples, void *callbackData)
{
    int32 error = 0;
    char errBuff[2048];
    int32 read;

    int32 sampsPerChan = daq6220pvt.sampsPerChan;
    int32 buff_size = daq6220pvt.sampsPerChan*16;

    int   fd;

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

    DAQmxErrChk(DAQmxReadAnalogF64(daq6220pvt.taskHandle, sampsPerChan, 10.0, DAQmx_Val_GroupByChannel, daq6220pvt.data,
                                     buff_size, &read, NULL));

    fd = open(DATAFILE_6220, O_WRONLY | O_CREAT);
    write(fd, daq6220pvt.data, buff_size*8);
    close(fd);

    epicsPrintf("**** File Save Byte : %d ****\n", buff_size*8);

    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;
}
Esempio n. 17
0
int
DoneStartle(void)
{
	if( startleDaqHandle!=0 ) {
		/*********************************************/
		// DAQmx Stop Code
		/*********************************************/
		DAQmxStopTask(startleDaqHandle);
		DAQmxClearTask(startleDaqHandle);
	}
	if( DAQmxFailed(error) )
		printf("DAQmx Error: %s\n",errBuff);
Error:
    return 0;
}
Esempio n. 18
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;
}
Esempio n. 19
0
void DexNiDaqTargets::Initialize( void ) {


	char channel_range[32];
	int32 error_code;

	// Define the channels to be acquired.
	// NI-DAQ uses this string based method to select channels. 
	// We need 23 bits to cover the horizontal and vertical channels,
	//  so we need 3 8-bit ports.
	sprintf( channel_range, "Dev1/port0:2" );

	// Initialize the ports for digital output.
	error_code = DAQmxCreateTask("",&taskHandle);
	if( DAQmxFailed( error_code ) ) ReportNiDaqError();
	// Set to treat all digital lines as a single multi-bit channel..
	error_code = DAQmxCreateDOChan(taskHandle, channel_range, "", DAQmx_Val_ChanForAllLines );
	if( DAQmxFailed( error_code ) ) ReportNiDaqError();
	// Here we don't set a clock. The read will read all the channels once as quickly as possible.

	// Initialize the screen targets that we run in parallel.
	screen_targets->Initialize();

}
Esempio n. 20
0
int32 CVICALLBACK DoneCallback(TaskHandle taskHandle, int32 status, void *callbackData)
{
	int32   error=0;
	char    errBuff[2048]={'\0'};

	// Check to see if an error stopped the task.
	DAQmxErrChk2 ("Status", status);

Error:
	if( DAQmxFailed(error) ) {
		DAQmxGetExtendedErrorInfo(errBuff,2048);
		DAQmxClearTask(taskHandle);
		printf("DAQmx Error: %s\n",errBuff);
	}
	return 0;
}
Esempio n. 21
0
	int DAQmxErrChk(int32 rueckgabeWert) { 	//Fehlerbehandlung
		char         errBuff[2048];
	
		if( DAQmxFailed(rueckgabeWert) ) { 
			DAQmxBaseGetExtendedErrorInfo (errBuff, 2048);
			printf ("DAQmxBase Error %ld: %s\n", rueckgabeWert, errBuff);
		
			DAQmxBaseResetDevice ("Dev1");
		
			if (exitBeiFehler) {
				printf("\nACHTUNG: Programm wurde wegen eines Fehlers beendet!\n");
				exit(1);
			}
			return 1;
		}
		return 0; 
	}
Esempio n. 22
0
	TaskHandle EXPORT_API EOGStartTask()
	{
		int32       error = 0;
		char        errBuff[2048] = { '\0' };

		/*********************************************/
		// DAQmx Configure Code
		/*********************************************/
		DAQmxErrChk(DAQmxCreateTask("", &taskHandle));
		return taskHandle;
		//return 1;

	Error:
		if (DAQmxFailed(error))
		{
			DAQmxGetExtendedErrorInfo(errBuff, 2048);
			Cleanup();
			printf("DAQmx Error: %s\n", errBuff);
		}
		return 0;
	}
Esempio n. 23
0
void QxrdNIDAQPlugin::errorCheck(const char* file, int line, int err)
{
  if (DAQmxFailed(err)) {
    int sz = DAQmxGetErrorString(err, NULL, 0);

    if (sz > 0) {
      char *buff = (char*) malloc(sz);

      if (DAQmxGetErrorString(err, buff, sz) == 0) {
        if (m_ErrorOutput &&
            QMetaObject::invokeMethod(m_ErrorOutput, "printMessage", Qt::QueuedConnection,
                                      Q_ARG(QString, tr("%1:%2 NI-DAQ Error %3 : %4").arg(file).arg(line).arg(err).arg(buff)))) {
        } else {
          printf("%s:%d NI-DAQ Error %d : %s\n", file, line, err, buff);
        }
      }

      free(buff);
    }
  }
}
Esempio n. 24
0
	float64 EXPORT_API *EOGReturnData(TaskHandle taskHandle)
	//int32 EXPORT_API *EOGReturnData(TaskHandle taskHandle)
	{
		float64		*ret = new float64[2];
		//int32		*ret = new int32[2];
		int32       error = 0;
		int32       read;
		char        errBuff[2048] = { '\0' };

		/*********************************************/
		// DAQmx Read Code
		/*********************************************/

		DAQmxErrChk(DAQmxReadAnalogF64(taskHandle, numSamples, 10.0, DAQmx_Val_GroupByChannel, data, 2, &read, NULL));
		// DAQmxErrChk(DAQmxReadAnalogF64(taskHandle, 1000, 10.0, DAQmx_Val_GroupByScanNumber, data, 1000, &read, NULL));
		// now call the callback we have set and send the data
		
		//ret[0] = 4.02;
		//ret[1] = -2.34;

		if (read > 0) {		
			for (int n = 0; n < 2; n++)
			{
				ret[n] = data[n];
			}	
		}

		return ret;

	Error:
		if (DAQmxFailed(error))
		{
			DAQmxGetExtendedErrorInfo(errBuff, 2048);
			Cleanup();
			printf("DAQmx Error: %s\n", errBuff);
		}
		return 0;
	}
Esempio n. 25
0
int32 CVICALLBACK DoneCallback(TaskHandle taskHandle, int32 status, void *callbackData)
{
    int32   error=0;
    char    errBuff[2048]={'\0'};
    DaqQueueData  queueData;

    printf("Read Done!!!\n");
    DAQmxErrChk (status);

    DAQmxErrChk(DAQmxStopTask(daq6220pvt.taskHandle));

    daq6220pvt.status = DAQ_STATUS_STOP;

    queueData.opcode = OP_CODE_DAQ_MDSPLUS;
    epicsMessageQueueSend(daq6220pvt.DaqQueueId, (void *)&queueData, sizeof(DaqQueueData));
Error:
    if( DAQmxFailed(error) ) {
        DAQmxGetExtendedErrorInfo(errBuff,2048);
        DAQmxClearTask(daq6220pvt.taskHandle);
        printf("DAQmx Error(6220): %s\n",errBuff);
    }
    return -1;
}
Esempio n. 26
0
	// when I tried to set the channels from c#, first channel set fine, but second one gets error. no freaking idea, so hardcoded it.
	//int EXPORT_API EOGSetChannel(const char *channel)
	TaskHandle EXPORT_API EOGSetChannel()
	{
		int32       error = 0;
		char        errBuff[2048] = { '\0' };

		/*********************************************/
		// DAQmx Configure Code
		/*********************************************/
		DAQmxErrChk(DAQmxCreateAIVoltageChan(taskHandle, "Dev1/ai3", "", DAQmx_Val_Cfg_Default, -5.0, 5.0, DAQmx_Val_Volts, NULL));
		DAQmxErrChk(DAQmxCreateAIVoltageChan(taskHandle, "Dev1/ai4", "", DAQmx_Val_Cfg_Default, -5.0, 5.0, DAQmx_Val_Volts, NULL));
		// DAQmxErrChk(DAQmxCreateAIVoltageChan(taskHandle, channel, "", DAQmx_Val_Cfg_Default, -5.0, 5.0, DAQmx_Val_Volts, NULL));
		
		return taskHandle;
		//return 1;

	Error:
		if (DAQmxFailed(error))
		{
			DAQmxGetExtendedErrorInfo(errBuff, 2048);
			Cleanup();
			printf("DAQmx Error: %s\n", errBuff);
		}
		return 0;
	}
Esempio n. 27
0
int32 CVICALLBACK EveryNCallback6220(TaskHandle taskHandle, int32 everyNsamplesEventType, uInt32 nSamples, void *callbackData)
{
    int32 error = 0;
    char errBuff[2048];
    int32 read;

    int32 sampsPerChan = daq6220pvt.rate;
    int32 buff_size = daq6220pvt.rate*16;

    int	i, j, ind;
    float64        *data;

    data = (float64 *)malloc(sizeof(float64)*buff_size);

    DAQmxErrChk(DAQmxReadAnalogF64(daq6220pvt.taskHandle, sampsPerChan, 10.0, DAQmx_Val_GroupByChannel, data,
                                     buff_size, &read, NULL));

    ind = 0;
    daq6220pvt.totalRead += sampsPerChan;

    for(i=0; i < 16; i++) {
        if(daq6220pvt.mdsput[i]) {
            if(daq6220pvt.fp[i] != NULL) {
                ind = i*sampsPerChan;
                fwrite(&data[ind], sizeof(float64)*sampsPerChan, 1, daq6220pvt.fp[i]);
                fflush(daq6220pvt.fp[i]);

                if(daq6220pvt.totalRead >= daq6220pvt.sampsPerChan) {
                    fclose(daq6220pvt.fp[i]);
                    daq6220pvt.fp[i] = NULL;
                    epicsPrintf("*** data file save finish... ***\n");
                }
            }
        }
    }

    if(daq6220pvt.totalRead >= daq6220pvt.sampsPerChan) {
        DaqQueueData queueData;

        daq6220pvt.totalRead = 0;

        SetDaqFinshStop(&daq6220pvt);
        daq6220pvt.status = DAQ_STATUS_STOP;

        queueData.opcode = OP_CODE_DAQ_MDSPLUS;
        epicsMessageQueueSend(daq6220pvt.DaqQueueId, (void *)&queueData, sizeof(DaqQueueData));
    }

    free(data);
    data = NULL;

    epicsPrintf("**** NI 6220 File Save Byte : %ld ****\n", buff_size*8);

    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;
}
Esempio n. 28
0
/*
 *

static int gRunning=0;

int main(int argc, char *argv[])
{
    // Task parameters
    int32       error = 0;
    TaskHandle  taskHandle = 0;
    int32       i = 0;
    char        errBuff[2048]={'\0'};
    time_t      startTime;
    bool32      done=0;

    // Channel parameters
    char        chan[] = "Dev2/ao0";
    float64     min = -10.0;
    float64     max = 10.0;

    // Timing parameters
    #define     bufferSize 512
    uInt64      samplesPerChan = bufferSize;
    float64     sampleRate = 20000.0;

    // Data write parameters
    float64     data[bufferSize];
    int32       pointsWritten;
    float64     timeout = 10.0;


    for(;i<bufferSize;i++)
        data[i] = 9.95*sin((double)i*20.0*PI/(double)bufferSize);

    DAQmxErrChk (DAQmxBaseCreateTask("",&taskHandle));
    DAQmxErrChk (DAQmxBaseCreateAOVoltageChan(taskHandle,chan,"",min,max,DAQmx_Val_Volts,NULL));
    DAQmxErrChk (DAQmxBaseCfgSampClkTiming(taskHandle,"",sampleRate,DAQmx_Val_Rising,DAQmx_Val_ContSamps,samplesPerChan));

    DAQmxErrChk (DAQmxBaseWriteAnalogF64(taskHandle,samplesPerChan,0,timeout,DAQmx_Val_GroupByChannel,data,&pointsWritten,NULL));

    DAQmxErrChk (DAQmxBaseStartTask(taskHandle));
    gRunning = 1;
    // The loop will quit after 10 seconds
    startTime = time(NULL);
    while( gRunning && !done && time(NULL)<startTime+10 ) {
        DAQmxErrChk (DAQmxBaseIsTaskDone(taskHandle,&done));
        if( !done )
            usleep(100000);
    }

Error:
    if( DAQmxFailed(error) )
        DAQmxBaseGetExtendedErrorInfo(errBuff,2048);
    if( taskHandle!=0 ) {
        DAQmxBaseStopTask(taskHandle);
        DAQmxBaseClearTask(taskHandle);
    }
    if( DAQmxFailed(error) )
        printf("DAQmxBase Error: %s\n",errBuff);
    return 0;
}
 *
 */
static PyObject *
pyni_ao(PyObject *self, PyObject *args)
{
    float sampr;
    int32       error = 0;
    TaskHandle  taskHandle = 0;
    int32       i = 0;
    int32       pointsWritten;
    char        errBuff[2048]={'\0'};
    time_t      startTime;
    bool32      done=0;
    PyObject *monitor;
    PyArrayObject *data;
    Py_ssize_t	l;
    int64	bs=20000;
    int gRunning = 1;
    double	data2[20000];
    char *name, *chanids;
    
    if (!PyArg_ParseTuple(args, "OfsO", &monitor, &sampr, &chanids, &data))
		    return NULL;
		    
    data=PyArray_FROM_OTF(data,  NPY_FLOAT64 , C_ARRAY);
    DAQmxErrChk (DAQmxBaseCreateTask("",&taskHandle));
    // for (i=0;i<PyList_Size(chanids);i++)
    // {
    // 	name=PyString_AsString(PyList_GetItem(chanids, i));
    // 	printf("%s\n", name);
    // }
    
    for(;i<bs;i++)
        data2[i] = 9.95*sin((double)i*20.0*PI/(double)bs);

    DAQmxErrChk (DAQmxBaseCreateTask("",&taskHandle));
    DAQmxErrChk (DAQmxBaseCreateAOVoltageChan(taskHandle,"Dev2/ao0","",-10,10,DAQmx_Val_Volts,NULL));
    DAQmxErrChk (DAQmxBaseCfgSampClkTiming(taskHandle,"", 10000,DAQmx_Val_Rising,DAQmx_Val_ContSamps,bs));

    DAQmxErrChk (DAQmxBaseWriteAnalogF64(taskHandle,bs,0,10.0,DAQmx_Val_GroupByChannel,data2,&pointsWritten,NULL));

    DAQmxErrChk (DAQmxBaseStartTask(taskHandle));
    // The loop will quit after 10 seconds
    startTime = time(NULL);
    while( gRunning && !done && time(NULL)<startTime+10 ) {
        DAQmxErrChk (DAQmxBaseIsTaskDone(taskHandle,&done));
        //if( !done )
        //    usleep(100000000);
    }


    //DAQmxErrChk (DAQmxBaseCreateAOVoltageChan(taskHandle, chanids ,"", 0.0, 5.0, DAQmx_Val_Volts,NULL));

    //DAQmxErrChk (DAQmxBaseCfgSampClkTiming(taskHandle,"",sampr,DAQmx_Val_Rising,DAQmx_Val_FiniteSamps,data->dimensions[0]));
   // DAQmxErrChk (DAQmxBaseWriteAnalogF64(taskHandle, data->dimensions[0] ,FALSE, 10 ,DAQmx_Val_GroupByScanNumber ,PyArray_DATA(data),&pointsWritten,NULL));
   // DAQmxErrChk (DAQmxBaseStartTask(taskHandle));
   // startTime = time(NULL);
   // while( !done && time(NULL)<startTime+10 ) {
   //         DAQmxErrChk (DAQmxBaseIsTaskDone(taskHandle,&done));
   //         if( !done )
   //     	    usleep(1000);
   //         }
   // startTime=time(NULL)-startTime;
   // DAQmxBaseStopTask(taskHandle);
   // DAQmxBaseClearTask(taskHandle);
    
    i=PyList_SetItem(monitor, 1, Py_BuildValue("i", pointsWritten) );
    i=PyList_SetItem(monitor, 0, Py_BuildValue("i", 1) );
    
    printf("wrote %i samples in %.2f sec\n", pointsWritten, (double)startTime);
    
    Py_XDECREF(data);	
    //Py_XDECREF(monitor);
    //Py_XDECREF(chanids);
    return monitor;
    
    _fail:
	if( taskHandle!=0 ) 
		    {
	    DAQmxBaseStopTask(taskHandle);
		    DAQmxBaseClearTask(taskHandle);
	    }
	if( DAQmxFailed(error) ) {
	    DAQmxBaseGetExtendedErrorInfo(errBuff,2048);
	    printf("DAQmxBase Error: %s\n",errBuff);
	    }
    
			    
	    Py_XDECREF(data);	
	    //Py_XDECREF(monitor);
	    //Py_XDECREF(chanids);	
		
	    return PyErr_Format(PyExc_StandardError,
				errBuff);	
								
}
Esempio n. 29
0
int main(int argc, char *argv[])
{
    // Task parameters
	FILE		*stimfile;
	int32       error = 0;
    TaskHandle  taskHandle = 0;
    int32       i = 0;
    char        errBuff[2048]={'\0'};
    time_t      startTime;
    bool32      done=0;

    // Channel parameters
    char        chan[10] = "Dev1/ao0";
    float64     min = -10.0;
    float64     max = 10.0;

    // Data write parameters
    int32       pointsWritten;
    float64     timeout = 10.0;
	
	float32		header[2];
	float32		datval;
	float64		*data;
	int			off=0;
	long		fsize;
	long		sampPerChan;

	stimfile=fopen(argv[1],"r");
	if (stimfile==NULL) {
		printf("Unable to open file %s \n", argv[1]);
		exit (8);
	}

	fread( (char *)header, 4, 2, stimfile);

	fseek(stimfile, 0, SEEK_END);
	fsize=ftell(stimfile)-8;
	fsize=fsize/4;
	fseek(stimfile, 8, SEEK_SET);
	
	sampPerChan=fsize/header[0];
	printf("Playing file %s: %i channels with %i samples at %.2f Hz ...\n", argv[1], (int)header[0], sampPerChan, header[1]);

	data=(float64 *) calloc(fsize, 8);
	for (i=0;i<fsize;i++) {
		fread( (char *)&datval, 4, 1, stimfile);
		data[i] = (float64)datval;
	}

	if ((int)header[0] > 1) {
		sprintf(chan, "Dev1/ao0:%i", (int) header[0]-1);
	}
	printf("Using device %s \n", chan);


    DAQmxErrChk (DAQmxBaseCreateTask("",&taskHandle));	
    DAQmxErrChk (DAQmxBaseCreateAOVoltageChan(taskHandle,chan,"",min,max,DAQmx_Val_Volts,NULL));
    DAQmxErrChk (DAQmxBaseCfgSampClkTiming(taskHandle,"",(float64) header[1], DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, sampPerChan));
    DAQmxErrChk (DAQmxBaseWriteAnalogF64(taskHandle,512, FALSE,timeout,DAQmx_Val_GroupByScanNumber, data ,&pointsWritten,NULL));
	off+=1024;

    DAQmxErrChk (DAQmxBaseStartTask(taskHandle));
    gRunning = 1;
    // The loop will quit after 10 seconds
    startTime = time(NULL);
    while( gRunning && !done && time(NULL)<startTime+10 ) {
    	DAQmxErrChk (DAQmxBaseWriteAnalogF64(taskHandle,512, FALSE,timeout,DAQmx_Val_GroupByScanNumber, data+off ,&pointsWritten,NULL));
		if (off>= fsize - 1024) {
			done=1;
		} else {
			off+=1024;
			
        DAQmxErrChk (DAQmxBaseIsTaskDone(taskHandle,&done));
		}	

    }
	
	printf("Done. Sent %i samples in %.2f seconds \n", pointsWritten, (float) time(NULL)-startTime);

	if (!done) {
        DAQmxBaseStopTask(taskHandle);
        DAQmxBaseClearTask(taskHandle);
	}

Error:
    if( DAQmxFailed(error) )
        DAQmxBaseGetExtendedErrorInfo(errBuff,2048);
    if( taskHandle!=0 ) {
        DAQmxBaseStopTask(taskHandle);
        DAQmxBaseClearTask(taskHandle);
    }
    if( DAQmxFailed(error) )
        printf("DAQmxBase Error: %s\n",errBuff);
    return 0;
}
Esempio n. 30
0
void acquire(void (*pyCallbackFunc)(uInt32),
	     double (*pyVoltFunc)(uInt32),
	     _Bool (*isFinished)(uInt32)) {
  // Task parameters
  int32       error = 0;
  //  TaskHandle  taskHandle = 0;
  char        errBuff[2048]={'\0'};
  time_t      startTime;

  // Data read parameters
  uInt32      data;
  float64     timeout = 5.0;

  // Channel parameters
  float64     min = 0.0;
  float64     max = 5.0;

  // Task parameters
  //  memcpy(writeParams.gerrBuff, '\0', 1);

  // Data write parameters
  TaskHandle taskHandle = 0;

  float64 voltage = 0.0;
  uInt32 count = 0;
  uInt32 previousCount = 0;

  writeParams.gtimeout = 10.0;
  writeParams.taskHandle = 0;
  writeParams.samplesPerChan = 1;

  // counter stuff
  DAQmxErrChk (DAQmxBaseCreateTask("",&taskHandle));
  DAQmxErrChk (DAQmxBaseCreateCICountEdgesChan(taskHandle,
					       userData.readChannel,"",
					       DAQmx_Val_Falling,0,
					       DAQmx_Val_CountUp));
  DAQmxErrChk (DAQmxBaseStartTask(taskHandle));
  gRunning = 1;

  // analogue output stuff
  DAQmxErrChk(DAQmxBaseCreateTask("", &writeParams.taskHandle));
  DAQmxErrChk(DAQmxBaseCreateAOVoltageChan(writeParams.taskHandle, 
					   userData.writeChannel,
					   "",min,max,
					   DAQmx_Val_Volts,NULL));
  DAQmxErrChk(DAQmxBaseStartTask(writeParams.taskHandle));

  // The loop will quit after 10 seconds
  startTime = time(NULL);


  printf("Beginning main loop\n");
  
  // set initial voltage
  voltage = pyVoltFunc(0);
  DAQmxErrChk(DAQmxBaseWriteAnalogF64(writeParams.taskHandle,
				      writeParams.samplesPerChan,0,
				      writeParams.gtimeout,
				      DAQmx_Val_GroupByChannel,
				      &voltage,
				      &writeParams.gpointsWritten,
				      NULL));

  while( gRunning && !isFinished(0) ) {

    // measure counts every time
    DAQmxErrChk (DAQmxBaseReadCounterScalarU32(taskHandle,
					       timeout,&data,NULL));
    
    if(count++ % userData.reportEvery == 0) {
      /*
	This represents the end of one complete voltage measure.
	We report back the count, set data to 0, set the new voltage
      */
      
      // set voltage
      voltage = pyVoltFunc(0);
      DAQmxErrChk(DAQmxBaseWriteAnalogF64(writeParams.taskHandle,
					  writeParams.samplesPerChan,0,
					  writeParams.gtimeout,
					  DAQmx_Val_GroupByChannel,
					  &voltage,
					  &writeParams.gpointsWritten,
					  NULL));

      // read data
      pyCallbackFunc(data - previousCount);
      previousCount = data;

    }
    
  }


 Error:
  puts("");
  
  if( DAQmxFailed(error) )
    DAQmxBaseGetExtendedErrorInfo(errBuff,2048);
  if( taskHandle!=0 ) {
    DAQmxBaseStopTask(taskHandle);
    DAQmxBaseClearTask(taskHandle);
  }
  if( writeParams.taskHandle!=0 ) {
    DAQmxBaseStopTask(writeParams.taskHandle);
    DAQmxBaseClearTask(writeParams.taskHandle);
  }


  if( DAQmxFailed(error) )
    printf ("DAQmxBase Error %ld: %s\n", error, errBuff);

}