Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

slow performance for digital write method WriteSingleSampleSingleLine

 digitalWriteTask = new Task();


digitalWriteTask.DOChannels.CreateChannel(physicalChannelComboBox.Text,"",
                        ChannelLineGrouping.OneChannelForAllLines);

 

digitalWriteTask.Timing.ConfigureSampleClock(clockSourceTextBox.Text,
    10000000,
    SampleClockActiveEdge.Rising, SampleQuantityMode.FiniteSamples, (int)totalSamplesToGen);

 

digitalWriteTask.Stream.ConfigureOutputBuffer(totalSamplesToGen);


writer = new DigitalSingleChannelWriter(digitalWriteTask.Stream);

digitalWriteTask.Control(TaskAction.Verify);


writer = new DigitalSingleChannelWriter(digitalWriteTask.Stream);


// The real problem is in the following code .. since the method writeSingleSampleSingleLine execute properly
and even write the data but it is writing tool slow.. for example if the totalSamplesToGen is greater 30000000
it takes around 20minutes to write that dat to output buffer.. I need a approach through which I can write data
to output buffer very fast.


                     while (boolArrayCounter < totalSamplesToGen)
                     {

                          writer.WriteSingleSampleSingleLine(false, aBufferBool[boolArrayCounter++]);


                     }


                     digitalWriteTask.Start();

 

Thanks

Umair

0 Kudos
Message 1 of 7
(5,203 Views)

omee,
Could you please provide some more information?

  • What hardware are you using to do your Digital Writes?
  • What version of .NET are you using?
  • How fast are you intending to write the digital samples?

There are great examples that show how to do digital generation located at: <Public Documents>\National Instruments\NI-DAQ\Examples\


You can also find the link on the Start Menu > All Programs > National Instruments > NI-DAQmx > Text-Based Code Support.

 

I believe if you follow these examples, you should be able to improve your write speed, as long as it is not a limitation of the hardware.

Jared A.
Applications Engineer
National Instruments
0 Kudos
Message 2 of 7
(5,194 Views)

HI,

1) I am using NI PCI 6251 hardware for my digital writes.

2) I am using .net framework 3.5

3) According to the documentation 6251 supports digital data rate upto 10mbps. I am just trying to write data at 2mbps to  6 mbps.

 

As far as the examples are concerned I have refer to them previously and also read the documentation for .net and NI Card. But could not find the solution.

 

In simple words my problem is I want to send a data file from my computer to an external system serially and using external clock.

 

For that I have configure Digital Data output channel and configure an external clock.

To write data I have used method writer.WriteSingleSampleSingleLine().

 

Now what is hapenning is that the card output the data ifrom the buffer at the desired rate but when my program writing to the buffer extremely slow .. slower than desired rate.

 

 

 

 

 

 

 

0 Kudos
Message 3 of 7
(5,186 Views)

Hi omee,

 

It seems to be that your limitation in speed is because you are using the WriteSingleSampleSingleLine to loop through and write the samples from your array one at a time which can be quite slow in .NET. You are basically filling the buffer up with 30 million samples before you even begin writing. I would suggest using the WriteWaveform instead to write the data to the buffer at one time. This method accepts an object of the DigitalWaveform type so you will have to covert your array to this format to use it which will likely take a signicant chunk of processing time as well. Using this method you can try setting autoStart to true in the call so that data will begin being written to the buffer, and the data transfer will start so you do not have to wait.

Justin D
Applications Engineer
National Instruments
http://www.ni.com/support/
0 Kudos
Message 4 of 7
(5,179 Views)

Hi Justin

I am filling up the buffer before I start it because if i dont do that there will be higher amount of repetetion in the output data.

 

I have do the same thing with the help of DigitalWaveform object and writeWaveform method, when my samples start to increase more than 2 mega samples windows xp causing out of memory exception. Because DigitalWaveform consumes memory in greater than 2 GB and maximum  process of size of windows xp is 2GB. 

 

If I am having a small number of  samples than it is an acceptable solution but I have to send large data files.

Code which I have written to work with DigitalWaveform object and WriteWaveform method is:

 

 

 

DigitalWaveform  custDigWave;

public void writeData()
{
writer.WriteWaveform(true, custDigWave);

}

     
UploadData()
{
 DigitalWaveform customizedWaveform = new DigitalWaveform( 50000000, 1); // it is configured for only 1 signal.. greaer number of samples cause out of memory exception

            

         

            


          for (int i = 0; i < aBufferBool.Length; i++)
          {

              if (aBufferBool[i])
              {





              }
              else
              {
                  customizedWaveform.Samples[0].States[i] = DigitalState.ForceDown;

     
              }

          }

          System.GC.Collect(System.GC.MaxGeneration, GCCollectionMode.Forced);

          custDigWave = customizedWaveform;

}

 

0 Kudos
Message 5 of 7
(5,175 Views)

Hi omee,

 

You can try breaking your DigitalWaveforms up in to smaller chunks and writing those chunks one at a time to avoid the memory problems.  For instance, you should be able to generate a set of 100000 samples in a DigitalWaveform then start that data being written using the asynchronous BeginWriteWaveform.  While that data is being written, begin creating a new DigitalWaveform with the next set of samples and write it to the device.  You will need to provide the samples to the device's buffer faster than the device is outputting data so that there is not a break in the digital output.  How fast is the clocking for your device's output?

Justin D
Applications Engineer
National Instruments
http://www.ni.com/support/
0 Kudos
Message 6 of 7
(5,169 Views)

I can try out this solution for sending data in chunks with the help of WaveForm object.

My data rate vary from 2 mbps to 10mbps.

 

thanks Justin.

0 Kudos
Message 7 of 7
(5,167 Views)