Signal Generators

cancel
Showing results for 
Search instead for 
Did you mean: 

PXI-5421, C++, Creating output signal, DAQmxWriteAnalogF64 fails

I want to create a simple sine wave output on a PXI-5421 card. I have looked at the sample projects for DAQmx, and based an application on them.

The application falls over at the call to DAQmxWriteAnalogF64 using the following parameters:

lReturn = DAQmxWriteAnalogF64(
m_hTask,
1000,
0,
10.0,
DAQmx_Val_GroupByChannel,
data,
&lWritten,
NULL
);



What am I doing wrong?

Below is the output of the application, and the code.


***** START OF OUTPUT *****
DAQmxResetDevice -> SUCCESS
DAQmxCreateTask -> SUCCESS
DAQmxCreateAOVoltageChan -> SUCCESS
DAQmxCfgSampClkTiming -> SUCCESS
Samples per channel written: 0
Source terminal to be routed could not be found on the device.
Make sure the terminal name is valid for the specified device. Refer to Measurement & Automation Explorer for valid terminal names.
Device: PXI1Slot3
Property: DAQmx_SampClk_Src
Source Terminal:
Task Name: _unnamedTask<0>
Status Code: -200040

DAQmxWriteAnalogF64 -> -200040
***** END OF OUTPUT *****


***** START OF APPLICATION *****
void Startup( void )
{

// get amplitude
double dblAmplitude = 5; // 5 volts

// generate wave data
float64 data[1000];
for( int i=0; i<1000; i++ )
data[i] = dblAmplitude * sin( (double)i * 2.0 * PI/1000.0 );

// device, channel and terminal names
char szDeviceName[128];
strcpy(szDeviceName,"PXI1Slot3"); // PXI1Slot3
char szChannel[128];
sprintf(szChannel,"%s/ao0",szChannelName); // PXI1Slot3/ao0
char szTerminal[128];
strcpy(szTerminal,"Onboard Clock"); // Onboard Clock

// reset device
long lReturn = DAQmxResetDevice(szDeviceName);
_AddToLog("DAQmxResetDevice",lReturn);

// create task
lReturn = DAQmxCreateTask("",&m_hTask);
_AddToLog("DAQmxCreateTask",lReturn);

// if that worked...
if(lReturn==0)
{

// create output voltage channel
lReturn = DAQmxCreateAOVoltageChan(
m_hTask,
szChannel,
"",
-1 * dblAmplitude,
dblAmplitude,
DAQmx_Val_Volts,
NULL
);
_AddToLog("DAQmxCreateAOVoltageChan",lReturn);

}

// if that worked...
if(lReturn==0)
{

// define sampling
lReturn = DAQmxCfgSampClkTiming(
m_hTask,
szTerminal,
10*1000,
DAQmx_Val_Rising,
DAQmx_Val_ContSamps,
1000
);
_AddToLog("DAQmxCfgSampClkTiming",lReturn);

}

// if that worked...
if(lReturn==0)
{

// write to buffer
long lWritten = 0;
lReturn = DAQmxWriteAnalogF64(
m_hTask,
1000,
0,
10.0,
DAQmx_Val_GroupByChannel,
data,
&lWritten,
NULL
);

CString strLine;
strLine.Format("Samples per channel written: %d",lWritten);
_AddToLog(strLine);
_AddToLog("DAQmxWriteAnalogF64",lReturn);

}

// if that worked...
if(lReturn==0)
{

// start task
lReturn = DAQmxStartTask(m_hTask);
_AddToLog("DAQmxStartTask",lReturn);

}
else
{

// clean up
_CleanUp();

}

}

void _CleanUp( void )
{

// stop task
long lReturn = DAQmxStopTask(m_hTask);
_AddToLog("DAQmxStopTask",lReturn);

// clear task
lReturn = DAQmxClearTask(m_hTask);
_AddToLog("DAQmxClearTask",lReturn);

}
***** END OF APPLICATION *****
0 Kudos
Message 1 of 2
(7,758 Views)

@Broccoli wrote:
I want to create a simple sine wave output on a PXI-5421 card. I have looked at the sample projects for DAQmx, and based an application on them.

The application falls over at the call to DAQmxWriteAnalogF64 using the following parameters:

