private void buttonStart_Click(object sender, EventArgs e)
        {
            uint status;

            status = Imports.SetChannel(_handle, Imports.Channel.ChannelA, 1, Imports.Coupling.PS5000A_DC, Imports.Range.Range_2V, 0);
            status = Imports.SetChannel(_handle, Imports.Channel.ChannelB, 0, Imports.Coupling.PS5000A_DC, Imports.Range.Range_2V, 0);
            status = Imports.SetChannel(_handle, Imports.Channel.ChannelC, 0, Imports.Coupling.PS5000A_DC, Imports.Range.Range_2V, 0);
            status = Imports.SetChannel(_handle, Imports.Channel.ChannelD, 0, Imports.Coupling.PS5000A_DC, Imports.Range.Range_2V, 0);

            short enable    = 0;
            uint  delay     = 0;
            short threshold = 25000;
            short auto      = 0;

            Imports.tPS5000ATriggerChannelPropertiesV2[] properties = new Imports.tPS5000ATriggerChannelPropertiesV2[1];

//            status = Imports.SetSimpleTrigger(_handle, enable, Imports.Channel.ChannelA, threshold, Imports.ThresholdDirection.Rising, delay, auto);

            properties[0].thresholdLower  = 25000;
            properties[0].thresholdUpper  = 25000;
            properties[0].hysteresisLower = 100;
            properties[0].hysteresisUpper = 100;
            properties[0].Channel         = Imports.Channel.ChannelA;

            Imports.tPS5000ACondition[] conditions = new Imports.tPS5000ACondition[1];
            conditions[0].source    = Imports.Channel.ChannelA;
            conditions[0].condition = Imports.TriggerState.True;

            Imports.tPS5000ADirection[] directions = new Imports.tPS5000ADirection[1];
            directions[0].channel   = Imports.Channel.ChannelA;
            directions[0].direction = Imports.ThresholdDirection.Above;
            directions[0].mode      = Imports.ThresholdMode.Level;

            status = Imports.SetTriggerChannelConditionsV2(_handle, conditions, 1, Imports.PS5000A_CONDITIONS_INFO.PS5000A_CLEAR);

            status = Imports.SetTriggerChannelPropertiesV2(_handle, properties, 1, 1);

            status = Imports.SetTriggerChannelConditionsV2(_handle, conditions, 1, Imports.PS5000A_CONDITIONS_INFO.PS5000A_ADD);

            status = Imports.SetTriggerChannelDirectionsV2(_handle, directions, 1);

            status = Imports.SetAutoTriggerMicroSeconds(_handle, 0);

            _ready            = false;
            _callbackDelegate = BlockCallback;
            _channelCount     = 4;
            string data;
            int    x;

            textMessage.Clear();
            textData.Clear();

            bool retry;
            uint sampleCount = 1000;

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

            int timeIndisposed;

            short[] databuffer = new short[sampleCount];
            //short[] minBuffers = new short[sampleCount];
            //short[] maxBuffers = new short[sampleCount];
            //minPinned[0] = new PinnedArray<short>(minBuffers);
            //maxPinned[0] = new PinnedArray<short>(maxBuffers);
            //status = Imports.SetDataBuffers(_handle, Imports.Channel.ChannelA, maxBuffers, minBuffers, (int)sampleCount, 0, Imports.RatioMode.None);
            status = Imports.SetDataBuffer(_handle, Imports.Channel.ChannelA, databuffer, (int)sampleCount, 0, Imports.RatioMode.None);
            textMessage.AppendText("BlockData\n");

            /*Find the maximum number of samples and the time interval(in nanoseconds).
             * If the function returns PICO_OK, the timebase will be used.
             */
            int timeInterval;
            int maxSamples;

            while (Imports.GetTimebase(_handle, _timebase, (int)sampleCount, out timeInterval, out maxSamples, 0) != 0)
            {
                textMessage.AppendText("Timebase selection\n");
                _timebase++;
            }
            textMessage.AppendText("Timebase Set\n");

            /* Start it collecting, then wait for completion*/
            _ready            = false;
            _callbackDelegate = BlockCallback;

            do
            {
                retry  = false;
                status = Imports.RunBlock(_handle, 0, (int)sampleCount, _timebase, out timeIndisposed, 0, _callbackDelegate, IntPtr.Zero);
                if (status == (short)StatusCodes.PICO_POWER_SUPPLY_CONNECTED || status == (short)StatusCodes.PICO_POWER_SUPPLY_NOT_CONNECTED || status == (short)StatusCodes.PICO_POWER_SUPPLY_UNDERVOLTAGE)
                {
                    status = Imports.ChangePowerSource(_handle, status);
                    retry  = true;
                }
                else
                {
                    textMessage.AppendText("Run Block Called\n");
                }
            }while (retry);

            textMessage.AppendText("Waiting for Data\n");

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

            Imports.Stop(_handle);

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

                if (status == (short)StatusCodes.PICO_OK)
                {
                    textMessage.AppendText("Have Data\n");
                    chartData.Series[0].Points.Clear();

                    for (int I = 0; I < 1000; I++)
                    {
                        chartData.Series[0].Points.AddXY(I, databuffer[I]);
                    }
//                    for (x = 0; x < sampleCount; x++)

//                    {
//                       data = maxBuffers[x].ToString();
//                       textData.AppendText(data);
//                       textData.AppendText("\n");
//                    }
                }
                else
                {
                    textMessage.AppendText("No Data\n");
                }
            }
            else
            {
                textMessage.AppendText("data collection aborted\n");
            }

            Imports.Stop(_handle);

            foreach (PinnedArray <short> p in minPinned)
            {
                if (p != null)
                {
                    p.Dispose();
                }
            }
            foreach (PinnedArray <short> p in maxPinned)
            {
                if (p != null)
                {
                    p.Dispose();
                }
            }
        }
        void start(uint sampleCountAfter = 50000, uint sampleCountBefore = 50000, int write_every = 100)
        {
            uint all_ = sampleCountAfter + sampleCountBefore;
            uint status;
            int  ms;

            status = Imports.MemorySegments(_handle, 1, out ms);

            Voltage_Range = 200;
            status        = Imports.SetChannel(_handle, Imports.Channel.ChannelA, 1, Imports.Coupling.PS5000A_AC, Imports.Range.Range_200mV, 0);
            //status = Imports.SetChannel(_handle, Imports.Channel.ChannelA, 1, Imports.Coupling.PS5000A_DC, Imports.Range.Range_200mV, 0);

            const short enable    = 1;
            const uint  delay     = 0;
            const short threshold = 25000;
            const short auto      = 22222;

            status            = Imports.SetBandwidthFilter(_handle, Imports.Channel.ChannelA, Imports.BandwidthLimiter.PS5000A_BW_20MHZ);
            status            = Imports.SetSimpleTrigger(_handle, enable, Imports.Channel.External, threshold, Imports.ThresholdDirection.Rising, delay, auto);
            _ready            = false;
            _callbackDelegate = BlockCallback;
            _channelCount     = 1;
            //string data;
            int x;


            bool retry;

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

            int timeIndisposed;

            short[] minBuffersA = new short[all_];
            short[] maxBuffersA = new short[all_];
            minPinned[0] = new PinnedArray <short>(minBuffersA);
            maxPinned[0] = new PinnedArray <short>(maxBuffersA);
            status       = Imports.SetDataBuffers(_handle, Imports.Channel.ChannelA, maxBuffersA, minBuffersA, (int)sampleCountAfter + (int)sampleCountBefore, 0, Imports.RatioMode.None);

            //int timeInterval;
            //int maxSamples;
            //while (Imports.GetTimebase(_handle, _timebase, (int)sampleCount, out timeInterval, out maxSamples, 0) != 0)
            //{
            //    _timebase++;
            //}
            _ready            = false;
            _callbackDelegate = BlockCallback;
            do
            {
                retry  = false;
                status = Imports.RunBlock(_handle, (int)sampleCountBefore, (int)sampleCountAfter, _timebase, out timeIndisposed, 0, _callbackDelegate, IntPtr.Zero);
                if (status == (short)StatusCodes.PICO_POWER_SUPPLY_CONNECTED || status == (short)StatusCodes.PICO_POWER_SUPPLY_NOT_CONNECTED || status == (short)StatusCodes.PICO_POWER_SUPPLY_UNDERVOLTAGE)
                {
                    status = Imports.ChangePowerSource(_handle, status);
                    retry  = true;
                }
                else
                {
                    //  textMessage.AppendText("Run Block Called\n");
                }
            }while (retry);
            while (!_ready)
            {
                Thread.Sleep(30);
            }
            Imports.Stop(_handle);
            if (_ready)
            {
                short overflow;
                status = Imports.GetValues(_handle, 0, ref all_, 1, Imports.RatioMode.None, 0, out overflow);

                if (status == (short)StatusCodes.PICO_OK)
                {
                    for (x = 0; x < all_; x++)
                    {
                        masA[x] += maxBuffersA[x] + minBuffersA[x];//=========================================================!
                    }
                }
            }

            Imports.Stop(_handle);
            foreach (PinnedArray <short> p in minPinned)
            {
                if (p != null)
                {
                    p.Dispose();
                }
            }
            foreach (PinnedArray <short> p in maxPinned)
            {
                if (p != null)
                {
                    p.Dispose();
                }
            }
        }
