Пример #1
0
 public PingLivingReader(ADataReaderParams readerParams, ACounterReader reader)
 {
     _params    = readerParams != null ? readerParams as PingDataReaderParams : PingReaderHelper.GetDefault;
     _reader    = reader as CounterReader;
     _startTime = TimeSpan.Parse(_params?.StartTime ?? PingReaderHelper.StartTime);
     _interval  = TimeSpan.Parse(_params?.Interval ?? PingReaderHelper.Interval);
 }
Пример #2
0
        /// <summary>
        /// Stops the read.
        /// </summary>
        public void Stop()
        {
            if (IsReading && CurReadWaitResult != null && !CurReadWaitResult.IsCompleted &&
                (CounterReader != null || AnalogReader != null))
            {
                try
                {
                    if (IsCounter)
                    {
                        CounterReader.EndReadMultiSampleUInt32(CurReadWaitResult);
                    }
                    else
                    {
                        AnalogReader.EndReadMultiSample(CurReadWaitResult);
                    }
                }
                catch (Exception ex)
                {
                    /// attempt to end he read failed.
                }

                // clear the async result.
                CurReadWaitResult = null;
            }
            IsReading = false;

            DestroyReaderTask();
            DestroyTimebaseTask();
        }
Пример #3
0
 public ExitReader(ADataReaderParams readerParams, ACounterReader reader)
 {
     _params = readerParams?.LogicalStorage != null ?
               readerParams as ExitDataReaderParams : new ExitDataReaderParams {
         LogicalStorage = "UNDEFINED-EXIT-READER"
     };
     _reader = reader as CounterReader;
 }
Пример #4
0
 public DatabaseDataReader(string connStrName, ADataReaderParams readerParams, ACounterReader counterReader)
 {
     _params        = readerParams as DatabaseDataReaderParams;
     _counterReader = counterReader as CounterReader;
     CheckParams(_params);
     _container = new FieldsContainer();
     _db        = Database.OpenConnection(connStrName);
 }
Пример #5
0
        public INotificationDataReader Prepare(ConfigManager.Models.Reader reader, ConfigManager.ConfigManager configManager)
        {
            var exitReaderParams = new ExitDataReaderParams {
                LogicalStorage = reader.LogicalName
            };
            var setCounterReader = new CounterReader(configManager, reader.ReaderId);

            return(new ExitReader.ExitReader(exitReaderParams, setCounterReader));
        }
Пример #6
0
        public double ReadDigitalPulseWidth(string counter, CIPulseWidthStartingEdge StartingEdge, double minPW_InSeconds, double maxPW_InSeconds)
        {
            // This example uses the default source (or gate) terminal for
            // the counter of your device.  To determine what the default
            // counter pins for your device are or to set a different source
            // (or gate) pin, refer to the Connecting Counter Signals topic
            // in the NI-DAQmx Help (search for "Connecting Counter Signals").
            // Uses default PFI 9/P2.1 as the pulse input.
            // Returns PW in seconds.

            double pulseWidth = 0;
            Task   myTask     = null;

            NationalInstruments.DAQmx.CounterReader myCounterReader;

            try
            {
                myTask = new Task();
                myTask.CIChannels.CreatePulseWidthChannel(counter,
                                                          "Meas Pulse Width", minPW_InSeconds,
                                                          maxPW_InSeconds, StartingEdge,
                                                          CIPulseWidthUnits.Seconds);
                //RLC Wait up to 5 sec default was 10 sec
                myTask.Stream.Timeout = 5000;
                myCounterReader       = new CounterReader(myTask.Stream);

                // For .NET Framework 2.0 or later, use SynchronizeCallbacks to specify that the object
                // marshals callbacks across threads appropriately.
                myCounterReader.SynchronizeCallbacks = true;
                // For .NET Framework 1.1, set SynchronizingObject to the Windows Form to specify
                // that the object marshals callbacks across threads appropriately.
                //myCounterReader.SynchronizingObject = this;


                //rlc AsyncCallback myCallback = new AsyncCallback(MeasurementCallback);
                //myCounterReader.BeginReadSingleSampleDouble(myCallback, null);
                IAsyncResult ar = null;
                ar = myCounterReader.BeginReadSingleSampleDouble(null, null);

                pulseWidth = myCounterReader.EndReadSingleSampleDouble(ar);
            }
            catch (Exception exception)
            {
                mstr_Error = exception.Message;
                pulseWidth = -1;
            }
            finally
            {
                if (myTask != null)
                {
                    myTask.Dispose();
                }
            }

            return(pulseWidth);
        }
