Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Digitial I/O Using USB-6229

This is the C# code snippet I am trying to use to generate a SPI interface using 2 digital line and a counter output of the USB-6229.  The digital waveform is create and output correctly.  The issue I seem to have is with the Digital input.  I physically have the output line connect to the input line.  The output is "clocked" out on the falling edge of the counter pulse.  My intention was to sample the input data on the rising edge of the counter pulse.  I get the following error message.

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

Additional information: Measurements: Attempted to read a sample beyond the final sample acquired. The acquisition has stopped, therefore the sample specified by the combination of position and offset will never be available."

          

            Task MOSITask;
            Task MISOTask;
            Task PulseTask;

            DigitalSingleChannelWriter MOSIWriter;
            DigitalSingleChannelReader MISOReader;

            DigitalWaveform waveform;

            BuildWaveForm(address, data, nBytes, out waveform);

            MOSITask = new Task("MOSITask");
            MOSITask.DOChannels.CreateChannel("dev2/Port0/line0:1", "", ChannelLineGrouping.OneChannelForAllLines);
            MOSITask.Timing.ConfigureSampleClock("ctr0InternalOutput", 1, SampleClockActiveEdge.Falling, SampleQuantityMode.FiniteSamples, 16);

            MISOTask = new Task("MISOTask");
            MISOTask.DIChannels.CreateChannel("dev2/Port0/Line2", "", ChannelLineGrouping.OneChannelForAllLines);
            MISOTask.Timing.ConfigureSampleClock("ctr0InternalOutput", 1e6, SampleClockActiveEdge.Rising, SampleQuantityMode.FiniteSamples, 16);

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

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


            MISOTask.Start();
            MISOReader = new DigitalSingleChannelReader(MISOTask.Stream);
            MISOReader.BeginReadWaveform(16, null, null);
            

            PulseTask.Start();

            DigitalWaveform waveformI;
            waveformI = MISOReader.ReadWaveform(16);



Thanks for any inputs
0 Kudos
Message 1 of 2
(3,163 Views)

Hi,

After doing some research your problem looks to be that you are trying to read samples after the card has stop acquiring. The number if this error is 200278 and it can be fix in two ways you can either set your timing to continuous, not finite acquisition like it is set right now, or you can stop the task when the N sample have been acquire.

Take a look at this knowledgebase:  Error -200278 at DAQmx Read and this discussion forum: Error -200278.

Let me know if it helps

Jaime Hoffiz
National Instruments
Product Expert
0 Kudos
Message 2 of 2
(3,147 Views)