07-10-2011 03:14 PM
I use NI-USB-6229 and calling it using CVI,
in order to change the Voltage i made this function, which i call whenever i need to change the voltage level,
the process takes about 7[ms[, which is very long. how can i shorten it? are there parts that i can skip?
//DAQ:
void SetDaqOut (char channel[],float64 DaqOutVal )
{
int error;
int32 written;
char errBuff[2048]={'\0'};
float64 ValArray[]={DaqOutVal};
TaskHandle TaskSetOut;
SetWaitCursor(1);
DAQmxErrChk (DAQmxCreateTask("",&TaskSetOut));
DAQmxErrChk (DAQmxCreateAOVoltageChan (TaskSetOut, channel, "", 0, 10, DAQmx_Val_Volts, ""));
//DAQmxErrChk (DAQmxCreateAOVoltageChan (TaskSetOut, channel, "", 0, 10,
// DAQmx_Val_FromCustomScale , calibrated_teta));
DAQmxErrChk (DAQmxWriteAnalogF64 (TaskSetOut, 1, 1, 10.0, DAQmx_Val_GroupByChannel, ValArray, &written, NULL));
DAQmxErrChk (DAQmxStartTask(TaskSetOut));
DAQmxStopTask(TaskSetOut);
DAQmxClearTask(TaskSetOut);
Error:
SetWaitCursor(0);
if( DAQmxFailed(error) )
DAQmxGetExtendedErrorInfo(errBuff,2048);
}
thank in advance,
07-10-2011 03:49 PM
If you just want to change the voltage, don't create the task and channel and close the task each time.
07-11-2011 12:16 AM
so what should i do? save the task pointer and call it each time?
something like that?:
void SetDaqOut (char channel[],float64 DaqOutVal, int finish_and_clear )
{
int error;
int32 written;
char errBuff[2048]={'\0'};
float64 ValArray[]={DaqOutVal};
static TaskHandle TaskSetOut;
staticc int first_time=1;
SetWaitCursor(1);
if (first_time)
{
DAQmxErrChk (DAQmxCreateTask("",&TaskSetOut));
first_time;
}
DAQmxErrChk (DAQmxCreateAOVoltageChan (TaskSetOut, channel, "", 0, 10, DAQmx_Val_Volts, ""));
DAQmxErrChk (DAQmxWriteAnalogF64 (TaskSetOut, 1, 1, 10.0, DAQmx_Val_GroupByChannel, ValArray, &written, NULL));
DAQmxErrChk (DAQmxStartTask(TaskSetOut));
DAQmxStopTask(TaskSetOut);
if (finish_and_clear)
{
DAQmxClearTask(TaskSetOut);
}
Error:
SetWaitCursor(0);
if( DAQmxFailed(error) )
DAQmxGetExtendedErrorInfo(errBuff,2048);
}
07-11-2011 10:16 AM
Do NOT call the create channel, start task, or stop task each time. You could simply have one function where the task is created, one where you do the write, and one where you stop and clear. And yes, this would require you saving the task and passing it to the write and stop functions.
07-17-2011 04:40 AM
thanks,
can i use write voltage twice, without soping and clearing?
07-17-2011 11:25 PM
You can use it as many times as you want if you don't clear the task. If you stop it, you would need to start it again.