LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Traditional DAQ to NI-DAQmx

Hi,

 

I am trying to convert the code that was in Traditional DAQ to new 6341 Daq card in DAQmx. I am not finding the functions I need to get the conversion. Can I get some help? Here is my old code.

 

//---------------------------------------------------------------------------
int GeneratePulses (void)
{
 unsigned long magOff = 0;
 double now, fourSecondsLater;
 
   i16 iStatus = 0;
   i16 iRetVal = 0;
   i16 iDevice = mioBrd;
   i16 iNumChans = 2;
   i16 iChan = 0;
   static i16 piChanVect[] = {0, 1};
   i16 iGroup = 1;
   //static f64 pdBuffer[5000] = {0};
   static i16 piBuffer[6000] = {0};
   u32 ulCount = 3000*iNumChans;
   u32 ulIterations = nCycles[metric];
   i16 iFIFOMode = 0;
   i16 iDelayMode = 0;
   f64 dUpdateRate = 100000;
   i16 iUpdateTB = 0;
   u32 ulUpdateInt = 0;
   i16 iWhichClock = 0;
   i16 iUnits = 0;
   i16 iWFMstopped = 0;
   u32 ulItersDone = 0;
   u32 ulPtsDone = 0;
   i16 iOpSTART = 1;
   i16 iOpCLEAR = 0;
   i16 iIgnoreWarning = 0;
   i16 iYieldON = 1;

   iStatus = NIDAQMakeBuffer(pdBuffer, ulCount, WFM_DATA_F64);

   if (iStatus == 0)
 {
  // assign AO channels to waveform generation group
      iStatus = WFM_Group_Setup(iDevice, iNumChans, piChanVect, iGroup);
      iRetVal = NIDAQErrorHandler(iStatus, "WFM_Group_Setup", iIgnoreWarning);

  // translate real values to integer values
      iStatus = WFM_Scale(iDevice, iChan, ulCount, 1.0, waveform, piBuffer);
      iRetVal = NIDAQErrorHandler(iStatus, "WFM_Scale", iIgnoreWarning);

      iStatus = WFM_Load(iDevice, iNumChans, piChanVect, piBuffer, ulCount, ulIterations, iFIFOMode);
      iRetVal = NIDAQErrorHandler(iStatus, "WFM_Load", iIgnoreWarning);

      iStatus = WFM_Rate(dUpdateRate, iUnits, &iUpdateTB, &ulUpdateInt);
      iRetVal = NIDAQErrorHandler(iStatus, "WFM_Rate", iIgnoreWarning);

      iStatus = WFM_ClockRate(iDevice, iGroup, iWhichClock, iUpdateTB, ulUpdateInt, iDelayMode);
      iRetVal = NIDAQErrorHandler(iStatus, "WFM_ClockRate", iIgnoreWarning);

      // printf(" A %lu point waveform should be output at a rate of %lf updates/sec.\n", ulCount, dUpdateRate);

      iStatus = WFM_Group_Control(iDevice, iGroup, iOpSTART);
      iRetVal = NIDAQErrorHandler(iStatus, "WFM_Group_Control/START", iIgnoreWarning);
       
  Delay (.5);
      while ((iWFMstopped == 0) && (iStatus == 0))
  {
         iStatus = WFM_Check(iDevice, iChan, &iWFMstopped, &ulItersDone, &ulPtsDone);
         iRetVal = NIDAQYield(iYieldON);
   Delay (.5);
      }

      iRetVal = NIDAQErrorHandler(iStatus, "WFM_Check", iIgnoreWarning);

      /* CLEANUP - Don't check for errors on purpose. */

      /* Set group back to initial state. */

      iStatus = WFM_Group_Control(iDevice, iGroup, iOpCLEAR);
       
      /* Set output at 0 volts. */

      iStatus = AO_VWrite(iDevice, iChan, 0.0);
      iStatus = AO_VWrite(iDevice, iChan+1, 0.0);
  
   }
   else
 {
      printf(" The buffer was not made correctly. Check the parameters for NIDAQMakeBuffer.\n");
 }
 return 0;
}

 

 

Thank you,

Hiren

Hiren Patel
0 Kudos
Message 1 of 4
(3,558 Views)

I have no PC with CVI installed to check, but you should take a look at DAQmx examples that ship with the product: there should be sample projects for waveform generation that may give you a framework that you can tailor to your needs. As far as I can understand from the code, you are performing a finite generation on two channels so you should be able to locate she appropriate sample using the example finder or browsing the sample folder in CVI directory.

 

Additionally, you may find these resources useful to deep into DAQmx programming:

Transitioning from Traditional NI-DAQ (Legacy) to NI-DAQmx Using ANSI C and NI LabWindows™/CVI

Analog waveform generation with output buffer update with DAQmx

 



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 4
(3,540 Views)

Thanks for reply Roberto,

 

I have looked at the examples but it is still not clear to me. I am generating the finite samples but also I need to generate them for 1000 iterations. That is being done in the old code by "WFM_Load(iDevice, iNumChans, piChanVect, piBuffer, ulCount, ulIterations, iFIFOMode);"

 

Also I used these functions to get the timing set. WFM_Rate(dUpdateRate, iUnits, &iUpdateTB, &ulUpdateInt); and WFM_ClockRate(iDevice, iGroup, iWhichClock, iUpdateTB, ulUpdateInt, iDelayMode);

 

Any help will be appreciated.

 

Thanks,

Hiren

Hiren Patel
0 Kudos
Message 3 of 4
(3,513 Views)

Hello Roberto,

 

You may want to reference our ANSI C shipping examples.  Included in the examples is a program for finite voltage generation.  For accessing the ANSI C shipping examples, I would suggest installing the newer version of DAQmx (9.2.2) and navigating to the Text-Based Code Support folder.  You can do so by navigating to the Windows Start Menu->All Programs->National Instruments->NI-DAQ->Text-Based Code Support->ANSI C Examples.

 

Please refer to the following links for additional information:

 

Location of ANSI C NI-DAQmx Shipping Examples and DAQmx Library File for Windows

http://digital.ni.com/public.nsf/allkb/FB26BDA52FFFD4EE86257124005C36C3

 

NI DAQmx 9.2.2:

http://joule.ni.com/nidu/cds/view/p/id/2214/lang/en

Regards,
Roman Sandoval | National Instruments | RF Systems Engineer
0 Kudos
Message 4 of 4
(3,500 Views)