当前位置: 首页>>代码示例>>C#>>正文


C# Task.Control方法代码示例

本文整理汇总了C#中Task.Control方法的典型用法代码示例。如果您正苦于以下问题:C# Task.Control方法的具体用法?C# Task.Control怎么用?C# Task.Control使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Task的用法示例。


在下文中一共展示了Task.Control方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DoWork

        public override void DoWork(System.ComponentModel.BackgroundWorker worker)
        {
            while (!worker.CancellationPending)
            {
                try
                {
                    this.Connect();

                    using (myTask = new Task())
                    {
                        //Create a virtual channel
                        myTask.AIChannels.CreateVoltageChannel(CHANNEL, Name,
                            AITerminalConfiguration.Rse, Convert.ToDouble(0),
                                Convert.ToDouble(5), AIVoltageUnits.Volts);

                        AnalogMultiChannelReader reader = new AnalogMultiChannelReader(myTask.Stream);

                        //Verify the Task
                        myTask.Control(TaskAction.Verify);
                        double[] data;
                        double angle;
                        while (!worker.CancellationPending)
                        {
                            data = reader.ReadSingleSample();
                            angle = 60.5 * data[0] - 150; //Console.Write(string.Format("{0:0.00}\r", angle));
                            samplebox.Add(angle);
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("{0} Read Failed.\nReason: {1}", Name, e);
                }
            }
        }
开发者ID:dansam100,项目名称:FYDP,代码行数:35,代码来源:ButtonReader.cs

示例2: Lesker903Gauge

 public Lesker903Gauge(string name, string channelName)
 {
     readPressureTask = new Task("Read pressure -" + name);
     ((AnalogInputChannel)Environs.Hardware.AnalogInputChannels[channelName]).AddToTask(readPressureTask, VOLTAGE_LOWER_BOUND, VOLTAGE_UPPER_BOUND);
     pressureReader = new AnalogSingleChannelReader(readPressureTask.Stream);
     readPressureTask.Control(TaskAction.Verify);
 }
开发者ID:ColdMatter,项目名称:EDMSuite,代码行数:7,代码来源:Lesker903Gauge.cs

示例3: AcquisitionStarting

 public override void AcquisitionStarting()
 {
     dot = new Task("ttlSwitchTask");
     raita = new DigitalSingleChannelWriter(dot.Stream);
     ((DigitalOutputChannel)Environs.Hardware.DigitalOutputChannels["digitalSwitchChannel"]).AddToTask(
         dot);
     dot.Control(TaskAction.Verify);
 }
开发者ID:ColdMatter,项目名称:EDMSuite,代码行数:8,代码来源:TTLSwitchPlugin.cs

示例4: Start

        /// <summary>
        /// Start.
        /// </summary>
        public void Start(double period)
        {
            // Create a new task instance that will be passed to the globally available task.
            var _daqtskTask = new Task();

            try
            {
                // Setup Global Sync Clock (GSC).
                // Commit before start to speed things up later on when the task needs to be started.
                _daqtskTask.COChannels.CreatePulseChannelTime(
                    "/" + this.m_device + "/" + this.m_counter,
                    "SampleClock",
                    COPulseTimeUnits.Seconds,
                    COPulseIdleState.Low,
                    0.0,
                    period * 0.01,
                    period);

                _daqtskTask.Timing.ConfigureImplicit(SampleQuantityMode.ContinuousSamples);

                _daqtskTask.Control(TaskAction.Verify);
                _daqtskTask.Control(TaskAction.Commit);

                // Finally pass the task.
                this.m_sampleClock = _daqtskTask;
            }
            catch (DaqException ex)
            {
                _daqtskTask.Dispose();
                this.m_sampleClock = null;

                m_logger.Error("Problem creating SYNC!" + ex.Message);
            }

            try
            {
                this.m_sampleClock.Start();
            }
            catch(DaqException ex)
            {
                m_logger.Error("Error starting SYNC: " + ex.Message);
            }
        }
开发者ID:KrisJanssen,项目名称:SIS,代码行数:46,代码来源:NISampleClock.cs

示例5: AcquisitionStarting

 public override void AcquisitionStarting()
 {
     if (!Environs.Debug)
     {
         digitalTask = new Task(Channel);
         ((DigitalOutputChannel)Environs.Hardware.DigitalOutputChannels[Channel]).AddToTask(digitalTask);
         digitalTask.Control(TaskAction.Verify);
         writer = new DigitalSingleChannelWriter(digitalTask.Stream);
     }
 }
开发者ID:ColdMatter,项目名称:EDMSuite,代码行数:10,代码来源:TTLSwitchedChannel.cs

示例6: AcquisitionStarting

 public override void AcquisitionStarting()
 {
     if (!Environs.Debug)
     {
         analogTask = new Task(Channel);
         ((AnalogOutputChannel)Environs.Hardware.AnalogOutputChannels[Channel]).AddToTask(analogTask, 0, 5);
         analogTask.Control(TaskAction.Verify);
         writer = new AnalogSingleChannelWriter(analogTask.Stream);
     }
 }
开发者ID:ColdMatter,项目名称:EDMSuite,代码行数:10,代码来源:AnalogSwitchedChannel.cs

示例7: DoWork

        public override void DoWork(BackgroundWorker worker)
        {
            timer.Interval = 100;
            timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Tick);
            timer.Start();

            while (!worker.CancellationPending)
            {
                try
                {
                    this.Connect();

                    System.Console.WriteLine("Initializing DAQ stuff");
                    using (Task myTask = new Task())
                    {
                        //Create a virtual channel
                        myTask.AIChannels.CreateVoltageChannel(Channel, Name,
                            AITerminalConfiguration.Rse, Convert.ToDouble(0),
                                Convert.ToDouble(5), AIVoltageUnits.Volts);
                        AnalogMultiChannelReader reader = new AnalogMultiChannelReader(myTask.Stream);
                        //Verify the Task
                        myTask.Control(TaskAction.Verify);

                        //completed initialization.
                        //Now to read some stuff
                        System.Console.WriteLine("Initialized DAQ stuff");

                        double[] data;
                        double angle;
                        while (!worker.CancellationPending)
                        {
                            if (!sendData) continue;

                            //data = reader.ReadSingleSample();
                            data = DoRead(reader);

                            angle = -(data[0]/(4.4/270) - 270/2);
                            angle /= 2;
                            base.TriggerReadEvent(angle);
                            System.Console.Write("Sending {0:0.00}", Math.Round(angle, 2));
                             sendData = false;
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("{0} Read Failed.\nReason: {1}", Name, e);
                }
            }
        }
开发者ID:dansam100,项目名称:FYDP,代码行数:50,代码来源:PotReader.cs

示例8: NiInterface

        public NiInterface(string deviceAddress, int sampleFrequency, int seconds)
        {
            //try
            //{
            Seconds = seconds;
            SampleFrequency = sampleFrequency;

            //NationalInstruments.DAQmx.
            // Create a new task
            _myTask = new Task();

            // Create a virtual channel

            AIChannel chan = _myTask.AIChannels.CreateVoltageChannel(deviceAddress, "",
                AITerminalConfiguration.Differential, Convert.ToDouble(-20),
                Convert.ToDouble(20), AIVoltageUnits.Volts);

            // Configure the timing parameters
            _myTask.Timing.ConfigureSampleClock("", SampleFrequency,
                SampleClockActiveEdge.Rising, SampleQuantityMode.FiniteSamples, SampleFrequency * Seconds);

            // Verify the Task
            _myTask.Control(TaskAction.Verify);

            _analogInReader = new AnalogMultiChannelReader(_myTask.Stream);
            _analogCallback = new AsyncCallback(AnalogInCallback);

            _analogInReader.SynchronizeCallbacks = true;

            _singleValueTask = new Task();

            _singleValueTask.AIChannels.CreateVoltageChannel(deviceAddress, "", AITerminalConfiguration.Differential,
                                                           Convert.ToDouble(-10), Convert.ToDouble(10),
                                                           AIVoltageUnits.Volts);

            _singleValueTask.Control(TaskAction.Verify);

            _singleValueReader = new AnalogMultiChannelReader(_singleValueTask.Stream);
            //}
            //catch (Exception ex)
            //{
            //    //MainWindow.ShowError(ex.Message, true);
            //}
        }
开发者ID:KCFTech,项目名称:GaussMaster3000,代码行数:44,代码来源:NiInterface.cs

示例9: ZeroAOChanOnDev

        internal void ZeroAOChanOnDev(string dev, int[] channelsToZero)
        {
            lock (this)
            {
                try
                {
                    // Create an analog out task for a given device for all 4 channels.
                    // Write clearingBufferSize zeros to that port. Wait
                    // until this is finished and destroy the clearning Task.
                    Task analogClearingTask = new Task("AnalogClear");

                    foreach (int chan in channelsToZero)
                        analogClearingTask.AOChannels.CreateVoltageChannel(
                            "/" + dev + "/ao" + chan, "", -10.0, 10.0, AOVoltageUnits.Volts);

                    //analogClearingTask.Timing.ConfigureSampleClock("/" + dev + "/PF",
                    //    clearingSampleRate,
                    //    SampleClockActiveEdge.Rising,
                    //    SampleQuantityMode.FiniteSamples,
                    //    clearingBufferSize);
                    analogClearingTask.Timing.ReferenceClockSource = ("/" + dev + "/PFI2");
                    analogClearingTask.Timing.ReferenceClockRate = 10e6;

                    AnalogMultiChannelWriter analogClearingWriter = new
                        AnalogMultiChannelWriter(analogClearingTask.Stream);

                    double[] zeroData = new double[channelsToZero.Length];
                    analogClearingWriter.BeginWriteSingleSample(false, zeroData, null, null);
                    analogClearingTask.Control(TaskAction.Verify);
                    analogClearingTask.Start();
                    //analogClearingWriter.WriteSingleSample(true, zeroData);
                    //analogClearingWriter.WriteMultiSample(true, zeroData);
                    analogClearingTask.WaitUntilDone(30);
                    analogClearingTask.Stop();
                    analogClearingTask.Dispose();
                    analogClearingTask = null;
                }
                catch (Exception e)
                {
                    Console.WriteLine("Could not zero analog outputs on device: " + dev);
                    Console.WriteLine(e.Message);
                }
            }
        }
开发者ID:rzellertownson,项目名称:neurorighter,代码行数:44,代码来源:ZeroOutput.cs

示例10: indhentData

        //Skraldespanden
        //protected override void Dispose(bool disposing)
        //{
        //    if (disposing)
        //    {
        //        if (components != null)
        //        {
        //            components.Dispose();
        //        }
        //        if (myTask != null)
        //        {
        //            runningTask = null;
        //            myTask.Dispose();
        //        }
        //    }
        //    Dispose(disposing);
        //}
        public void indhentData()
        {
            if (runningTask == null)
            {
                try
                {
                    // Create a new task
                    myTask = new Task();

                    // Create a virtual channel
                    myTask.AIChannels.CreateVoltageChannel("Dev1/ai0", "",
                        (AITerminalConfiguration)(-1), Convert.ToDouble(-3.00),
                        Convert.ToDouble(3.00), AIVoltageUnits.Volts);

                    // Configure the timing parameters
                    myTask.Timing.ConfigureSampleClock("", Convert.ToDouble(1000),
                        SampleClockActiveEdge.Rising, SampleQuantityMode.ContinuousSamples, 1000);

                    // Verify the Task
                    myTask.Control(TaskAction.Verify);

                    // Prepare the table for Data
                    InitializeDataTable(myTask.AIChannels, ref dataTable);

                    runningTask = myTask;
                    analogInReader = new AnalogMultiChannelReader(myTask.Stream);
                    analogCallback = new AsyncCallback(AnalogInCallback); //Håndterer de data vi for ind løbende, selvkørende event

                    // Use SynchronizeCallbacks to specify that the object
                    // marshals callbacks across threads appropriately.
                    analogInReader.SynchronizeCallbacks = true; //Sørger for at sætte trådene til den prioritet som de skal have
                    analogInReader.BeginReadWaveform(Convert.ToInt32(10),
                        analogCallback, myTask);
                }
                catch (DaqException exception)
                {
                    runningTask = null;
                    myTask.Dispose();
                    throw exception;
                }
            }
        }
开发者ID:banasik,项目名称:Semesterprojekt3,代码行数:59,代码来源:IndhentDataDAQ.cs

示例11: DoWork

        public override void DoWork(BackgroundWorker worker)
        {
            updateTimer = new System.Timers.Timer();
            updateTimer.Interval = 100;
            updateTimer.Elapsed += new System.Timers.ElapsedEventHandler(UpdateTimer_Tick);
            updateTimer.Start();

            while (!worker.CancellationPending)
            {
                try
                {
                    //this.Connect();

                    System.Console.WriteLine("Initializing DAQ stuff");
                    using (Task myTask = new Task())
                    {
                        //Create a virtual channel
                        myTask.AIChannels.CreateVoltageChannel(Channel, Name,
                            AITerminalConfiguration.Rse, Convert.ToDouble(0),
                                Convert.ToDouble(5), AIVoltageUnits.Volts);
                        AnalogMultiChannelReader reader = new AnalogMultiChannelReader(myTask.Stream);
                        //Verify the Task
                        myTask.Control(TaskAction.Verify);

                        //completed initialization.
                        //Now to read some stuff
                        System.Console.WriteLine("Initialized DAQ stuff");

                        double[] data;
                        while (!worker.CancellationPending)
                        {
                            data = DoRead(reader);
                            signal = Math.Round(data.First(), 2);
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("{0} Read Failed.\nReason: {1}", Name, e);
                }
            }
        }
开发者ID:dansam100,项目名称:FYDP,代码行数:42,代码来源:ActiveReader.cs

示例12: AcquisitionStarting

        public override void AcquisitionStarting()
        {
            // configure the analog input
            inputTask = new Task("analog inputs");

            string[] channels = ((String)settings["channelList"]).Split(',');
            if (!Environs.Debug)
            {
                foreach (string channel in channels)
                {
                    ((AnalogInputChannel)Environs.Hardware.AnalogInputChannels[channel]).AddToTask(
                        inputTask,
                        (double)settings["inputRangeLow"],
                        (double)settings["inputRangeHigh"]
                        );
                    }
                inputTask.Control(TaskAction.Verify);
            }
            reader = new AnalogMultiChannelReader(inputTask.Stream);
        }
开发者ID:ColdMatter,项目名称:EDMSuite,代码行数:20,代码来源:DAQMxAnalogInputPlugin.cs

示例13: SetAnalogOutput

 private void SetAnalogOutput(Task task, double voltage)
 {
     AnalogSingleChannelWriter writer = new AnalogSingleChannelWriter(task.Stream);
     writer.WriteSingleSample(true, voltage);
     task.Control(TaskAction.Unreserve);
 }
开发者ID:ColdMatter,项目名称:EDMSuite,代码行数:6,代码来源:Controller.cs

示例14: AcquisitionStarting

        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);
        }
开发者ID:ColdMatter,项目名称:EDMSuite,代码行数:69,代码来源:BufferedEventCountingShotGathererPlugin.cs

示例15: StartScope

        private void StartScope()
        {
            if (runningTask == null)
            {
                try
                {
                    // Create a new task
                    myTask = new Task();

                    // Create a virtual channel
                    myTask.AIChannels.CreateVoltageChannel(comboBoxChannel.Text, "",
                        (AITerminalConfiguration)(-1), Convert.ToDouble(spinEditMinVal.Value),
                        Convert.ToDouble(spinEditMaxVal.Value), AIVoltageUnits.Volts);

                    // Configure the timing parameters
                    myTask.Timing.ConfigureSampleClock("", Convert.ToDouble(sampleRate),
                        SampleClockActiveEdge.Rising, SampleQuantityMode.ContinuousSamples, Convert.ToInt32(sampleRead));

                    // Verify the Task
                    myTask.Control(TaskAction.Verify);

                    runningTask = myTask;
                    analogInReader = new AnalogMultiChannelReader(myTask.Stream);
                    analogCallback = new AsyncCallback(AnalogInCallback);

                    // Use SynchronizeCallbacks to specify that the object
                    // marshals callbacks across threads appropriately.
                    analogInReader.SynchronizeCallbacks = true;
                    analogInReader.BeginReadWaveform(Convert.ToInt32(sampleRead),
                        analogCallback, myTask);
                }
                catch (DaqException exception)
                {
                    // Display Errors
                    MessageBox.Show(exception.Message);
                    runningTask = null;
                    myTask.Dispose();
                }
            }
        }
开发者ID:farisais,项目名称:sigsence-apps-core,代码行数:40,代码来源:FormNIDeviceSetup.cs


注:本文中的Task.Control方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。