Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to output waveform

Solved!
Go to solution

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

0 Kudos
Message 1 of 3
(2,602 Views)
Solution
Accepted by topic author dotNet_to_LabW

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.


Ingo – LabVIEW 2013, 2014, 2015, 2016, 2017, 2018, NXG 2.0, 2.1, 3.0
CLADMSD
Message 2 of 3
(2,446 Views)

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

0 Kudos
Message 3 of 3
(2,337 Views)