Beispiel #3
0
        private void buttonStart_Click(object sender, EventArgs e)
        {
            uint status;

            status = Imports.SetChannel(_handle, Imports.Channel.ChannelA, 1, Imports.Coupling.PS5000A_DC, Imports.Range.Range_2V, 0);
            status = Imports.SetChannel(_handle, Imports.Channel.ChannelB, 0, Imports.Coupling.PS5000A_DC, Imports.Range.Range_2V, 0);
            status = Imports.SetChannel(_handle, Imports.Channel.ChannelC, 0, Imports.Coupling.PS5000A_DC, Imports.Range.Range_2V, 0);
            status = Imports.SetChannel(_handle, Imports.Channel.ChannelD, 0, Imports.Coupling.PS5000A_DC, Imports.Range.Range_2V, 0);

            short enable    = 0;
            uint  delay     = 0;
            short threshold = 25000;
            short auto      = 0;

            status = Imports.SetSimpleTrigger(_handle, enable, Imports.Channel.ChannelA, threshold, Imports.ThresholdDirection.Rising, delay, auto);

            _ready            = false;
            _callbackDelegate = BlockCallback;
            _channelCount     = 4;
            string data;
            int    x;

            textMessage.Clear();
            textData.Clear();

            bool retry;
            uint sampleCount = 1000;

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

            int timeIndisposed;

            short[] minBuffers = new short[sampleCount];
            short[] maxBuffers = new short[sampleCount];
            minPinned[0] = new PinnedArray <short>(minBuffers);
            maxPinned[0] = new PinnedArray <short>(maxBuffers);
            status       = Imports.SetDataBuffers(_handle, Imports.Channel.ChannelA, maxBuffers, minBuffers, (int)sampleCount, 0, Imports.RatioMode.None);
            textMessage.AppendText("BlockData\n");

            /*  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, out maxSamples, 0) != 0)
            {
                textMessage.AppendText("Timebase selection\n");
                _timebase++;
            }
            textMessage.AppendText("Timebase Set\n");

            /* Start it collecting, then wait for completion*/
            _ready            = false;
            _callbackDelegate = BlockCallback;

            do
            {
                retry  = false;
                status = Imports.RunBlock(_handle, 0, (int)sampleCount, _timebase, out timeIndisposed, 0, _callbackDelegate, IntPtr.Zero);
                if (status == (short)StatusCodes.PICO_POWER_SUPPLY_CONNECTED || status == (short)StatusCodes.PICO_POWER_SUPPLY_NOT_CONNECTED || status == (short)StatusCodes.PICO_POWER_SUPPLY_UNDERVOLTAGE)
                {
                    status = Imports.ChangePowerSource(_handle, status);
                    retry  = true;
                }
                else
                {
                    textMessage.AppendText("Run Block Called\n");
                }
            }while (retry);

            textMessage.AppendText("Waiting for Data\n");

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

            Imports.Stop(_handle);

            if (_ready)
            {
                short overflow;
                status = Imports.GetValues(_handle, 0, ref sampleCount, 1, Imports.DownSamplingMode.None, 0, out overflow);
                if (status == (short)StatusCodes.PICO_OK)
                {
                    textMessage.AppendText("Have Data\n");
                    for (x = 0; x < sampleCount; x++)
                    {
                        data = maxBuffers[x].ToString();
                        textData.AppendText(data);
                        textData.AppendText("\n");
                    }
                }
                else
                {
                    textMessage.AppendText("No Data\n");
                }
            }
            else
            {
                textMessage.AppendText("data collection aborted\n");
            }

            Imports.Stop(_handle);

            foreach (PinnedArray <short> p in minPinned)
            {
                if (p != null)
                {
                    p.Dispose();
                }
            }
            foreach (PinnedArray <short> p in maxPinned)
            {
                if (p != null)
                {
                    p.Dispose();
                }
            }
        }
