Beispiel #1
0
    int NationalInstrumentsDAQ::writeAO(float64 *data)
    {
      int32 written,
            N = _config->ao_samples_per_waveform();

#if 0
      {
        uInt32 nchan;
        char
          buf[1024],
          name[1024];
        memset(buf ,0,sizeof(buf ));
        memset(name,0,sizeof(name));
        DAQWRN( DAQmxGetTaskName(_ao.daqtask,name,sizeof(name)) );
        DAQWRN( DAQmxGetTaskNumChans(_ao.daqtask,&nchan) );
        DAQWRN( DAQmxGetTaskChannels(_ao.daqtask,buf,sizeof(buf)) );
        HERE;
        debug("NI-DAQmx Task (%s) has %d channels"ENDL"\t%s"ENDL,
          name,
          nchan,
          buf);

        while(nchan--)
        { DAQWRN( DAQmxGetNthTaskChannel(_ao.daqtask, 1+nchan, buf, sizeof(buf)) );
          DAQWRN( DAQmxGetPhysicalChanName(_ao.daqtask, buf, buf, sizeof(buf)) );
          debug("\t%d:\t%s"ENDL,nchan,buf);
        }
      }
      {
        FILE *fp = fopen("NationalInstrumentsDAQ_writeAO.f64","wb");
        fwrite(data,sizeof(f64),3*N,fp);
        fclose(fp);
      }
#endif

      DAQJMP( DAQmxWriteAnalogF64(_ao.daqtask,
        N,
        0,                           // autostart?
        1.0,                         // timeout (s) - to write - 0 causes write to fail if blocked at all
        DAQmx_Val_GroupByChannel,
        data,
        &written,
        NULL));
      Guarded_Assert( written == N );
      return 0; // success
Error:
      return 1; // fail
    }
// this is copied from ContinuousAI.c  Not fully sure how it works.
int32 GetTerminalNameWithDevPrefix(TaskHandle taskHandle, const char terminalName[], char triggerName[])
{
  int32 error = 0;
  char chan[256];
  char *slash;

  daq_err_check( DAQmxGetNthTaskChannel(taskHandle, 1, chan, 256) );
  daq_err_check( DAQmxGetPhysicalChanName(taskHandle, chan, chan, 256) );
  if( (slash =strchr(chan,'/')) != NULL){
    *slash = '\0';
    *triggerName++ = '/';
    strcat(strcat(strcpy(triggerName,chan),"/"),terminalName);
  } else
    strcpy (triggerName, terminalName);
  return 0;
}
Beispiel #3
0
int DllExport _nidaq_store (int id, char *nodeName, int simultaneous)
{
	char channelName[256], pathName[256];
	int16 *data;
	int32 stats, samplesRead, idesc, idesc1, idesc2, idesc3, idesc4, idesc5, idesc6, dtype, null = 0;
	uInt32 i, arraySize, nPacket, packetSize;
	uInt64 numSamples;
	float64 convRate, dt, range, resolution, period;
	sTask *pTask;
	sDataChain *pData, *pNext;
	
	pTask = tasks.item + id;
	if (simultaneous)
	{
		dt = 0.0;
	}
	else
	{
		DAQmxGetTimingAttribute (pTask->handle, DAQmx_AIConv_Rate, &convRate);
		dt = 1.0/convRate;
	}

	if (pTask->type== DAQmx_Val_OnDemand)
	{
		pData = pTask->current;
		samplesRead = pTask->num * NBUF + pData->num;
		arraySize = pTask->numChannels * samplesRead;
		data = (int16 *)malloc(arraySize * sizeof (int16));
		nPacket = NBUF * pTask->numChannels;
		packetSize = nPacket * sizeof (int16);
		pNext = pTask->start;
		for (i=0; i<pTask->num; i++)
		{
			pData = pNext;
			memcpy (data + i * nPacket, pData->data, packetSize);
			pNext = pData->next;
			free (pData->data);
			free (pData);
		}
		memcpy (data + i * nPacket, pNext->data, pNext->num * pTask->numChannels * sizeof (int16));
		free (pNext->data);
		free (pNext);
	}
	else
	{
		/* # of samples */
		DAQmxGetTimingAttribute (pTask->handle, DAQmx_SampQuant_SampPerChan, &numSamples);
		arraySize = pTask->numChannels * numSamples;
		data = (int16 *)malloc(arraySize * sizeof (int16));
		DAQmxReadBinaryI16 (pTask->handle, DAQmx_Val_Auto, 10.0, DAQmx_Val_GroupByScanNumber, data, arraySize, &samplesRead, NULL);
	}
	/* Get the ADC resolution 12bits=NI6071,NI6115, 16bits=NI6143, 14bits but packed from bit 15=NI6133 */
	DAQmxGetChanAttribute (pTask->handle, NULL, DAQmx_AI_Resolution, &resolution);
	if (resolution == 14.) resolution = 16.;
	resolution = ldexp (1.0, (int) resolution-1);  

	/* Sampling time */
	DAQmxGetTimingAttribute (pTask->handle, DAQmx_SampClk_Rate, &period);
	period = 1.0/period; //Rate -> Time
	
	dtype = DTYPE_SHORT;
	idesc1 = descr(&dtype, data, &arraySize, &null);

	dtype = DTYPE_ULONG;
	idesc2 = descr(&dtype, &i, &null);

	idesc3 = descr(&dtype, &pTask->numChannels, &null);

	dtype = DTYPE_ULONGLONG;
	numSamples = samplesRead - 1;
	idesc4 = descr(&dtype, &numSamples, &null);

	dtype = DTYPE_DOUBLE;
	idesc = descr(&dtype, &range, &null);
	idesc5 = descr(&dtype, &convRate, &null);
	idesc6 = descr(&dtype, &period, &null);
	for (i=0; i<pTask->numChannels; i++)
	{
		/* Translate a channel name to a node name */
		DAQmxGetNthTaskChannel (pTask->handle, i+1, channelName, 256);
		sprintf (pathName, "%s:%s:FOO", nodeName, channelName);

		DAQmxGetChanAttribute (pTask->handle, channelName, DAQmx_AI_Max, &range);
		range /= resolution;

		convRate = i * dt;
		stats = MdsPut(pathName,"BUILD_SIGNAL(BUILD_WITH_UNITS($*$VALUE,'V'),(`$[$:*:($)]),MAKE_DIM(MAKE_WINDOW(0,$,$),MAKE_SLOPE(MAKE_WITH_UNITS($,'s'))))",
			&idesc, &idesc1, &idesc2, &idesc3, &idesc4, &idesc5, &idesc6, &null);
	}
	free (data);
	
	DAQmxStopTask (pTask->handle);
	return 1;
}