Beispiel #1
0
        /****************************************************************************
        * StreamDataHandler
        * - Used by all streaming data routines
        *   and saves all to stream.txt
        *   Fast Streaming requires a local buffer to hold the data
        *   while streaming can ouput to file directly
        ****************************************************************************/
        void StreamDataHandler(bool faststreaming)
        {
            //Check if fast streaming has been selected and if device is compatible
            if (_hasFastStreaming && faststreaming)
            {
                // Console.WriteLine("Fast streaming is not support on this device");
                return;
            }

            //TextWriter writer = new StreamWriter(StreamFile, 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();

            //Console.WriteLine("Data is being collect press any key to cancel");

            if (faststreaming)
            {
                uint  noOfSamplesPerAggregate = 1;
                uint  sampleInterval          = 1;
                short autoStop = 1;

                _totalSampleCount = 0;
                _autoStop         = false;
                _trig             = 0;
                _trigAt           = 0;
                _appBufferFull    = false;

                for (int i = 0; i < 2; i++)
                {
                    _appBuffer[i] = new short[_MaxSamples]; //Set local buffer to hold all values
                }

                Imports.ps2000_run_streaming_ns(_handle, sampleInterval, Imports.ReportedTimeUnits.MicroSeconds, _MaxSamples, autoStop,
                                                noOfSamplesPerAggregate, _OverViewBufferSize);


                while (!_autoStop && !Console.KeyAvailable && !_appBufferFull)
                {
                    Imports.ps2000_get_streaming_last_values(_handle, StreamingCallback);

                    Console.WriteLine("Collected {0,4} samples, Total = {2,5}", _nValues, _totalSampleCount);

                    if (_trig > 0)
                    {
                        Console.WriteLine("Scope triggered at {0}  index", _totalSampleCount - _nValues + _trigAt);
                    }
                }

                Imports.Stop(_handle);

                for (int i = 0; i < _totalSampleCount; i++)
                {
                    for (int channel = 0; channel < _channelCount; channel++)
                    {
                        //  writer.Write("{0,5}  ", (i * sampleInterval));

                        if (_channelSettings[channel].enabled == 1)
                        {
                            //writer.Write("Ch{0} {1,7}   {2,7}   ",
                            //               (char)('A' + channel),
                            //               _appBuffer[channel][i],
                            //               adc_to_mv(_appBuffer[channel][i],
                            //                         (int)_channelSettings[channel].range));
                        }
                    }

                    //  writer.WriteLine();
                }
            }

            else
            {
                int   no_of_samples = 0;
                short overflow;
                short sampleInterval_ms = 10;
                short windowed          = 0;

                for (int i = 0; i < _channelCount; i++)
                {
                    short[] buffer = new short[_MaxSamples];
                    Pinned[i] = new PinnedArray <short>(buffer);
                }

                Imports.ps2000_run_streaming(_handle, sampleInterval_ms, (int)_MaxSamples, windowed);

                while (!Console.KeyAvailable)
                {
                    no_of_samples = Imports.GetValues(_handle, Pinned[0], Pinned[1], null, null, out overflow, BUFFER_SIZE);

                    for (int i = 0; i < no_of_samples; i++)
                    {
                        for (int ch = 0; ch < _channelCount; ch++)
                        {
                            //  writer.Write("{0,5}  ", (i * sampleInterval_ms));
                            if (_channelSettings[ch].enabled == 1)
                            {
                                //writer.Write("Ch{0} {1,7}   {2,7}   ",
                                //               (char)('A' + ch),
                                //               Pinned[ch].Target[i],
                                //               adc_to_mv(Pinned[ch].Target[i],
                                //                         (int)_channelSettings[ch].range));
                            }
                        }

                        //  writer.WriteLine();
                    }
                }

                Imports.Stop(_handle);
            }

            if (Console.KeyAvailable)
            {
                Console.ReadKey(true);                       // clear the key
            }
            // writer.Close(); //close writer
        }
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 block.txt
        * Input :
        * - 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)
        {
            int   sampleCount = BUFFER_SIZE;
            short timeunit    = 0;
            int   timeIndisposed;



            for (int i = 0; i < _channelCount; i++)
            {
                short[] buffer = new short[sampleCount];
                Pinned[i] = new PinnedArray <short>(buffer);
            }

            /* 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 = 0;
            int maxSamples;

            while ((Imports.GetTimebase(_handle, _timebase, sampleCount, out timeInterval, out timeunit, _oversample, out maxSamples)) == 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*/

            Imports.RunBlock(_handle, sampleCount, _timebase, _oversample, out timeIndisposed);

            Console.WriteLine("Waiting for data...Press a key to abort");
            short ready = 0;

            while ((ready = Imports.Isready(_handle)) == 0 && !Console.KeyAvailable)
            {
                Thread.Sleep(1);
            }
            if (Console.KeyAvailable)
            {
                Console.ReadKey(true);                       // clear the key
            }
            if (ready > 0)
            {
                short overflow;

                Imports.GetValues(_handle, Pinned[0], Pinned[1], null, null, out overflow, sampleCount);

                /* Print out the first 10 readings, converting the readings to mV if required */
                Console.WriteLine(text);



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



                for (int i = offset; i < offset + 10; i++)
                {
                    for (int ch = 0; ch < _channelCount; ch++)
                    {
                        if (_channelSettings[ch].enabled == 1)
                        {
                            Console.Write("{0,8}                 ", adc_to_mv(Pinned[ch].Target[i], (int)_channelSettings[ch].range));
                        }
                    }
                    Console.WriteLine();
                }


                sampleCount = Math.Min(sampleCount, BUFFER_SIZE);
                //TextWriter writer = new StreamWriter(BlockFile, 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,5}  ", (i * timeInterval));
                        if (_channelSettings[ch].enabled == 1)
                        {
                            //writer.Write("Ch{0} {1,7}   {2,7}   ",
                            //               (char)('A' + ch),
                            //               Pinned[ch].Target[i],
                            //               adc_to_mv(Pinned[ch].Target[i],
                            //                         (int)_channelSettings[ch].range));
                        }
                    }
                    //     writer.WriteLine();
                }
                // writer.Close();
            }
            else
            {
                //      Console.WriteLine("data collection aborted");
            }

            Imports.Stop(_handle);
        }