Exemple #1
0
        // this method configures and starts the counter.
        private void StartCounter()
        {
            // set up the counter - the fast oscillator is fed into a counter's source input
            counterTask = new Task("PhaseLock task");
            CounterChannel oscillatorChannel =
                ((CounterChannel)Environs.Hardware.CounterChannels["phaseLockOscillator"]);

            counterTask.CIChannels.CreateCountEdgesChannel(
                oscillatorChannel.PhysicalChannel,
                oscillatorChannel.Name,
                CICountEdgesActiveEdge.Rising,
                0,
                CICountEdgesCountDirection.Up
                );

            // this counter is sample-clocked by the slow reference that we are locking to.
            // the buffer is set to be "large"
            CounterChannel referenceChannel =
                ((CounterChannel)Environs.Hardware.CounterChannels["phaseLockReference"]);

            counterTask.Timing.ConfigureSampleClock(
                referenceChannel.PhysicalChannel,
                SAMPLE_CLOCK_RATE,
                SampleClockActiveEdge.Rising,
                SampleQuantityMode.ContinuousSamples,
                1000
                );

            counterReader = new CounterSingleChannelReader(counterTask.Stream);
            counterReader.SynchronizeCallbacks = true;

            if (!Environs.Debug)
            {
                counterReader.BeginReadMultiSampleInt32(
                    SAMPLE_MULTI_READ,
                    new AsyncCallback(CounterCallBack),
                    null
                    );
            }
        }
        /// <summary>Read the specified histogram channel range.</summary>
        public ushort[] ReadHistogram(CounterChannel channel, int minValue, int maxValue)
        {
            ClearReadBuffer();
            SendCheckedCommand(string.Format("M1005 {0} {1} {2}", (int)channel, minValue, maxValue));

            var data = ReadResponse();

            var final = ReadResponse();
            if (final != "ok")
                throw new CounterException("Recieved unexpected response: " + final);

            try
            {
                return data.Split(' ')
                    .Where(s => !string.IsNullOrEmpty(s))
                    .Select(s => ushort.Parse(s))
                    .ToArray();
            }
            catch (Exception e)
            {
                throw new CounterException("Recieved unexpected data: " + data + "\n\n" + e.Message);
            }
        }