10-10-2011 01:06 PM
Running in Windows 7 64bit
Compiling in Visual Studio 2008 Professional Edition
using the NI PXIe-6363 card
I can create the Digital waveform no problem. My problem arises when I try to use BeginWriteWaveform to put the writing of the waveform in the background.
All of this in the attached zip, but I'll reproduce it here, I'm setting up 2 channels to output some digital pulses.
Here's how I set up the task:
private const string TRIGGER_CHANNEL = "PXI1Slot2/port0/line0";
private const string TTL_A_CHANNEL = "PXI1Slot2/port0/line1";
private const string TTL_B_CHANNEL = "PXI1Slot2/port0/line2";
signalTask = new Task();
signalTask.DOChannels.CreateChannel( TRIGGER_CHANNEL, "Signal", ChannelLineGrouping.OneChannelForEachLine); signalTask.DOChannels.CreateChannel( TTL_A_CHANNEL, "TTL_A", ChannelLineGrouping.OneChannelForEachLine);
signalTask.Timing.ConfigureSampleClock( "", signalClock, SampleClockActiveEdge.Rising, SampleQuantityMode.FiniteSamples); signalTask.Control(TaskAction.Verify); signalTask.Stream.WriteRegenerationMode = WriteRegenerationMode.DoNotAllowRegeneration; signalWriter = new DigitalMultiChannelWriter(signalTask.Stream); signalWriter.SynchronizeCallbacks = true; signalCallback = new AsyncCallback(SignalCallback);
and here is how I output the waveform:
private void btn_Start_Click(object sender, EventArgs e)
{
Int32 signals = signalTask.DOChannels.Count;
DigitalWaveform[] wave = new DigitalWaveform[signals];
int pulse = (int)numE_pulse.Value;
int samples = pulse * 4;
for (int i = 0; i < signals; ++i)
{
wave[i] = new DigitalWaveform(samples, 1, DigitalState.ForceDown);
for (int j = 0; j < pulse; ++j)
{
wave[i].Signals[0].States[j + i*2] = DigitalState.ForceUp;
wave[i].Signals[0].States[(j + 2*pulse) + i * 2] = DigitalState.ForceUp;
}
}
signalTask.Timing.ConfigureSampleClock(
"",
signalClock,
SampleClockActiveEdge.Rising,
SampleQuantityMode.FiniteSamples,
samples);
btn_Start.Enabled = false;
signalWriter.BeginWriteWaveform(
true,
wave,
signalCallback,
null);
/*
signalWriter.WriteWaveform(true, wave);
signalTask.WaitUntilDone();
signalTask.Stop();
btn_Start.Enabled = true;
*/
If I comment out the section where I BeginWriteWaveform(), and uncomment out the section where I WriteWaveform(), WaitUntilDone(), and Stop(), I get the proper digital signal out. So I know I'm creating the wafeform correctly.
If I do the reverse, and try to use the BeginWriteWaveform(), I don't get the proper digital signal out. Usually one of the lines goes high, and never returns to zero.
Is there anything I'm missing?
10-11-2011 07:52 PM
Hello dknovick,
Have you been able to successfully run the shipping examples? Do you see any strange behavior when running those?
10-12-2011 05:49 PM
Thanks for the reply.
Can you point me to an example that might be similar? These are the samples that were installed:
ContWriteDigChan_Burst - uses burst mode
ContWriteDigChan_PipeSampClk - interfaces to the NI 6536/7
ContWriteDigChan_PipeSampClokwHshk - interfaces to the NI 6536/7
ContWriteDigPort_ExtClk - uses .WriteMultiSamplePort()
WriteDigChan - uses .WriteSingleSampleMultiLine()
WriteDigChan_ExtClk - uses .WriteWaveform()
WriteDigChan_WatchdogTimer - doesn't use a DigitalWaveform
WriteDigPort - uses .WriteSingleSamplePort()
-Dave
10-14-2011 09:36 AM
Hi Dave,
Do you know if your BeginWriteWaveform is finishing and calling SignalCallback? I took a look at your code, and you seem to be calling everything properly, and if WriteWaveform works, then the async call should work also.
Regards,
Matt
10-17-2011 11:00 AM
@Matt.M wrote:
Hi Dave,
Do you know if your BeginWriteWaveform is finishing and calling SignalCallback? I took a look at your code, and you seem to be calling everything properly, and if WriteWaveform works, then the async call should work also.
Regards,
Matt
Thanks for double checking things. I was pretty sure it was being called, since I disble the button before BeginWriteWaveform and enable it inside SignalCallback (one of my own tests to see if it was being called). Just to be sure, I added a 1sec sleep inside SignalCallback before I enable the button. And sure enough, with the code section around BeginWriteWaveform running, the button is disable, and then 1 sec later, it's enable again.
I was able to get this to work by creating my own asynchronous task. I created a sendDigitalWaveform() function and a delegate function as well. Then inside btn_Start_Click(), I create a new delegate, and then BeginInvoke().
Inside the function, I'm still doing:
WriteWaveform()
WaitUntilDone()
Stop()
...
Not very elegant.
-Dave