Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

(C code) Sending n triggers with AO waveform

Hello everyone,

 

I am trying to do the following: I have C++ code that generates a waveform on an analog out channel of a PCIe-6321. This works well. Now, in certain conditions I also want to send a number of triggers for each wave period. So far, I have failed to achieve this... I have made many changes to the below code and the latest error is "Write cannot be performed because this version of DAQmx Write does not match the type of channels in the task." when writing to ao_task, even though I have spent half a day making sure I am not mixing my task handles.

 

I am really stumped. Can anyone see what I am doing wrong?

 

Thank you!!

Peter

 

Pseudo-code without error handling elements:

 

boolean trigger = true;

string name = "ao_task";

TaskHandle ao_task;
TaskHandle do_task;

DAQmxClearTask(ao_task);
DAQmxCreateTask(name.c_str(), &ao_task);

uInt32 buffer_size = 1;
DAQmxGetBufOutputOnbrdBufSize(ao_task, &buffer_size);

uInt32 n_channels = 2;

int32 samples = buffer_size / n_channels;
int32 sampling = DAQmx_Val_ContSamps;
uInt64 sample_number = 1;
double frequency = 10;

DAQmxCfgSampClkTiming(ao_task, "", samples*frequency, DAQmx_Val_Rising, sampling, samples*sample_number);

if (trigger) {
	DAQmxClearTask(do_task);
	DAQmxCreateTask("DOTrigger", &ao_task);
	DAQmxCreateDOChan(do_task, "Dev1/port0/line0", "nDO", DAQmx_Val_ChanForAllLines);

	DAQmxCfgSampClkTiming(do_task, "/Dev1/ao/SampleClock", samples*frequency, DAQmx_Val_Rising, sampling, 2);

	DAQmxCfgDigEdgeStartTrig(do_task, "/Dev1/ao/StartTrigger", DAQmx_Val_Rising);

	uInt8 trigger_data[2] = { 0, 1 };
	int32 * samplesWritten = 0;

	DAQmxWriteDigitalLines(do_task, 2, false, 2, DAQmx_Val_GroupByChannel, trigger_data, samplesWritten, NULL);

	DAQmxStartTask(do_task);
}

float64* analog_data = new float64[buffer_size]; // Followed by other code that generates a wave shape.

int32 samples_written = 0;

DAQmxWriteAnalogF64(ao_task, samples, false, 2, DAQmx_Val_GroupByScanNumber, analog_data, &samples_written, NULL);

DAQmxStartTask(ao_task);

  

0 Kudos
Message 1 of 1
(2,062 Views)