RunBlock() private method

private RunBlock ( short handle, int noOfPreTriggerSamples, int noOfPostTriggerSamples, uint timebase, short oversample, int &timeIndisposedMs, ushort segmentIndex, ps4000BlockReady lpps4000BlockReady, IntPtr pVoid ) : short
handle short
noOfPreTriggerSamples int
noOfPostTriggerSamples int
timebase uint
oversample short
timeIndisposedMs int
segmentIndex ushort
lpps4000BlockReady ps4000BlockReady
pVoid System.IntPtr
return short
Beispiel #1
0
        /****************************************************************************
        * RapidBlockDataHandler
        * - Used by all the CollectBlockRapid routine
        * - acquires data (user sets trigger mode before calling), displays 10 items
        *   and saves all to data.txt
        * Input :
        * - nRapidCaptures : the user specified number of blocks to capture
        ****************************************************************************/
        private void RapidBlockDataHandler(ushort nRapidCaptures)
        {
            short status;
            int   numChannels = _channelCount;
            uint  numSamples  = BUFFER_SIZE;

            // Run the rapid block capture
            int timeIndisposed;

            _ready = false;

            _callbackDelegate = BlockCallback;
            Imports.RunBlock(_handle,
                             0,
                             (int)numSamples,
                             _timebase,
                             _oversample,
                             out timeIndisposed,
                             0,
                             _callbackDelegate,
                             IntPtr.Zero);



            Console.WriteLine("Waiting for data...Press a key to abort");

            while (!_ready && !Console.KeyAvailable)
            {
                Thread.Sleep(100);
            }
            if (Console.KeyAvailable)
            {
                Console.ReadKey(true);                       // clear the key
            }
            Imports.Stop(_handle);


            // Set up the data arrays and pin them
            short[][][] values = new short[nRapidCaptures][][];
            PinnedArray <short>[,] pinned = new PinnedArray <short> [nRapidCaptures, numChannels];

            for (ushort segment = 0; segment < nRapidCaptures; segment++)
            {
                values[segment] = new short[numChannels][];
                for (short channel = 0; channel < numChannels; channel++)
                {
                    if (_channelSettings[channel].enabled)
                    {
                        values[segment][channel] = new short[numSamples];
                        pinned[segment, channel] = new PinnedArray <short>(values[segment][channel]);

                        status = Imports.SetDataBuffersRapid(_handle,
                                                             (Imports.Channel)channel,
                                                             values[segment][channel],
                                                             (int)numSamples,
                                                             segment);
                    }
                    else
                    {
                        status = Imports.SetDataBuffersRapid(_handle,
                                                             (Imports.Channel)channel,
                                                             null,
                                                             0,
                                                             segment);
                    }
                }
            }

            // Read the data
            short[] overflows = new short[nRapidCaptures];

            status = Imports.GetValuesRapid(_handle, ref numSamples, 0, (ushort)(nRapidCaptures - 1), overflows);



            /* Print out the first 10 readings, converting the readings to mV if required */
            Console.WriteLine("\nValues in {0}", (_scaleVoltages) ? ("mV") : ("ADC Counts"));

            for (int seg = 0; seg < nRapidCaptures; seg++)
            {
                Console.WriteLine("Capture {0}", seg);
                for (int i = 0; i < 10; i++)
                {
                    for (int chan = 0; chan < _channelCount; chan++)
                    {
                        Console.Write("{0}\t", _scaleVoltages ?
                                      adc_to_mv(pinned[seg, chan].Target[i], (int)_channelSettings[(int)(Imports.Channel.ChannelA + chan)].range)           // If _scaleVoltages, show mV values
                                                : pinned[seg, chan].Target[i]);                                                                             // else show ADC counts
                    }
                    Console.WriteLine();
                }
                Console.WriteLine();
            }

            // Un-pin the arrays
            foreach (PinnedArray <short> p in pinned)
            {
                if (p != null)
                {
                    p.Dispose();
                }
            }

            //TODO: Do what ever is required with the data here.
        }
