05-17-2019 08:48 AM
Hello,
I am unable to output a simple waveform at a digital output port. Below is my code:
int numberOfSamples =10000; DigitalWaveform wave = new DigitalWaveform(numberOfSamples, 1, DigitalState.ForceDown); //Add a digital output channel
localTask.AddGlobalChannel(aChannelName);
//Task timings localTask.Timing.SampleTimingType = SampleTimingType.SampleClock; localTask.Timing.ConfigureSampleClock(string.Empty, 2000, SampleClockActiveEdge.Rising, SampleQuantityMode.FiniteSamples);
//Prepare samples. Half of them are low, rest half are high int i = 0; for (i = 0; i < numberOfSamples / 2; i++) wave.Signals[0].States[i] = DigitalState.ForceDown; for (; i < numberOfSamples; i++) wave.Signals[0].States[i] = DigitalState.ForceUp;
DigitalSingleChannelWriter writer = new DigitalSingleChannelWriter(localTask.Stream); writer.WriteWaveform(true, wave);
The above code shall give me one wave of 5 seconds with 2.5 seconds as low and 2.5 seconds as high. Unfortunately, I am not getting desired result.
Please tell me what I am doing incorrect.
Thanks and regards
Ricky
Solved! Go to Solution.
07-09-2019 10:29 AM
Hello Ricky,
What is the result you are seeing?
Depending on what else you are doing, you might want to WaitUntilDone at the end of your code, also see the remarks section in e.g. WriteWaveform Method - NI-DAQmx 17.1 .NET Class Library Help.
Apart from that I assume that your code is just a test for some more complicated output to come. Is that correct? Otherwise you could simply output low, wait 2.5s, output high. If exact timing is needed, you could also consider using a counter.
09-02-2019 01:29 AM
Hi iKaiser,
Thaks for responding.
"..Otherwise you could simply output low, wait 2.5s, output high"
This is what I did as work around. I don't remember if I tried WaitUnilDone as it's long ago and application is working. I will try it if I get this opportunity again or see bugs in future.
Since I wanted to have precise timings, I thought it was better to use DO the way I mentioned. I don't have enough Counters (only 4) and my app needed at least 8, so I decided to use DO.
Will close this thread for now.
Regards
Ricky