Exemplo n.º 1
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;
}
Exemplo n.º 2
0
int main(int argc, char **argv)
{
	ros::init(argc, argv, "GalvoScanner");
	ros::NodeHandle n;

	//ros::Publisher pubGalvoScanner = n.advertise<std_msgs::String>("GalvoScanner", 1000);
	ros::Subscriber subGalvoScanner = n.subscribe("ScannerPoints", 1000, GalvoPointListCallback);
	ros::Rate loop_rate(10);

	char 		szTask[]="OutputPointList";
	char		szPhysicalChannel[]="Dev1/ao0:1";
	float64		 ratePoint = 100.0; //rateFrame * gnPoints;
	float64		 ratePointActual = 0.0;


	//DAQmxCreateTask (szTask, &ghTask);
	//DAQmxCreateAOVoltageChan (ghTask, szPhysicalChannel, NULL, -10.0, +10.0, DAQmx_Val_Volts, NULL);
	//DAQmxSetWriteRegenMode(ghTask, DAQmx_Val_AllowRegen);
	//DAQmxCfgSampClkTiming (ghTask, "OnboardClock", ratePoint, DAQmx_Val_Rising, DAQmx_Val_ContSamps, gnPoints);
	//DAQmxGetSampClkRate(ghTask, &ratePointActual);
	//WriteFlyLogo();
	//DAQmxStartTask (ghTask);
	//ros::spin();
	//DAQmxClearTask (ghTask);

	DAQmxBaseCreateTask (szTask, &ghTask);
	DAQmxBaseCreateAOVoltageChan (ghTask, szPhysicalChannel, NULL, -10.0, +10.0, DAQmx_Val_Volts, NULL);
	DAQmxBaseCfgSampClkTiming (ghTask, "OnboardClock", ratePoint, DAQmx_Val_Rising, DAQmx_Val_ContSamps, gnPoints);
	WriteFlyLogo();
	DAQmxBaseStartTask (ghTask);
	ros::spin();
	DAQmxBaseClearTask (ghTask);

	//while (ros::ok())
	//{
	//	ros::spinOnce();
	//	loop_rate.sleep();
	//}


	return 0;
}
Exemplo n.º 3
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;
}
Exemplo n.º 4
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);	
								
}
Exemplo n.º 5
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);

}