Beispiel #2
0
        /****************************************************************************
        * BlockDataHandler
        * - Used by all block data routines
        * - acquires data (user sets trigger mode before calling), displays 10 items
        *   and saves all to data.txt
        * Input :
        * - unit : the unit to use.
        * - text : the text to display before the display of data slice
        * - offset : the offset into the data buffer to start the display's slice.
        ****************************************************************************/
        void BlockDataHandler(string text, int offset)
        {
            uint sampleCount = BUFFER_SIZE;

            PinnedArray <short>[] minPinned = new PinnedArray <short> [_channelCount];
            PinnedArray <short>[] maxPinned = new PinnedArray <short> [_channelCount];

            int timeIndisposed;

            for (int i = 0; i < _channelCount; i++)
            {
                short[] minBuffers = new short[sampleCount];
                short[] maxBuffers = new short[sampleCount];
                minPinned[i] = new PinnedArray <short>(minBuffers);
                maxPinned[i] = new PinnedArray <short>(maxBuffers);
                int status = Imports.SetDataBuffers(_handle, (Imports.Channel)i, maxBuffers, minBuffers, (int)sampleCount);
            }

            /*  find the maximum number of samples, the time interval (in timeUnits),
             *		 the most suitable time units, and the maximum _oversample at the current _timebase*/
            int timeInterval;
            int maxSamples;

            while (Imports.GetTimebase(_handle, _timebase, (int)sampleCount, out timeInterval, _oversample, out maxSamples, 0) != 0)
            {
                Console.WriteLine("Selected timebase {0} could not be used\n", _timebase);
                _timebase++;
            }
            Console.WriteLine("Timebase: {0}\toversample:{1}\n", _timebase, _oversample);

            /* Start it collecting, then wait for completion*/
            _ready            = false;
            _callbackDelegate = BlockCallback;
            Imports.RunBlock(_handle, 0, (int)sampleCount, _timebase, _oversample, out timeIndisposed, 0, _callbackDelegate, IntPtr.Zero);

            /*Console.WriteLine("Run Block : {0}", status);*/
            Console.WriteLine("Waiting for data...Press a key to abort");

            while (!_ready && !Console.KeyAvailable)
            {
                Thread.Sleep(100);
            }
            if (Console.KeyAvailable)
            {
                Console.ReadKey(true);                       // clear the key
            }
            Imports.Stop(_handle);

            if (_ready)
            {
                short overflow;
                Imports.GetValues(_handle, 0, ref sampleCount, 1, Imports.DownSamplingMode.None, 0, out overflow);

                /* Print out the first 10 readings, converting the readings to mV if required */
                Console.WriteLine(text);
                Console.WriteLine("Value {0}", (_scaleVoltages) ? ("mV") : ("ADC Counts"));

                for (int ch = 0; ch < _channelCount; ch++)
                {
                    Console.Write("   Ch{0}    ", (char)('A' + ch));
                }
                Console.WriteLine();

                for (int i = offset; i < offset + 10; i++)
                {
                    for (int ch = 0; ch < _channelCount; ch++)
                    {
                        if (_channelSettings[ch].enabled)
                        {
                            Console.Write("{0,6}    ", _scaleVoltages ?
                                          adc_to_mv(maxPinned[ch].Target[i], (int)_channelSettings[(int)(Imports.Channel.ChannelA + ch)].range) // If _scaleVoltages, show mV values
                                : maxPinned[ch].Target[i]);                                                                                     // else show ADC counts
                        }
                    }
                    Console.WriteLine();
                }

                sampleCount = Math.Min(sampleCount, BUFFER_SIZE);
                TextWriter writer = new StreamWriter("block.txt", false);
                writer.Write("For each of the {0} Channels, results shown are....", _channelCount);
                writer.WriteLine();
                writer.WriteLine("Time interval Maximum Aggregated value ADC Count & mV, Minimum Aggregated value ADC Count & mV");
                writer.WriteLine();

                for (int i = 0; i < _channelCount; i++)
                {
                    writer.Write("Time  Ch  Max ADC    Max mV   Min ADC    Min mV   ");
                }
                writer.WriteLine();



                for (int i = 0; i < sampleCount; i++)
                {
                    for (int ch = 0; ch < _channelCount; ch++)
                    {
                        writer.Write("{0,4}  ", (i * timeInterval));
                        if (_channelSettings[ch].enabled)
                        {
                            writer.Write("Ch{0} {1,7}   {2,7}   {3,7}   {4,7}   ",
                                         (char)('A' + ch),
                                         maxPinned[ch].Target[i],
                                         adc_to_mv(maxPinned[ch].Target[i],
                                                   (int)_channelSettings[(int)(Imports.Channel.ChannelA + ch)].range),
                                         minPinned[ch].Target[i],
                                         adc_to_mv(minPinned[ch].Target[i],
                                                   (int)_channelSettings[(int)(Imports.Channel.ChannelA + ch)].range));
                        }
                    }
                    writer.WriteLine();
                }
                writer.Close();
            }
            else
            {
                Console.WriteLine("data collection aborted");
                WaitForKey();
            }

            foreach (PinnedArray <short> p in minPinned)
            {
                if (p != null)
                {
                    p.Dispose();
                }
            }
            foreach (PinnedArray <short> p in maxPinned)
            {
                if (p != null)
                {
                    p.Dispose();
                }
            }
        }