Ejemplo n.º 1
0
        /****************************************************************************
         * BlockDataHandler
         * - Used by all block data routines
         ****************************************************************************/
        void BlockDataHandler()
        {
            short status;
            uint sampleCount = BUFFER_SIZE;
            int timeIndisposed;
            int timeInterval;
            int maxSamples;

            // Clear data buffers
            for (int i = 0; i < ENABLED_CHANNELS; i++)
            {
                Array.Clear(minBuffers, 0, minBuffers.Length);
                Array.Clear(maxBuffers, 0, maxBuffers.Length);
            }

            while (Imports.GetTimebase(_handle, _timebase, (int)sampleCount, out timeInterval, _oversample, out maxSamples, 0) != 0)
                _timebase++;

            _ready = false;
            _callbackDelegate = BlockCallback;
            status = Imports.RunBlock(
                _handle,
                0,
                (int)sampleCount,
                _timebase,
                _oversample,
                out timeIndisposed,
                0,
                _callbackDelegate,
                IntPtr.Zero
            );

            while (!_ready)
                Thread.Sleep(1);

            Imports.Stop(_handle);
            if (_ready)
            {
                short overflow;
                status = Imports.GetValues(
                    _handle,
                    0,
                    ref sampleCount,
                    NSAMPLES,
                    Imports.PS6000DownSampleRatioMode.PS6000_RATIO_MODE_AGGREGATE,
                    0,
                    out overflow
                );

                for (int i = 0; i < sampleCount; i++)
                {
                    for (int ch = 0; ch < ENABLED_CHANNELS; ch++)
                    {
                        float max = minPinned[ch].Target[i];
                        float min = maxPinned[ch].Target[i];
                        processPeakToPeak(ch, max - min);
                    }
                }
            }
        }
Ejemplo n.º 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)
        {
            short status;
              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);
            status = Imports.SetDataBuffers(_handle, (Imports.Channel)i, maxBuffers, minBuffers, (int)sampleCount, Imports.PS6000DownSampleRatioMode.PS6000_RATIO_MODE_NONE);
              }

              /*  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)
              {
            _timebase++;
              }
              Console.WriteLine("Timebase: {0}\toversample:{1}", _timebase, _oversample);

              /* Start it collecting, then wait for completion*/
              _ready = false;
              _callbackDelegate = BlockCallback;
              status = Imports.RunBlock(_handle, 0, (int)sampleCount, _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);

              if (_ready)
              {
            short overflow;
            status = Imports.GetValues(_handle, 0, ref sampleCount, 1, Imports.PS6000DownSampleRatioMode.PS6000_RATIO_MODE_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++)
            {
            if (_channelSettings[ch].enabled)
                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 enabled Channels, results shown are....");
            writer.WriteLine();
            writer.WriteLine("Time interval Maximum Aggregated value ADC Count & mV, Minimum Aggregated value ADC Count & mV");
            writer.WriteLine();

            writer.Write("Time  ");
            for (int ch = 0; ch < _channelCount; ch++)
            if (_channelSettings[ch].enabled)
                writer.Write("Ch  Max ADC    Max mV   Min ADC    Min mV   ");
            writer.WriteLine();

            for (int i = 0; i < sampleCount; i++)
            {
              writer.Write("{0,4}  ", (i * timeInterval));
              for (int ch = 0; ch < _channelCount; ch++)
              {
              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();
              }
        }
Ejemplo n.º 3
0
        /****************************************************************************
         * RapidBlockDataHandler
         * - Used by all the CollectBlockRapid routine
         * - acquires data (user sets trigger mode before calling), displays 10 items
         * Input :
         * - nRapidCaptures : the user specified number of blocks to capture
         ****************************************************************************/
        private void RapidBlockDataHandler(uint nRapidCaptures)
        {
            short status;
            int numChannels = _channelCount;
            uint numSamples = BUFFER_SIZE;

            // Run the rapid block capture
            int timeIndisposed;
            _ready = false;

            //  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)numSamples, out timeInterval, _oversample, out maxSamples, 0) != 0)
            {
            _timebase++;
            }
            Console.WriteLine("Timebase: {0}\toversample:{1}", _timebase, _oversample);

            _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,
                                           Imports.PS6000DownSampleRatioMode.PS6000_RATIO_MODE_NONE);
                }
                else
                {
                    status = Imports.SetDataBuffersRapid(_handle,
                               (Imports.Channel)channel,
                                null,
                                0,
                                segment,
                                Imports.PS6000DownSampleRatioMode.PS6000_RATIO_MODE_NONE);

                }
            }
            }

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

            status = Imports.GetValuesRapid(_handle, ref numSamples, 0, nRapidCaptures - 1, 1, Imports.PS6000DownSampleRatioMode.PS6000_RATIO_MODE_NONE, 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 ch = 0; ch < _channelCount; ch++)
            {
                if (_channelSettings[ch].enabled)
                    Console.Write("  Ch{0}   ", (char)('A' + ch));
            }
            Console.WriteLine();

            for (int i = 0; i < 10; i++)
            {
                for (int ch = 0; ch < _channelCount; ch++)
                {
                    if (_channelSettings[ch].enabled)
                    {
                        Console.Write("{0,6}\t", _scaleVoltages ?
                                            adc_to_mv(pinned[seg, ch].Target[i], (int)_channelSettings[(int)(Imports.Channel.ChannelA + ch)].range) // If _scaleVoltages, show mV values
                                            : pinned[seg, ch].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();
            }
        }
Ejemplo n.º 4
0
        /****************************************************************************
        * BlockDataHandler
        * - Used by all block data routines
        ****************************************************************************/
        void BlockDataHandler()
        {
            short status;
            uint  sampleCount = BUFFER_SIZE;
            int   timeIndisposed;
            int   timeInterval;
            int   maxSamples;

            // Clear data buffers
            for (int i = 0; i < ENABLED_CHANNELS; i++)
            {
                Array.Clear(minBuffers, 0, minBuffers.Length);
                Array.Clear(maxBuffers, 0, maxBuffers.Length);
            }

            while (Imports.GetTimebase(_handle, _timebase, (int)sampleCount, out timeInterval, _oversample, out maxSamples, 0) != 0)
            {
                _timebase++;
            }

            _ready            = false;
            _callbackDelegate = BlockCallback;
            status            = Imports.RunBlock(
                _handle,
                0,
                (int)sampleCount,
                _timebase,
                _oversample,
                out timeIndisposed,
                0,
                _callbackDelegate,
                IntPtr.Zero
                );

            while (!_ready)
            {
                Thread.Sleep(1);
            }

            Imports.Stop(_handle);
            if (_ready)
            {
                short overflow;
                status = Imports.GetValues(
                    _handle,
                    0,
                    ref sampleCount,
                    NSAMPLES,
                    Imports.PS6000DownSampleRatioMode.PS6000_RATIO_MODE_AGGREGATE,
                    0,
                    out overflow
                    );

                for (int i = 0; i < sampleCount; i++)
                {
                    for (int ch = 0; ch < ENABLED_CHANNELS; ch++)
                    {
                        float max = minPinned[ch].Target[i];
                        float min = maxPinned[ch].Target[i];
                        processPeakToPeak(ch, max - min);
                    }
                }
            }
        }