From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Sporadic Error 200292

Error -200292

Some or all of the samples to write could not be written to the buffer yet. More space will free up as samples currently in the buffer are generated. To wait for more space to become available, use a longer write timeout. To make the space available sooner, increase the sample rate.

 

I am using a USB6343 X Series DAQ with Visual C# .NET.  On some machines we get the error -200292 when writing with these lines:

      var writer = new AnalogMultiChannelWriter(m_stim.Stream);
      writer.WriteMultiSample(false, m_waveform);

 

We are trying to generate a 60us wide pulse at 2400Hz (416.67 us) on two analog output channels with a phase offset between the channels.  The output buffer contains two cycles worth of data, which comes to 374 samples per channel.  The output generation is continuously retriggered by a frequency counter that is running at a frequency of 1200Hz. There are 42 sample clocks between the end of the generation and the next frequency clock edge, so there should be plenty of time for the hardware to finish generation and set up for the next trigger.

 

The problem is both waveform dependent and host PC dependent.  On my development machine everything works beautifully.  On some of our machines this setting fails consistently and on some it fails intermittently.  We have other waveform settings where everything works well across all of our host PC's.

 

The timeout is already 10 seconds, so increasing the timeout as the message suggests is not going to help anything. We have been able to cure many other sporadic problems of this nature by adjusting the buffer size.  In this case I have adjusted the buffer size so that it holds 1, 2, 3, or 5 complete cycles of data, to no avail.  Our other successful settings have both more data and less data than this setting. 

 

I am at a loss for what to try next.  Any suggestions?

 

I have included a simplified version of our generation code:

/// <summary>
/// Start a dual electrode stimulation train.  The pulse amplitudes are independently specified for each channel, but the pulse
/// train timing is identical for both channels.
///
/// The stimulation pulse train consists of a negativing going current pulse at the specified width
/// and amplitude then a 50 usec gap then a positive going current pulse at the specifed width and amplitude, followed by a rest
/// for the remainder of the period corresponding to the specified frequency.  If the period is so short that it cannot support
/// a 50usec pause after each pulse, then the available rest time in the period will be split equally.  Note that the peak to peak
/// amplitude is twice the specified amplitude.
///
/// For frequencies below 1KHz, the positive going pulse has double the specified pulse width and half the amplitude of the
/// negative going pulse
///
/// If onTime and offTime are specified then pulse trains will be delivered during the ontime followed by a pause for the offTime
/// perior to restarting the sequence.  For the transition between ON-OFF, a partial pulse train will be delivered if both positive
/// and negative pulses can be delivered prior to the expiration of the ON time.  If onTime or offTime is not specified, then the
/// pulse train is restarting.
/// </summary>
/// <param name="amplitude1">amplitude of stimulation pulse on the first channel [V]</param>
/// <param name="amplitude2">amplitude of stimulation pulse on the second channel [V]</param>
/// <param name="frequency">frequency of pulse stimulation [Hz]</param>
/// <param name="pulseWidth">width of single stimulation pulse [uS]</param>
/// <param name="channel2Delay">% cycle delay of channel 2 relative to channel 1</param>
public static void StartDualStim(double amplitude1, double amplitude2,
                                 int frequency, double pulseWidth, double channel2Delay = 0.0)
{
  try
  {
    var period = 1.0 / frequency; //desired period

    m_stim = new Task();
    m_frequencyClock = new Task();
    m_stim.AOChannels.CreateVoltageChannel(m_daq.AOPhysicalChannels[0], "stim0", -MaxOutputVoltage, MaxOutputVoltage, AOVoltageUnits.Volts);
    m_stim.AOChannels.CreateVoltageChannel(m_daq.AOPhysicalChannels[1], "stim1", -MaxOutputVoltage, MaxOutputVoltage, AOVoltageUnits.Volts);
    m_stim.Control(TaskAction.Verify);

    //to minimize timing error we need to make the pulse width an even multiple of the sampling clock time
    var n = (int) Math.Floor(4000 * pulseWidth * 1e-6 / period);

    //If necessary, decrease the sampling multiple to to stay below the DAQ's maximum sampling rate
    var maxSamplingRate = m_daq.AIMaximumMultiChannelRate;
    //the output max rate is higher, but the sample clock balks if you use that number
    n = Math.Min(n, (int) Math.Floor(maxSamplingRate * pulseWidth * 1e-6));

    //determine how many ticks are used to make the pulse width
    var tickTime = pulseWidth * 1e-6 / n;
    var samplingRate = 1 / tickTime;

    m_stim.Timing.ConfigureSampleClock("", samplingRate, SampleClockActiveEdge.Rising, SampleQuantityMode.FiniteSamples);

    //actual sampling rate may deviate from requested, so recalculate
    tickTime = 1 / m_stim.Timing.SampleClockRate;
    var periodTicks = (int) Math.Round(period / tickTime);
    period = periodTicks * tickTime; //actual period given hardware limitations
    var channel2ShiftTicks = (int) (periodTicks * channel2Delay);

    //DAQ can sometimes shutoff if the number of samples is too small.  This problem is PC dependent, not DAQ dependent.  
    //For frequencies above 4kHz we will define two or three complete periods instead of one to increase the sample count.
    var periodCount = (int) Math.Ceiling(.33e-3 / period) + 1;

    var pulseTicks = (int) Math.Round(pulseWidth * 1e-6 / tickTime);

    m_frequencyClock.COChannels.CreatePulseChannelFrequency(m_daq.COPhysicalChannels[3], "stimFreq0", COPulseFrequencyUnits.Hertz, COPulseIdleState.Low, 0, frequency, 0.5);
    m_frequencyClock.Control(TaskAction.Verify);
    m_frequencyClock.Timing.ConfigureImplicit(SampleQuantityMode.ContinuousSamples, 100);

    var gapTicks = (periodTicks - 2 * pulseTicks) / 2;
    var leftoverTicks = periodTicks - pulseTicks * 2 - gapTicks - channel2ShiftTicks - 3;

    m_waveform = new double[2, periodTicks * periodCount - leftoverTicks];
    for (var i = 0; i < m_waveform.GetLength(1); i++)
    {
      var cycleTick = i % periodTicks;
      if (cycleTick < pulseTicks)
        m_waveform[0, i] = -amplitude1;
      else if (pulseTicks + gapTicks <= cycleTick && cycleTick < gapTicks + pulseTicks * 2)
        m_waveform[0, i] = amplitude1;
      else
        m_waveform[0, i] = 0.0;

      if (channel2ShiftTicks <= cycleTick && cycleTick < pulseTicks + channel2ShiftTicks)
        m_waveform[1, i] = -amplitude2;
      else if (pulseTicks + gapTicks + channel2ShiftTicks <= cycleTick && cycleTick < gapTicks + pulseTicks * 2 + channel2ShiftTicks)
        m_waveform[1, i] = amplitude2;
      else
        m_waveform[1, i] = 0.0;

      var writer = new AnalogMultiChannelWriter(m_stim.Stream);
      writer.WriteMultiSample(false, m_waveform);

      m_stim.Timing.SampleQuantityMode = SampleQuantityMode.FiniteSamples;
      m_stim.Timing.SamplesPerChannel = m_waveform.GetLength(1);
    }

    m_stim.Triggers.StartTrigger.Type = StartTriggerType.DigitalEdge;
    m_stim.Triggers.StartTrigger.Retriggerable = true;
    m_stim.Triggers.StartTrigger.DigitalEdge.Edge = DigitalEdgeStartTriggerEdge.Rising;
    m_stim.Triggers.StartTrigger.DigitalEdge.Source = "/" + m_frequencyClock.COChannels[0].PhysicalName + "InternalOutput";

    m_stim.Control(TaskAction.Verify);
    m_stim.Start();
    m_frequencyClock.Start();
  }
  catch (Exception exception)
  {
    SessionViewModel.WriteLogEntry("DAQ_Exception", exception.Message);
    SessionViewModel.GetInst().StimSessionMessageText = exception.Message + "\nDAQ Exception";
    throw;
  }
}

0 Kudos
Message 1 of 2
(2,696 Views)

Hello Drury,

 

It has passed some time, are you still having these error? I found similar forum posts that I'm sure you have already looked at but just in case:

1. https://forums.ni.com/t5/Multifunction-DAQ/Digital-output-error-200292/td-p/1030945

2. http://forums.ni.com/t5/Multifunction-DAQ/Generating-4-analog-output-waveforms-with-different-freque...

3. http://natinst.public.daq.digital.general.narkive.com/7u7Apsh2/help-on-2-digital-out-signals

About the computer differences, can you tell me the RAM capacity of the computers where you have tested this code as well as the results? In can even be related with other programs RAM demands so it would be nice to test this code without other programs.

0 Kudos
Message 2 of 2
(2,559 Views)