Пример #7
0
 /// <summary>
 /// Async call to read the data.
 /// </summary>
 protected void ReadData()
 {
     if (IsCounter)
     {
         CurReadWaitResult = CounterReader.BeginReadMultiSampleUInt32(SamplesPerReadTick, OnDataRead, null);
     }
     else
     {
         CurReadWaitResult = AnalogReader.BeginReadMultiSample(SamplesPerReadTick, OnDataRead, null);
     }
 }
Пример #8
0
        public INotificationDataReader Prepare(ConfigManager.Models.Reader reader, ConfigManager.ConfigManager configManager)
        {
            var pingReaderParams = new PingDataReaderParams
            {
                LogicalStorage = reader.LogicalName,
                StartTime      = reader.ReaderAdditionalParams.StartTime,
                Interval       = reader.ReaderAdditionalParams.Interval,
                Occurs         = reader.ReaderAdditionalParams.Occurs
            };

            var setCounterReader = new CounterReader(configManager, reader.ReaderId);

            return(new PingLivingReader(pingReaderParams, setCounterReader));
        }
Пример #9
0
        /// <summary>
        /// On data was read.
        /// </summary>
        /// <param name="rslt"></param>
        protected void OnDataRead(IAsyncResult rslt)
        {
            if (!rslt.IsCompleted || !IsReading)
            {
                return;
            }

            DataChunk c      = null;
            TimeSpan  offset = TimeSpan.FromSeconds(ReadTicks * 1.0 / SamplingFrequency);

            if (IsCounter)
            {
                // data is counter.
                uint[,] data = CounterReader.EndReadMultiSampleUInt32(rslt);
                ReadTicks   += data.GetLength(1);
                c            = new DataChunk(offset, data);
            }
            else
            {
                // data is analog.
                double[,] data = AnalogReader.EndReadMultiSample(rslt);

                // adding to the read ticks.
                ReadTicks += data.GetLength(1);
                c          = new DataChunk(offset, data);
            }

            // call async again.
            if (IsReading)
            {
                ReadData();
            }

            // No data.
            if (c.DataCount == 0)
            {
                return;
            }

            m_dataQ.Enqueue(c);

            // call to process the queue if needed.
            DoQueueProcessing();
        }
Пример #10
0
        public double Meas2EdgeSeparation(string lines, double min, double max, CITwoEdgeSeparationFirstEdge firstEdge, CITwoEdgeSeparationSecondEdge secondEdge, int Timeout)
        {
            // This example uses the default source (or gate) terminal for
            // the counter of your device.  To determine what the default
            // counter pins for your device are or to set a different source
            // (or gate) pin, refer to the Connecting Counter Signals topic
            // in the NI-DAQmx Help (search for "Connecting Counter Signals").
            // Uses default PFI 9/P2.1 as the pulse input.

            double pulseGap = 0;
            Task   myTask   = null;

            NationalInstruments.DAQmx.CounterReader myCounterReader;

            try
            {
                myTask = new Task();

                myTask.Stream.Timeout = Timeout;

                myTask.CIChannels.CreateTwoEdgeSeparationChannel(
                    lines, "", min, max,
                    firstEdge, secondEdge, CITwoEdgeSeparationUnits.Seconds);

                myCounterReader = new CounterReader(myTask.Stream);
                pulseGap        = myCounterReader.ReadSingleSampleDouble();
            }
            catch (DaqException exception)
            {
                mstr_Error = exception.Message;
                pulseGap   = 0;
            }
            finally
            {
                if (myTask != null)
                {
                    myTask.Dispose();
                }
            }

            return(pulseGap);
        }
