Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Read Error Daqmx in C# .Net

I am using a NI- 6229 usb device and have written a C# dll that is used in Labview and Measurment Studio applications for SPI communications.  It works most of the time yet i get the following message and have not found a root cause for the problem .  I have included the code snipet below where the offending reading is going on.  Any suggestions are welcome



An unhandled exception of type 'NationalInstruments.DAQmx.DaqException' occurred in NationalInstruments.DAQmx.dll

Additional information: Measurements: Some or all of the samples requested have not yet been acquired.


To wait for the samples to become available use a longer read timeout or read later in your program. To make the samples available sooner, increase the sample rate. If your task uses a start trigger,  make sure that your start trigger is configured correctly. It is also possible that you configured the task for external timing, and no clock was supplied. If this is the case, supply an external clock.

 

Property: NationalInstruments.DAQmx.DaqStream.ReadRelativeTo

Corresponding Value: NationalInstruments.DAQmx.ReadRelativeTo.CurrentReadPosition

 

Property: NationalInstruments.DAQmx.DaqStream.ReadOffset

Corresponding Value:

 

 

Task Name: MISOTask

 

Status Code: -200284







        public int[,] ReadBytes(int[] address, int nBytes, string SPI_CLK, string SPI_MOSI, string SPI_MISO, double CLKdelay, double CLKwidth)
        {
            Task MOSITask;
            Task MISOTask;
            Task PulseTask;

            DigitalSingleChannelWriter MOSIWriter;
            DigitalSingleChannelReader MISOReader;

            DigitalWaveform waveform;

            BuildWaveForm(1,address, out waveform); 

            MOSITask = new Task("MOSITask");
            MOSITask.DOChannels.CreateChannel(SPI_MOSI, "", ChannelLineGrouping.OneChannelForAllLines);
            MOSITask.Timing.ConfigureSampleClock("ctr0InternalOutput", 1, SampleClockActiveEdge.Falling, SampleQuantityMode.FiniteSamples, nBytes * 16);

            MOSIWriter = new DigitalSingleChannelWriter(MOSITask.Stream);
            MOSIWriter.BeginWriteWaveform(true, waveform, null, null);

            MISOTask = new Task("MISOTask");
            MISOTask.DIChannels.CreateChannel(SPI_MISO, "", ChannelLineGrouping.OneChannelForAllLines);
            MISOTask.Timing.ConfigureSampleClock("ctr0InternalOutput", 1e6, SampleClockActiveEdge.Rising, SampleQuantityMode.ContinuousSamples, 100);
            MISOReader = new DigitalSingleChannelReader(MISOTask.Stream);
            MISOReader.BeginReadWaveform(-1, null, null);

            PulseTask = new Task();
            PulseTask.COChannels.CreatePulseChannelTime(SPI_CLK, "", COPulseTimeUnits.Seconds, COPulseIdleState.High, 0, CLKdelay, CLKwidth);
            PulseTask.Timing.ConfigureImplicit(SampleQuantityMode.FiniteSamples, nBytes * 16);

            PulseTask.Start();


            for (int task_index = 0; task_index <= 100; task_index++) // allows for 100 * 20 mS = 2 Seconds
            {                                                         // for the task to complete.       
                Thread.Sleep(20);
                if (PulseTask.IsDone) break;
            }

            DigitalWaveform waveformI;
            waveformI = MISOReader.ReadWaveform(nBytes*16);
  
            int[] ReadSPIsamples = new int[nBytes*16];
            int[,] ReadSPI= new int[2, nBytes];

            for (int i = 0; i < waveformI.Samples.Count; i++)
            {
                ReadSPIsamples[i] = (waveformI.Signals[0].States[i] == DigitalState.ForceUp) ? 1 : 0;
            }
            for (int byteindex = 0; byteindex < nBytes; byteindex++)
            {
                int val;
                val=0;
                for(int bitindex=0;bitindex<8;bitindex++)
                {
                    val = val << 1;
                    val=(val+ReadSPIsamples[8+bitindex+byteindex*16]); // shift in the bit
               
                }
                ReadSPI[0, byteindex] = address[byteindex];
                ReadSPI[1, byteindex] = val;
            }


            PulseTask.Dispose();
            MOSITask.Dispose();
            MISOTask.Dispose();
            return ReadSPI;
        }
    }

0 Kudos
Message 1 of 2
(4,723 Views)

Hi and sorry about the frustrations this may be causing,

The error your getting is generally due to a timeout at the DAQmx Read function. Either the number of samples that it expects to receive was never achieved during the time out specified (which looks to be infinite) or the external clock was never supplied. Looking at your code, I think the latter is the case.

Try configuring and starting the counter pulse train before the MISO and MOSI tasks are started or set up a digital start trigger for both MISO and MOSI to begin when the counter task begin. You're probably getting the error during the short, non deterministic, amount of time between starting the two tasks which rely on the ctr0internaloutput for a clock and the counter being setup and outputting said clock.

See if that works for you.

PBear
NI RF
0 Kudos
Message 2 of 2
(4,705 Views)