Exemplo n.º 1
0
//Gateway routine
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
	TaskHandle task;
	int32 numSampsPerChan;
	float64 timeout;

	uInt32 numChannels;
	int32 totalNumSamples;
	uInt32 arraySizeInSamples;
	uInt32 arraySizeInBytes;	
	int32 sampsRead;
	int32 numBytesPerSamp;
	int16 *dataBuffer;
	int32 status;
	int32 errorStringSize;
	char *errorString;

	double *sampsReadOutput;

	//Parse input arguments
	task = (TaskHandle)mxGetScalar(prhs[0]);
	numSampsPerChan = (int32)mxGetScalar(prhs[1]);
	timeout = (float64)mxGetScalar(prhs[2]);
	arraySizeInSamples = (uInt32)mxGetScalar(prhs[3]);
	
	//Determine # of channels and amt. of memory to allocate
	DAQmxGetTaskNumChans(task, &numChannels);
	totalNumSamples = arraySizeInSamples * numChannels;
	arraySizeInBytes = totalNumSamples * sizeof(int16);

	//Create memory for output arguments
	plhs[0] = mxCreateNumericMatrix(totalNumSamples, 1, mxINT16_CLASS, mxREAL); 
	plhs[1] = mxCreateDoubleScalar(0);
	dataBuffer = (int16*)mxGetPr(plhs[0]);
	sampsReadOutput = mxGetPr(plhs[1]);
	
	//Call DAQmx function
	status = (int32) DAQmxReadRaw(task, numSampsPerChan, timeout, dataBuffer, arraySizeInBytes, &sampsRead, &numBytesPerSamp, NULL);

	//Return output buffer
	if (!status)
	{
		mexPrintf("Successfully read %d samples of data\n", sampsRead);		
		*sampsReadOutput = (double)sampsRead;
	}
	else
	{
		//Display error string
		errorStringSize = DAQmxGetErrorString(status,NULL,0); //Gets size of buffer
		errorString = (char *)mxCalloc(errorStringSize,sizeof(char));
		DAQmxGetErrorString(status,errorString,errorStringSize);
		mexPrintf("ERROR in %s: %s\n", mexFunctionName(), errorString);
		mxFree(errorString);

		//Return an empty array insead
		mxDestroyArray(plhs[0]); //I think this is kosher
		plhs[0] = mxCreateNumericMatrix(0, 0, mxINT16_CLASS, mxREAL);
	}

}
Exemplo n.º 2
0
//Helper functions
void handleDAQmxError(int32 status, const char *functionName)
{
	//Display DAQmx error string
	int32 errorStringSize = DAQmxGetErrorString(status,NULL,0); //Gets size of buffer
	char *errorString = (char *)mxCalloc(errorStringSize,sizeof(char));
	char *finalErrorString = (char*) mxCalloc(errorStringSize+100,sizeof(char));
	DAQmxGetErrorString(status,errorString,errorStringSize);
	sprintf(finalErrorString, "DAQmx Error (%d) encountered in %s:\n %s\n", status,functionName,errorString);

	mxFree(errorString);
	mexErrMsgTxt(finalErrorString); // leaks finalErrorString
}
Exemplo n.º 3
0
int DllExport _nidaq_open (char* name)
{
	int id ,status;
	char buf[256];
	TaskHandle handle;
	sTask *pTask;
	sDataChain *pData;

	status = DAQmxLoadTask (name, &handle);
	if (status)
	{
		DAQmxGetErrorString (status, buf, 256);
		printf("%s\n",buf);
		return status;
	}
	id = task_insert(handle);
	pTask = tasks.item + id;

	/* # of channels */
	DAQmxGetReadAttribute (handle, DAQmx_Read_NumChans, &pTask->numChannels);

	DAQmxGetTimingAttribute (handle, DAQmx_SampTimingType, &pTask->type);
	if (pTask->type== DAQmx_Val_OnDemand)
	{
		pData = malloc(sizeof(sDataChain));
		pData->data = malloc(NBUF * pTask->numChannels * sizeof(short));
		pData->num = 0;
		pData->next = 0;
		pTask->current = pData;
		pTask->start = pData;
		pTask->num = 0;
	}

	return id;
}
Exemplo n.º 4
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);
    }
  }
}
Exemplo n.º 5
0
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;
}
std::string ATIDAQHardwareInterface::GetErrorCodeDescription( long errCode )
{
    char errorBuffer[WHOLE_LOTTA_CHARACTERS]; /*c-string style representation of error description*/
    DAQmxGetErrorString( errCode, errorBuffer, WHOLE_LOTTA_CHARACTERS );
    return std::string( errorBuffer );
}