LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Can somebody please tell me the steps to Program USB 6211 with C. Will I get the software to program the device along with the drivers CD that I got when I purchased the Device?

Solved!
Go to solution

Hi Brain,

I tried executing the example program for analog continuous wave generation. I was sucessful in generation of the wave, but when I stop the execution my DAQ board still outputs a DC voltage.

But I want the output to go to Zero once I'm done withthe execution. Is there something else that I need to add to the code to acheive this.Please help me.

Thanks,

Diya

0 Kudos
Message 21 of 30
(1,548 Views)

Diya,

 

With Analog Out the card will always output the last voltage it was given.  If you want to have it go to zero after you are done, you can write a 0 to your line at the end of the program.

 

I hope that helps.

 

Brian

Applications Engineer
National Instruments
0 Kudos
Message 22 of 30
(1,547 Views)

Brain,

I tried doing that but I'm seeing an error message which says "Specified resource is reserved".

I want my wave to be continous and just go to zero when I hit enter to end program.

Can you help me out with the syntax of the program? i.e. where should i give the statement data=0.0; in my code?

Thanks,

Diya

0 Kudos
Message 23 of 30
(1,544 Views)

Diya,

 

In order to get it to output a zero, I changed the error section to write a zero and then output it before it stops the program.  Here is how I modified it:

 

Error:

if( DAQmxFailed(error) )

DAQmxGetExtendedErrorInfo(errBuff,2048);

if( taskHandle!=0 ){

/*********************************************/

//DAQmx Stop Code

/*********************************************/

DAQmxStopTask(taskHandle);

DAQmxWriteAnalogF64(taskHandle,1,1,10.0,DAQmx_Val_GroupByChannel,0,NULL,NULL);

DAQmxStartTask(taskHandle);DAQmxStopTask(taskHandle);DAQmxClearTask(taskHandle);

}

if( DAQmxFailed(error) )

printf("DAQmx Error: %s\n",errBuff);

printf("End of program, press Enter key to quit\n");

getchar();

return 0;

 

And that would bring my output back to zero.  

 

I hope this helps.

 

Brian P.

Applications Engineer
National Instruments
0 Kudos
Message 24 of 30
(1,527 Views)

Hi Brain,

I've the same problem back again.. It just worked for once and it is not working again.. 😞

 

This is my code :

 

#include <stdio.h>#include <math.h>#include "NIDAQmx.h"
#pragma hdrstop
//---------------------------------------------------------------------------
#define DAQmxErrChk(functionCall) if( DAQmxFailed(error=(functionCall)) ) goto Error; else
#define PI3.1415926535
int32 CVICALLBACK DoneCallback(TaskHandle taskHandle, int32 status, void *callbackData);
#pragma argsusedint main(int argc, char* argv[]){
int       error=0;

TaskHandle  taskHandle=0;

float64     data[100001];

char        errBuff[2048]={'\0'};

int         i=0;       

int freq;       

printf("Please enter the Desired Frequency\n"); 

scanf("%d", &freq);

for(;i<100001;i++)

data[i] = 5*sin((double)i*2.0*PI* freq/240000.0);
/*********************************************/// DAQmx Configure Code/*********************************************/DAQmxErrChk (DAQmxCreateTask("",&taskHandle));

DAQmxErrChk (DAQmxCreateAOVoltageChan(taskHandle,"Dev1/ao1","",-10.0,10.0,DAQmx_Val_Volts,NULL));

DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle,"",240000.0,DAQmx_Val_Rising,DAQmx_Val_ContSamps,50000));
DAQmxErrChk (DAQmxRegisterDoneEvent(taskHandle,0,DoneCallback,NULL));
/*********************************************/// DAQmx Write Code/*********************************************/DAQmxErrChk (DAQmxWriteAnalogF64(taskHandle,50000,0,-1.0,DAQmx_Val_GroupByChannel,data,NULL,NULL));
/*********************************************/// DAQmx Start Code/*********************************************/DAQmxErrChk (DAQmxStartTask(taskHandle));
printf("Generating voltage continuously. Press Enter to interrupt\n");

getchar();       

getchar();
Error:if( DAQmxFailed(error) )

DAQmxGetExtendedErrorInfo(errBuff,2048);

if( taskHandle!=0 ) {

/*********************************************/

// DAQmx Stop Code

/*********************************************/

DAQmxStopTask(taskHandle);             

  DAQmxWriteAnalogF64(taskHandle,240000,0,10.0,DAQmx_Val_GroupByChannel,0,NULL,NULL);             

  DAQmxStartTask(taskHandle);

DAQmxStopTask(taskHandle);

DAQmxClearTask(taskHandle);    

  //DAQmxClearTask(taskHandle);}

if( DAQmxFailed(error) )

printf("DAQmx Error: %s\n",errBuff);

printf("End of program, press Enter key to quit\n");

getchar();

return 0;}
int32 CVICALLBACK DoneCallback(TaskHandle taskHandle, int32 status, void *callbackData)

{

int32   error=0;

char    errBuff[2048]={'\0'};
// Check to see if an error stopped the task.

DAQmxErrChk (status);
Error:

if( DAQmxFailed(error) ) {

DAQmxGetExtendedErrorInfo(errBuff,2048);

DAQmxClearTask(taskHandle);

printf("DAQmx Error: %s\n",errBuff);}return 0;

}
//----------------------------------------------------------------------------------

0 Kudos
Message 26 of 30
(1,511 Views)

Diya,

 

I am sorry that it is not working for you again.  When you say not working, what exactly do you mean, are you getting an error?  What has changed from when it was working?

 

I looked at your code and everything seems to be in order so I am thinking that we do that self test again, where we output the data and then read the data back in using a test panel.

 

Please let me know what errors you are getting if any.

 

Regards,

 

Brian P.

Applications Engineer
National Instruments
0 Kudos
Message 28 of 30
(1,494 Views)

Hi Brain,

I tried executing the code even using the test panel method you suggested earlier. Still didn't work. 😞

Previously when I posted that it worked and the reason behind it might be, when I hit enter to abort the generation of the sine wave, maybe I got lucky and it stopped exactly at the point zero and it seemed to be working But after I executed the code couple of times it never worked again, i.e.. It never ended at zero. It is giving me some DC offset values but not going to Zero.

 

Regards,

Diya

0 Kudos
Message 29 of 30
(1,487 Views)

Hi Diya, 

 

I ran your code and it executed properly as it zeroed after pressing Enter to interrupt. Does the waveform (prior to zero) look correct in the AI Test Panel? Could you take a screenshot of the test panel after you press Enter?

 

Kind Regards,

0 Kudos
Message 30 of 30
(1,471 Views)