Пример #11
0
        public INotificationDataReader Prepare(ConfigManager.Models.Reader reader, ConfigManager.ConfigManager configManager)
        {
            var databaseDataReaderParams = new DatabaseDataReaderParams
            {
                LogicalStorage        = reader.LogicalName,
                Schema                = reader.ReaderAdditionalParams.Schema ?? "dbo",
                TableName             = reader.ReaderAdditionalParams.TableName,
                OrderByColumnName     = reader.ReaderAdditionalParams.OrderByColumnName,
                InitialCounter        = reader.InitialCounter,
                MessageTypeColumnName = reader.ReaderAdditionalParams.MessageTypeColumnName,
                ColumnsNames          = reader.ColumnNames
            };

            var setCounterReader = new CounterReader(configManager, reader.ReaderId);

            var notificationDataReaderDecorator = new NotificationDataReaderDecorator(
                new DatabaseDataReader.DatabaseDataReader(reader.ConnectionString, databaseDataReaderParams, setCounterReader), reader.ReaderId);

            return(notificationDataReaderDecorator);
        }
Пример #12
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 CounterReader(counterTask.Stream);
            counterReader.SynchronizeCallbacks = true;

            if (!Environs.Debug)
            {
                counterReader.BeginReadMultiSampleInt32(
                    SAMPLE_MULTI_READ,
                    new AsyncCallback(CounterCallBack),
                    null
                    );
            }
        }