Beispiel #4
0
        static public void startacquisition()
        {
            short status;
            uint  i, j;

            if (channelson[4])
            {
                startgenerator();
            }

            status = Imports.SetChannel(_handle, Imports.Channel.ChannelA, channelson[0] ? (short)1 : (short)0, 1, (Imports.Range)ranges.GetValue(rangeinds[0]), 0);
            status = Imports.SetChannel(_handle, Imports.Channel.ChannelB, channelson[1] ? (short)1 : (short)0, 1, (Imports.Range)ranges.GetValue(rangeinds[1]), 0);
            status = Imports.SetChannel(_handle, Imports.Channel.ChannelC, channelson[2] ? (short)1 : (short)0, 1, (Imports.Range)ranges.GetValue(rangeinds[2]), 0);
            status = Imports.SetChannel(_handle, Imports.Channel.ChannelD, channelson[3] ? (short)1 : (short)0, 1, (Imports.Range)ranges.GetValue(rangeinds[3]), 0);

            short enable = 1;//0;
            uint  delay  = 0;
            //triggerthreshold = 0;//25000;
            short auto = 0;

            Imports.ThresholdDirection direction;
            switch (rangeinds[4])
            {
            case 3:     //ramp up
                direction = Imports.ThresholdDirection.Falling;
                break;

            case 4:     // ramp down
                direction = Imports.ThresholdDirection.Rising;
                break;

            default:
                direction = Imports.ThresholdDirection.Rising;
                break;
            }
            status = Imports.SetSimpleTrigger(_handle, enable, Imports.Channel.ChannelA, triggerthreshold, direction, delay, auto);

            _ready            = false;
            _callbackDelegate = BlockCallback;
            _channelCount     = 4;

            devicelogs = "";

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

            int timeIndisposed;

            ////short[] minBuffers = new short[sampleCount];
            BufferA = new short[bufferlength];
            BufferB = new short[bufferlength];
            BufferC = new short[bufferlength];
            BufferD = new short[bufferlength];
            ////minPinned[0] = new PinnedArray<short>(minBuffers);
            ////maxPinned[0] = new PinnedArray<short>(BufferA);
            //status = Imports.SetDataBuffers(_handle, Imports.Channel.ChannelA, BufferA, minBuffers, (int)sampleCount, 0, Imports.RatioMode.None);

            status      = Imports.SetDataBuffer(_handle, Imports.Channel.ChannelA, BufferA, (int)bufferlength, 0, Imports.RatioMode.None);
            devicelogs += status == (short)Imports.PICO_OK ? "Ch A OK\n" : "Ch A Error\n";
            status      = Imports.SetDataBuffer(_handle, Imports.Channel.ChannelB, BufferB, (int)bufferlength, 0, Imports.RatioMode.None);
            devicelogs += status == (short)Imports.PICO_OK ? "Ch B OK\n" : "Ch B Error\n";
            status      = Imports.SetDataBuffer(_handle, Imports.Channel.ChannelC, BufferC, (int)bufferlength, 0, Imports.RatioMode.None);
            devicelogs += status == (short)Imports.PICO_OK ? "Ch C OK\n" : "Ch C Error\n";
            status      = Imports.SetDataBuffer(_handle, Imports.Channel.ChannelD, BufferD, (int)bufferlength, 0, Imports.RatioMode.None);
            devicelogs += status == (short)Imports.PICO_OK ? "Ch D OK\n" : "Ch D Error\n";
            devicelogs += "BlockData\n";

            /*  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)bufferlength, out timeInterval, out maxSamples, 0) != 0)
            {
                devicelogs += "Timebase selection\n";
                timebase++;
            }
            devicelogs += "Timebase Set " + timebase.ToString() + "\n";
            devicelogs += "Sample Count Set " + bufferlength.ToString() + "\n";
            devicelogs += "Time Interval Set " + timeInterval.ToString() + "\n";
            devicelogs += "Max Samples Set " + maxSamples.ToString() + "\n";

            /* Start it collecting, then wait for completion*/
            _ready            = false;
            _callbackDelegate = BlockCallback;

            do
            {
                retry  = false;
                status = Imports.RunBlock(_handle, 0, (int)bufferlength, timebase, out timeIndisposed, 0, _callbackDelegate, IntPtr.Zero);
                if (status == (short)Imports.PICO_POWER_SUPPLY_CONNECTED || status == (short)Imports.PICO_POWER_SUPPLY_NOT_CONNECTED || status == (short)Imports.PICO_POWER_SUPPLY_UNDERVOLTAGE)
                {
                    retry = true;
                }
                else
                {
                    devicelogs += "Run Block Called\n";
                }
            }while (retry);

            devicelogs += "Waiting for Data\n";

            {
                uint sleepcntr = 0;
                while (sleepcntr < 10 && !_ready)
                {
                    Thread.Sleep(100);
                    sleepcntr++;
                }
                devicelogs += String.Format("{0} ms\n", sleepcntr * 100);
            }

            Imports.Stop(_handle);
            if (channelson[4])
            {
                stopgenerator();
            }

            if (_ready)
            {
                uint[] rangemv = { 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000, 20000, 20000 };
                short  overflow;
                uint   t = bufferlength;
                status = Imports.GetValues(_handle, 0, ref t, 1, Imports.DownSamplingMode.None, 0, out overflow);
                if (status == (short)Imports.PICO_OK && (numberofsamplesinsweep + guardinterval * 2) * numberofsweeps == bufferlength)
                {
                    devicelogs += "Have Data\n";

                    channelAvoltage = new double[numberofsamplesinsweep];
                    channelBvoltage = new double[numberofsamplesinsweep];
                    channelCvoltage = new double[numberofsamplesinsweep];
                    channelDvoltage = new double[numberofsamplesinsweep];
                    vlp             = new double[numberofsamplesinsweep];
                    vrp             = new double[numberofsamplesinsweep];
                    vp       = new double[numberofsamplesinsweep];
                    ilp      = new double[numberofsamplesinsweep];
                    dilp     = new double[numberofsamplesinsweep];
                    d2ilp    = new double[numberofsamplesinsweep];
                    vlpmin   = 1e12;
                    vrpmin   = 1e12;
                    vpmin    = 1e12;
                    ilpmin   = 1e12;
                    dilpmin  = 1e12;
                    d2ilpmin = 1e12;
                    vlpmax   = -1e12;
                    vrpmax   = -1e12;
                    vpmax    = -1e12;
                    ilpmax   = -1e12;
                    dilpmax  = -1e12;
                    d2ilpmax = -1e12;

                    devicelogs += "Reallocated " + channelAvoltage.Length.ToString() + " doubles\n";


                    //median filtering starting.
                    if (medianwindow > 0)
                    {
                        short[] tempArr;
                        uint    medianguard = Math.Min(medianwindow / 2, numberofsamplesinsweep / 4);
                        if (channelson[0])
                        {
                            tempArr = BufferA.SubArray(0, bufferlength);
                            for (i = medianguard; i < bufferlength - medianguard; i++)
                            {
                                BufferA[i] = statisticalprocessing.Median(tempArr.SubArray(i - medianguard, 2 * medianguard));
                            }
                            for (i = medianguard; i > 0; i--)
                            {
                                BufferA[i - 1] = (short)(2 * (long)BufferA[i] - (long)BufferA[i + 1]);
                                j          = bufferlength - i;
                                BufferA[j] = (short)(2 * (long)BufferA[j - 1] - (long)BufferA[j - 2]);
                            }
                        }

                        if (channelson[1])
                        {
                            tempArr = BufferB.SubArray(0, bufferlength);
                            for (i = medianguard; i < bufferlength - medianguard; i++)
                            {
                                BufferB[i] = statisticalprocessing.Median(tempArr.SubArray(i - medianguard, 2 * medianguard));
                            }
                            for (i = medianguard; i > 0; i--)
                            {
                                BufferB[i - 1] = (short)(2 * (long)BufferB[i] - (long)BufferB[i + 1]);
                                j          = bufferlength - i;
                                BufferB[j] = (short)(2 * (long)BufferB[j - 1] - (long)BufferB[j - 2]);
                            }
                        }

                        if (channelson[2])
                        {
                            tempArr = BufferC.SubArray(0, bufferlength);
                            for (i = medianguard; i < bufferlength - medianguard; i++)
                            {
                                BufferC[i] = statisticalprocessing.Median(tempArr.SubArray(i - medianguard, 2 * medianguard));
                            }
                            for (i = medianguard; i > 0; i--)
                            {
                                BufferC[i - 1] = (short)(2 * (long)BufferC[i] - (long)BufferC[i + 1]);
                                j          = bufferlength - i;
                                BufferC[j] = (short)(2 * (long)BufferC[j - 1] - (long)BufferC[j - 2]);
                            }
                        }

                        if (channelson[3])
                        {
                            tempArr = BufferD.SubArray(0, bufferlength);
                            for (i = medianguard; i < bufferlength - medianguard; i++)
                            {
                                BufferD[i] = statisticalprocessing.Median(tempArr.SubArray(i - medianguard, 2 * medianguard));
                            }
                            for (i = medianguard; i > 0; i--)
                            {
                                BufferD[i - 1] = (short)(2 * (long)BufferD[i] - (long)BufferD[i + 1]);
                                j          = bufferlength - i - 1;
                                BufferD[j] = (short)(2 * (long)BufferD[j - 1] - (long)BufferD[j - 2]);
                            }
                        }
                    }
                    //median filtering done.

                    uint x;
                    for (x = 0; x < numberofsamplesinsweep; x++)
                    {
                        uint x1;
                        if (channelson[0])
                        {
                            channelAvoltage[x] = (double)BufferA[x + guardinterval];
                            for (x1 = numberofsamplesinsweep + 3 * guardinterval + x; x1 < bufferlength; x1 += (numberofsamplesinsweep + 2 * guardinterval))
                            {
                                channelAvoltage[x] += (double)BufferA[x1];
                            }
                            channelAvoltage[x] *= (double)rangemv[rangeinds[0]] / ((double)numberofsweeps * (double)Imports.MaxLogicLevel);
                            vlp[x]              = channelAvoltage[x] * LPVoltmeterAttenuation / 1000;
                            vlpmax              = vlp[x] > vlpmax ? vlp[x] : vlpmax;
                            vlpmin              = vlp[x] < vlpmin ? vlp[x] : vlpmin;
                        }
                        else
                        {
                            vlp[x] = vlpmin = vlpmax = channelAvoltage[x] = 0.0;
                        }

                        if (channelson[1])
                        {
                            channelBvoltage[x] = (double)BufferB[x];
                            for (x1 = numberofsamplesinsweep + 3 * guardinterval + x; x1 < bufferlength; x1 += (numberofsamplesinsweep + 2 * guardinterval))
                            {
                                channelBvoltage[x] += (double)BufferB[x1];
                            }
                            channelBvoltage[x] *= (double)rangemv[rangeinds[1]] / ((double)numberofsweeps * (double)Imports.MaxLogicLevel);
                            ilp[x]              = channelBvoltage[x] / CurrentMeterShuntResistance / 1000;
                            ilpmax              = ilp[x] > ilpmax ? ilp[x] : ilpmax;
                            ilpmin              = ilp[x] < ilpmin ? ilp[x] : ilpmin;
                        }
                        else
                        {
                            ilp[x] = ilpmin = ilpmax = channelBvoltage[x] = 0.0;
                        }

                        if (channelson[2])
                        {
                            channelCvoltage[x] = (double)BufferC[x];
                            for (x1 = numberofsamplesinsweep + 3 * guardinterval + x; x1 < bufferlength; x1 += (numberofsamplesinsweep + 2 * guardinterval))
                            {
                                channelCvoltage[x] += (double)BufferC[x1];
                            }
                            channelCvoltage[x] *= (double)rangemv[rangeinds[2]] / ((double)numberofsweeps * (double)Imports.MaxLogicLevel);
                            vrp[x]              = channelCvoltage[x] * RPVoltmeterAttenuation / 1000;
                            vrpmax              = vrp[x] > vrpmax ? vrp[x] : vrpmax;
                            vrpmin              = vrp[x] < vrpmin ? vrp[x] : vrpmin;
                        }
                        else
                        {
                            vrp[x] = vrpmin = vrpmax = channelCvoltage[x] = 0.0;
                        }


                        if (channelson[3])
                        {
                            channelDvoltage[x] = (double)BufferD[x];
                            for (x1 = numberofsamplesinsweep + 3 * guardinterval + x; x1 < bufferlength; x1 += (numberofsamplesinsweep + 2 * guardinterval))
                            {
                                channelDvoltage[x] += (double)BufferD[x1];
                            }
                            channelDvoltage[x] *= (double)rangemv[rangeinds[3]] / ((double)numberofsweeps * (double)Imports.MaxLogicLevel);
                        }
                        else
                        {
                            channelDvoltage[x] = 0.0;
                        }


                        vp[x] = vlp[x] - vrp[x];
                        vpmax = vp[x] > vpmax ? vp[x] : vpmax;
                        vpmin = vp[x] < vpmin ? vp[x] : vpmin;
                    }



                    for (x = diffinterval; x < numberofsamplesinsweep - diffinterval; x++)
                    {
                        dilp[x] = (ilp[x + diffinterval] - ilp[x - diffinterval]) / (vp[x + diffinterval] - vp[x - diffinterval]);
                        dilpmax = dilp[x] > dilpmax ? dilp[x] : dilpmax;
                        dilpmin = dilp[x] < dilpmin ? dilp[x] : dilpmin;
                    }
                    for (x = 0; x < diffinterval; x++)
                    {
                        dilp[x] = dilp[diffinterval];
                        dilp[numberofsamplesinsweep - x - 1] = dilp[numberofsamplesinsweep - diffinterval - 1];
                    }

                    for (x = diffinterval; x < numberofsamplesinsweep - diffinterval; x++)
                    {
                        d2ilp[x] = (dilp[x + diffinterval] - dilp[x - diffinterval]) / (vp[x + diffinterval] - vp[x - diffinterval]);
                        d2ilpmax = d2ilp[x] > d2ilpmax ? d2ilp[x] : d2ilpmax;
                        d2ilpmin = d2ilp[x] < d2ilpmin ? d2ilp[x] : d2ilpmin;
                    }
                    for (x = 0; x < diffinterval; x++)
                    {
                        d2ilp[x] = d2ilp[diffinterval];
                        d2ilp[numberofsamplesinsweep - x - 1] = d2ilp[numberofsamplesinsweep - diffinterval - 1];
                    }
                }
                else
                {
                    devicelogs += "No Data\n";
                }
            }
            else
            {
                devicelogs += "data collection aborted\n";
            }

            Imports.Stop(_handle);

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