lReturn = DAQmxWriteAnalogF64(
m_hTask,
1000,
0,
10.0,
DAQmx_Val_GroupByChannel,
data,
&lWritten,
NULL
);



What am I doing wrong?

Below is the output of the application, and the code.


***** START OF OUTPUT *****
DAQmxResetDevice -> SUCCESS
DAQmxCreateTask -> SUCCESS
DAQmxCreateAOVoltageChan -> SUCCESS
DAQmxCfgSampClkTiming -> SUCCESS
Samples per channel written: 0
Source terminal to be routed could not be found on the device.
Make sure the terminal name is valid for the specified device. Refer to Measurement & Automation Explorer for valid terminal names.
Device: PXI1Slot3
Property: DAQmx_SampClk_Src
Source Terminal:
Task Name: _unnamedTask<0>
Status Code: -200040

DAQmxWriteAnalogF64 -> -200040
***** END OF OUTPUT *****


***** START OF APPLICATION *****
void Startup( void )
{

// get amplitude
double dblAmplitude = 5; // 5 volts

// generate wave data
float64 data[1000];
for( int i=0; i<1000; i++ )
data[i] = dblAmplitude * sin( (double)i * 2.0 * PI/1000.0 );

// device, channel and terminal names
char szDeviceName[128];
strcpy(szDeviceName,"PXI1Slot3"); // PXI1Slot3
char szChannel[128];
sprintf(szChannel,"%s/ao0",szChannelName); // PXI1Slot3/ao0
char szTerminal[128];
strcpy(szTerminal,"Onboard Clock"); // Onboard Clock

// reset device
long lReturn = DAQmxResetDevice(szDeviceName);
_AddToLog("DAQmxResetDevice",lReturn);

// create task
lReturn = DAQmxCreateTask("",&m_hTask);
_AddToLog("DAQmxCreateTask",lReturn);

// if that worked...
if(lReturn==0)
{

// create output voltage channel
lReturn = DAQmxCreateAOVoltageChan(
m_hTask,
szChannel,
"",
-1 * dblAmplitude,
dblAmplitude,
DAQmx_Val_Volts,
NULL
);
_AddToLog("DAQmxCreateAOVoltageChan",lReturn);

}

// if that worked...
if(lReturn==0)
{

// define sampling
lReturn = DAQmxCfgSampClkTiming(
m_hTask,
szTerminal,
10*1000,
DAQmx_Val_Rising,
DAQmx_Val_ContSamps,
1000
);
_AddToLog("DAQmxCfgSampClkTiming",lReturn);

}

// if that worked...
if(lReturn==0)
{

// write to buffer
long lWritten = 0;
lReturn = DAQmxWriteAnalogF64(
m_hTask,
1000,
0,
10.0,
DAQmx_Val_GroupByChannel,
data,
&lWritten,
NULL
);

CString strLine;
strLine.Format("Samples per channel written: %d",lWritten);
_AddToLog(strLine);
_AddToLog("DAQmxWriteAnalogF64",lReturn);

}

// if that worked...
if(lReturn==0)
{

// start task
lReturn = DAQmxStartTask(m_hTask);
_AddToLog("DAQmxStartTask",lReturn);

}
else
{

// clean up
_CleanUp();

}

}

void _CleanUp( void )
{

// stop task
long lReturn = DAQmxStopTask(m_hTask);
_AddToLog("DAQmxStopTask",lReturn);

// clear task
lReturn = DAQmxClearTask(m_hTask);
_AddToLog("DAQmxClearTask",lReturn);

}
***** END OF APPLICATION *****


Hello Broccoli,

NI-DAQmx is not a supported API for the NI-5421 AWG. For all NI Signal Generators, please use the NI-FGEN API, which shipped with your instrument. You may also download NI-FGEN (2.2.1 as of today) from

http://digital.ni.com/softlib.nsf/954feaeea92d90918625674b00658b83/8b1f32b4b8f7148586256efd006075a9?OpenDocument

You should find helpful C examples bundled with NI-FGEN that will make using the NI-5421's full capabilities very easy.

Marcos Kirsch
Signal Generators Software Engineer
Marcos Kirsch
Chief Software Engineer
NI Driver Software
0 Kudos
Message 2 of 2
(7,746 Views)