Пример #13
0
        public bool ReadDigitalLowFrequency(string lines, string name, double min, double max, double time)
        {
            // This example uses the default source (or gate) terminal for
            // the counter of your device.  To determine what the default
            // counter pins for your device are or to set a different source
            // (or gate) pin, refer to the Connecting Counter Signals topic
            // in the NI-DAQmx Help (search for "Connecting Counter Signals").
            // Uses default PFI 9/P2.1 as the pulse input.
            try
            {
                m_d_MeasuredFrequency = 0;

                Task_MeasureLowFreq = new Task();

                Task_MeasureLowFreq.CIChannels.CreateFrequencyChannel(lines, name, min, max, CIFrequencyStartingEdge.Rising,
                                                                      CIFrequencyMeasurementMethod.LowFrequencyOneCounter, time, 4, CIFrequencyUnits.Hertz);

                myCounterReader = new CounterReader(Task_MeasureLowFreq.Stream);

                // For .NET Framework 2.0 or later, use SynchronizeCallbacks to specify that the object
                // marshals callbacks across threads appropriately.
                myCounterReader.SynchronizeCallbacks = true;

                myCallBack = new AsyncCallback(CounterInCallback);
                myCounterReader.BeginReadSingleSampleDouble(myCallBack, null);
            }
            catch (Exception exception)
            {
                mstr_Error = exception.Message;
                Task_MeasureLowFreq.Dispose();

                return(false);
            }

            return(true);
        }
        public override void AcquisitionStarting()
        {
            //set up an edge-counting task
            countingTask = new Task("buffered edge counter gatherer " + (string)settings["channel"]);

            //count upwards on rising edges starting from zero
            countingTask.CIChannels.CreateCountEdgesChannel(
                ((CounterChannel)Environs.Hardware.CounterChannels[(string)settings["channel"]]).PhysicalChannel,
                "edge counter",
                CICountEdgesActiveEdge.Rising,
                0,
                CICountEdgesCountDirection.Up);

            //The counting buffer is triggered by a sample clock, which will be routed to the gate pin of ctr0 (PFI9)
            //The number of samples to collect is determined by the "gateLength" setting. We add 1 to this,
            // since the first count is not synchronized to anything and will be discarded
            countingTask.Timing.ConfigureSampleClock(
                (string)Environs.Hardware.Boards["daq"] + "/PFI9",
                (int)settings["sampleRate"],
                SampleClockActiveEdge.Rising,
                SampleQuantityMode.FiniteSamples,
                (int)settings["gateLength"] + 1);

            countingTask.Control(TaskAction.Verify);

            // set up two taska to generate the sample clock on the second counter
            freqOutTask1 = new Task("buffered event counter clock generation 1");
            freqOutTask2 = new Task("buffered event counter clock generation 2");

            //the frequency of the clock is set by the "sampleRate" setting and the duty cycle is set to 0.5
            //the two output tasks have the same settings
            freqOutTask1.COChannels.CreatePulseChannelFrequency(
                ((CounterChannel)Environs.Hardware.CounterChannels["sample clock"]).PhysicalChannel,
                "photon counter clocking signal",
                COPulseFrequencyUnits.Hertz,
                COPulseIdleState.Low,
                0,
                (int)settings["sampleRate"],
                0.5);
            freqOutTask1.Timing.ConfigureImplicit(SampleQuantityMode.ContinuousSamples, 1000);

            freqOutTask2.COChannels.CreatePulseChannelFrequency(
                ((CounterChannel)Environs.Hardware.CounterChannels["sample clock"]).PhysicalChannel,
                "photon counter clocking signal",
                COPulseFrequencyUnits.Hertz,
                COPulseIdleState.Low,
                0,
                (int)settings["sampleRate"],
                0.5);
            freqOutTask2.Timing.ConfigureImplicit(SampleQuantityMode.ContinuousSamples, 1000);


            // if we're using a hardware trigger to synchronize data acquisition, we need to set up the
            // trigger parameters on the sample clock.
            // The first output task is triggered on PFI0 and the second is triggered on PFI1
            if ((bool)settings["triggerActive"])
            {
                freqOutTask1.Triggers.StartTrigger.Type             = StartTriggerType.DigitalEdge;
                freqOutTask1.Triggers.StartTrigger.DigitalEdge.Edge = DigitalEdgeStartTriggerEdge.Rising;
                freqOutTask2.Triggers.StartTrigger.Type             = StartTriggerType.DigitalEdge;
                freqOutTask2.Triggers.StartTrigger.DigitalEdge.Edge = DigitalEdgeStartTriggerEdge.Rising;
                // the trigger is expected to appear on PFI0
                freqOutTask1.Triggers.StartTrigger.DigitalEdge.Source = (string)Environs.Hardware.Boards["daq"] + "/PFI0";
                // the trigger is expected to appear on PFI1
                freqOutTask2.Triggers.StartTrigger.DigitalEdge.Source = (string)Environs.Hardware.Boards["daq"] + "/PFI1";
            }

            // set up a reader for the edge counter
            countReader = new CounterReader(countingTask.Stream);
        }
Пример #15
0
 //---------------------------------------------------------------------------------------------------------------------------------------------
 internal void triggerInit(double casoKrok)
 {
     //     ttlSignal = new int[NumOfSteps];
     Steptime = casoKrok;
     CICh = UlohaCounter.CIChannels.CreateCountEdgesChannel(
         prevodnikId + "/ctr0",
         prevodnikId + "ctr0",
         CICountEdgesActiveEdge.Falling,
         0,
         CICountEdgesCountDirection.Up
     );
     UlohaCounter.Control(TaskAction.Verify);
     Counter = new CounterReader(UlohaCounter.Stream);
     //    UlohaCounter.Start();
 }
