Exemplo n.º 1
0
        public bool CaptureScopeSignal(int[] channels, Imports.Range range, int sampleTimeMs)
        {
            short overflow;
            int   timeIndisposed;

            //Set timeout values
            int timeoutCount    = 0;
            int maxTimeoutCount = sampleTimeMs + 500;

            //Set number of samples and calculate time base
            int    numReadings = 1000000; //Get 1M readings
            uint   sampleCount = (uint)numReadings;
            double frequency   = 1000 * (numReadings / sampleTimeMs);
            uint   timebase    = (uint)(MaxSampleRate / frequency) - 1; //Sample at 1 MHz

            if (channels.Length < 1 || channels.Length > Imports.OCTO_SCOPE)
            {
                return(false);
            }

            //Disable trigger
            Imports.SetSimpleTrigger(handle, 0, Imports.Channel.CHANNEL_A + channels[0], 0, Imports.ThresholdDirection.Rising, 0, 0);

            foreach (int channel in channels)
            {
                //Enable scope with given range settings
                EnableScopeChannel(channel, range, true);

                InitScopeBuffer(channel, numReadings);
            }

            //Start block read
            Imports.ps4000aBlockReady _callbackDelegate = BlockCallback;
            blockReady = false;
            status     = Imports.RunBlock(handle, 0, numReadings, timebase, out timeIndisposed, 0, _callbackDelegate, IntPtr.Zero);

            //Wait for data to be ready or timeout to occur
            while (!blockReady && (timeoutCount < maxTimeoutCount))
            {
                Thread.Sleep(1);
                timeoutCount++;
            }

            //Ensure we did not timeout
            if (timeoutCount >= maxTimeoutCount)
            {
                return(false);
            }

            //Import values
            status = Imports.GetValues(handle, 0, ref sampleCount, 1, Imports.DownSamplingMode.None, 0, out overflow);

            //Check if reading was successful
            if (sampleCount != numReadings || status != 0)
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 2
0
        public double GetScopeQuickValue(int channel, Imports.Range range)
        {
            double avg             = 0;
            int    numReadings     = 500;
            uint   sampleCount     = (uint)numReadings;
            int    timeoutCount    = 0;
            int    maxTimeoutCount = 100;
            int    timeIndisposed;
            short  overflow;

            if (range > MaxRange)
            {
                range = MaxRange;
            }

            //Enable scope with given range settings
            EnableScopeChannel(channel, range, true);

            //Disable trigger
            Imports.SetSimpleTrigger(handle, 0, Imports.Channel.CHANNEL_A, 0, Imports.ThresholdDirection.Rising, 0, 0);

            //Initialize the scope buffer
            InitScopeBuffer(channel, numReadings);

            //Start block read
            uint timebase = (MaxSampleRate / 1000000) - 1;    //Sample at 1 MHz

            Imports.ps4000aBlockReady _callbackDelegate = BlockCallback;
            blockReady = false;
            status     = Imports.RunBlock(handle, 0, numReadings, timebase, out timeIndisposed, 0, _callbackDelegate, IntPtr.Zero);

            //Wait for read to finish or timeout
            while (!blockReady && (timeoutCount < maxTimeoutCount))
            {
                Thread.Sleep(1);
                timeoutCount++;
            }

            //Ensure we did not timeout
            if (timeoutCount >= maxTimeoutCount)
            {
                return(-1);
            }

            //Try to get readings
            status = Imports.GetValues(handle, 0, ref sampleCount, 1, Imports.DownSamplingMode.None, 0, out overflow);

            //Check if reading was successful
            if (sampleCount != numReadings || status != 0)
            {
                return(-1);
            }

            //Get average value
            for (int i = 0; i < numReadings; i++)
            {
                avg += dataBuffers[channel].Target[i];
            }

            EnableScopeChannel(channel, range, false);
            dataBuffers[channel] = null;

            //Conversion from adc value to volts
            avg = (avg / numReadings);
            double scaling = inputRanges[(int)range] / Imports.MaxValue;

            return((double)avg * scaling);
        }