Example #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;
}