Пример #16
0
        /// <summary>
        /// Prime the APD for counting. Every time it receives a trigger it will now count photons for a set bintime. 
        /// The count will be stored in a buffer and can be read at any time.
        /// </summary>
        public void StartAPDAcquisition()
        {
            // Reset the total amount of counts read.
            this.m_dTotalCountsRead = 0;

            // Create an instance of a reader to get counts from the HW buffer.
            m_rdrCountReader = new CounterReader(this.m_daqtskAPDCount.Stream);

            // Start the task that counts the TTL's coming from the APD first.
            m_daqtskAPDCount.Start();

            // Now start the pulse with duration of bintime. The length of this pulse will be measured in TTL ticks from the actual APD.
            //m_daqtskGatePulse.Start();
        }
        public override void AcquisitionStarting()
        {
            //set up an edge-counting task
            countingTask = new Task("buffered edge counter gatherer " + (string)settings["channel"]);

            //count upwards on rising edges starting from zero
            countingTask.CIChannels.CreateCountEdgesChannel(
                ((CounterChannel)Environs.Hardware.CounterChannels[(string)settings["channel"]]).PhysicalChannel,
                "edge counter",
                CICountEdgesActiveEdge.Rising,
                0,
                CICountEdgesCountDirection.Up);

            //The counting buffer is triggered by a sample clock, which will be routed to the gate pin of ctr0 (PFI9)
            //The number of samples to collect is determined by the "gateLength" setting. We add 1 to this,
            // since the first count is not synchronized to anything and will be discarded
            countingTask.Timing.ConfigureSampleClock(
                (string)Environs.Hardware.Boards["daq"] + "/PFI9",
                (int)settings["sampleRate"],
                SampleClockActiveEdge.Rising,
                SampleQuantityMode.FiniteSamples,
                (int)settings["gateLength"] + 1);

            countingTask.Control(TaskAction.Verify);

            // set up two taska to generate the sample clock on the second counter
            freqOutTask1 = new Task("buffered event counter clock generation 1");
            freqOutTask2 = new Task("buffered event counter clock generation 2");

            //the frequency of the clock is set by the "sampleRate" setting and the duty cycle is set to 0.5
            //the two output tasks have the same settings
            freqOutTask1.COChannels.CreatePulseChannelFrequency(
                ((CounterChannel)Environs.Hardware.CounterChannels["sample clock"]).PhysicalChannel,
                "photon counter clocking signal",
                COPulseFrequencyUnits.Hertz,
                COPulseIdleState.Low,
                0,
                (int)settings["sampleRate"],
                0.5);
            freqOutTask1.Timing.ConfigureImplicit(SampleQuantityMode.ContinuousSamples, 1000);

            freqOutTask2.COChannels.CreatePulseChannelFrequency(
                ((CounterChannel)Environs.Hardware.CounterChannels["sample clock"]).PhysicalChannel,
                "photon counter clocking signal",
                COPulseFrequencyUnits.Hertz,
                COPulseIdleState.Low,
                0,
                (int)settings["sampleRate"],
                0.5);
            freqOutTask2.Timing.ConfigureImplicit(SampleQuantityMode.ContinuousSamples, 1000);

            // if we're using a hardware trigger to synchronize data acquisition, we need to set up the
            // trigger parameters on the sample clock.
            // The first output task is triggered on PFI0 and the second is triggered on PFI1
            if((bool)settings["triggerActive"])
            {
                freqOutTask1.Triggers.StartTrigger.Type = StartTriggerType.DigitalEdge;
                freqOutTask1.Triggers.StartTrigger.DigitalEdge.Edge = DigitalEdgeStartTriggerEdge.Rising;
                freqOutTask2.Triggers.StartTrigger.Type = StartTriggerType.DigitalEdge;
                freqOutTask2.Triggers.StartTrigger.DigitalEdge.Edge = DigitalEdgeStartTriggerEdge.Rising;
                // the trigger is expected to appear on PFI0
                freqOutTask1.Triggers.StartTrigger.DigitalEdge.Source = (string)Environs.Hardware.Boards["daq"] + "/PFI0";
                // the trigger is expected to appear on PFI1
                freqOutTask2.Triggers.StartTrigger.DigitalEdge.Source = (string)Environs.Hardware.Boards["daq"] + "/PFI1";
            }

            // set up a reader for the edge counter
            countReader = new CounterReader(countingTask.Stream);
        }
Пример #18
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 CounterReader(counterTask.Stream);
            counterReader.SynchronizeCallbacks = true;

            if (!Environs.Debug)
                counterReader.BeginReadMultiSampleInt32(
                    SAMPLE_MULTI_READ,
                    new AsyncCallback(CounterCallBack),
                    null
                    );
        }