I have an application using a USB-6341 to control a process machine. One of the tasks is producing a predetermined analog output voltage waveform to control a heater cycle, which has two parts ... let's call them "A" and "B" (really ramp and soak, fwiw). Usually waveform B should be run immediately after A completes, but occasionally A needs to be truncated (already hot enough), then B needs to run.
I have tried a couple ways to make this happen, but I'm running into errors when I try to rewrite waveform B into the task. I have been trying to do it using finite generation mode so that I can make use of the "DAQmx IsTaskDone.vi" to know when it is complete, since all of this is happening in one of several subroutine vi's that let the machine multitask with limited polling to each subroutine.
My wish list:
One possible solution would be to write out A+B as a single finite task, monitor during "A" whether we need to cut it short, and if so, force the pointer of the output write buffer to jump to the beginning of "B". Is that possible? How?
I have tried to just stop the task and write a new waveform to DAQmx_Write. It works once, but generates an error -200292.
I also tried stopping the task, calling DAQmx_Timing_(UseWaveform).vi with waveform B to get the buffer and sampling clocks reset for "B", then write the new waveform to DAQmx_Write. Also works once, but generates error -200557 saying task must be stopped first. Odd, since the DAQmx Stop was called immediately before DAQmx Timing ... maybe there is some latency waiting for the current sample to ouput before the state change?
Suggestions or solutions would be much appreciated
One brute force method would be to use two AO channels, one for A and the other for B. Add an external analog switch and control it with a digital output line. When you need to switch, start B and use the DO line to switch from A to B with the external switch. A can just run to completion or stop the task - since A is not longer connected to your heater control it does not matter.
I'm most of the way there ... but getting some behavior that I don't understand. Here's what I'm doing
This sequence gets me the physical behavior I need, without creating any errors or leaving the AO task in a bad state for the next time around. But the one quirk is that the AO outputs multiple cycles of the waveform B. The heater doesn't respond because of the digital disable line, but on the monitor line I have connected to the power level (AO) output, I end up with waveform B regenerating. EVEN THOUGH DAQmx_STOP WAS CALLED!!
Can anyone lend some insight here? Here's a visual of what's going on:
The light Blue line is a plot of what a simple A+B would look like. The green is the temperature monitor of the thing getting heated, and the red is the monitor of the analog output being sent to the heater. You can see that the early switch A-->B happens as desired when the green hits the threshold. But why does the output continue from B to a second repeat of B even after DAQmx STOP?
BTW, I tried throwing in a DoNotAllowRegeneration property node between the Timing setup and the first write, but then I end up with an error from IsTaskDone at the end when I haven't supplied any more data and it has completed the generation. (err -200290)
I'm not sure what else to suggest for you main setup - my instinct would have been to set the DoNotAllowRegenerationProperty. However, it looks like you can potentially address error -200290 by increasing the output buffer size.
From LabVIEW -> Explain Error:
"Error -200290 occurred at an unidentified location
The generation has stopped to prevent the regeneration of old samples. Your application was unable to write samples to the background buffer fast enough to prevent old samples from being regenerated.
To avoid this error, you can do any of the following:
1. Increase the size of the background buffer by configuring the buffer.
2. Increase the number of samples you write each time you invoke a write operation.
3. Write samples more often.
4. Reduce the sample rate.
5. If your data transfer method is interrupts, try using DMA or USB Bulk.
6. Reduce the number of applications your computer is executing concurrently.
In addition, if you do not need to write every sample that is generated, you can configure the regeneration mode to allow regeneration, and then use the Position and Offset attributes to write the desired samples."