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


C# Task.Control方法代码示例

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


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

示例1: Read

        public void Read()
        {
            try {
                string[] channelNameList = DaqSystem.Local.GetPhysicalChannels(PhysicalChannelTypes.AI, PhysicalChannelAccess.External);
                if (channelNameList.Length > 0) {
                    Task task = new Task();
                    task.AIChannels.CreateVoltageChannel(channelNameList[0], "Voltage", AITerminalConfiguration.Differential, 0.0, 10.0, AIVoltageUnits.Volts);
                    task.Timing.ConfigureSampleClock("", 100000, SampleClockActiveEdge.Rising, SampleQuantityMode.FiniteSamples);
                    task.Control(TaskAction.Verify);

                    AnalogSingleChannelReader airead = new AnalogSingleChannelReader(task.Stream);
                    AnalogWaveform<double> waveform;
                    for(int i=0;i<repeat;i++){
                        waveform = airead.ReadWaveform(sampleRate);
                        datalist.AddRange(waveform.GetRawData());
                        Console.Out.WriteLine("Acquire " + i + "th try");
                    }
                    StreamWriter writer = new StreamWriter(File.Open("ai.txt", FileMode.Create));
                    int c = 0;
                    foreach (double d in datalist) {
                        writer.WriteLine(String.Format("{0} {1}",c,d));
                        c++;
                    }
                    writer.Close();
                }
            } catch (DaqException e) {
                Console.Out.WriteLine(e.Message);
            }
        }
开发者ID:kodack64,项目名称:NIDAQ_Control,代码行数:29,代码来源:Program.cs

示例2: ConfigureReadAI

        //AND CAVITY VOLTAGE!!!
        //The photodiode inputs have been bundled into one task. We never read one photodiode without reading
        //the other.
        public void ConfigureReadAI(int numberOfMeasurements, bool autostart)
        {
            readAIsTask = new Task("readAI");

            channels = new Dictionary<string, AnalogInputChannel>();
            foreach (string s in analogInputs)
            {
                AnalogInputChannel channel = (AnalogInputChannel)Environs.Hardware.AnalogInputChannels[s];
                channels.Add(s, channel);
            }

            foreach (KeyValuePair<string, AnalogInputChannel> pair in channels)
            {
                pair.Value.AddToTask(readAIsTask, 0, 10);
            }

            if (autostart == false)
            {
                 readAIsTask.Timing.ConfigureSampleClock(
                    "",
                    40000,
                    SampleClockActiveEdge.Rising,
                    SampleQuantityMode.FiniteSamples, numberOfMeasurements);
                readAIsTask.Triggers.StartTrigger.ConfigureDigitalEdgeTrigger(
                    (string)Environs.Hardware.GetInfo(trigger),
                    DigitalEdgeStartTriggerEdge.Rising);
            }
            readAIsTask.Control(TaskAction.Verify);
            analogReader = new AnalogMultiChannelReader(readAIsTask.Stream);
        }
开发者ID:akaushik1,项目名称:EDMSuite,代码行数:33,代码来源:DAQMxTCL2012ExtTriggeredMultiReadHelper.cs

示例3: ConfigureCavityScan

 public void ConfigureCavityScan(int numberOfSteps, bool autostart)
 {
     outputCavityTask = new Task("CavityPiezoVoltage");
     cavityChannel =
                 (AnalogOutputChannel)Environs.Hardware.AnalogOutputChannels[cavityChannelName];
     cavityChannel.AddToTask(outputCavityTask, 0, 10);
     outputCavityTask.Control(TaskAction.Verify);
     cavityWriter = new AnalogSingleChannelWriter(outputCavityTask.Stream);
 }
开发者ID:ColdMatter,项目名称:EDMSuite,代码行数:9,代码来源:DAQMxTCLHelperSWTimed.cs

示例4: ConfigureSetLaserVoltage

 //This takes in a voltage. A bit cheezy, but I needed the laser
 // voltage to be set as soon value as soon as it gets configured.
 public void ConfigureSetLaserVoltage(double voltage)
 {
     outputLaserTask = new Task("FeedbackToLaser" + laserChannelName);
     laserChannel =
             (AnalogOutputChannel)Environs.Hardware.AnalogOutputChannels[laserChannelName];
     laserChannel.AddToTask(outputLaserTask, laserChannel.RangeLow, laserChannel.RangeHigh);
     outputLaserTask.Control(TaskAction.Verify);
     laserWriter = new AnalogSingleChannelWriter(outputLaserTask.Stream);
     laserWriter.WriteSingleSample(true, voltage);
     //outputLaserTask.Start();
 }
开发者ID:JamesNgai,项目名称:EDMSuite,代码行数:13,代码来源:DAQMxTCL2012LaserControlHelper.cs

示例5: ConfigureCavityScan

        public void ConfigureCavityScan(int numberOfSteps, bool autostart)
        {
            outputCavityTask = new Task("CavityPiezoVoltage");
            cavityChannel =
                        (AnalogOutputChannel)Environs.Hardware.AnalogOutputChannels[cavityChannelName];
            cavityChannel.AddToTask(outputCavityTask, 0, 10);
            outputCavityTask.AOChannels[0].DataTransferMechanism = AODataTransferMechanism.Dma;

            if (!autostart)
            {
                outputCavityTask.Timing.ConfigureSampleClock("", 500,
                SampleClockActiveEdge.Rising, SampleQuantityMode.FiniteSamples, 2 * numberOfSteps);
                outputCavityTask.Triggers.StartTrigger.ConfigureDigitalEdgeTrigger(
                        (string)Environs.Hardware.GetInfo(cavityTriggerInputName), DigitalEdgeStartTriggerEdge.Rising);
            }

            outputCavityTask.Control(TaskAction.Verify);
            cavityWriter = new AnalogSingleChannelWriter(outputCavityTask.Stream);
        }
开发者ID:ColdMatter,项目名称:EDMSuite,代码行数:19,代码来源:DAQMxTransferCavityLockHelper.cs

示例6: Read2

        public void Read2()
        {
            try {
                string[] channelNameList = DaqSystem.Local.GetPhysicalChannels(PhysicalChannelTypes.DILine, PhysicalChannelAccess.External);
                if (channelNameList.Length > 0) {
                    Task task = new Task("Digital Input Test");
                    task.DIChannels.CreateChannel(channelNameList[0]+":7", "",ChannelLineGrouping.OneChannelForAllLines);
                    task.Timing.ConfigureSampleClock("", 10000, SampleClockActiveEdge.Rising, SampleQuantityMode.FiniteSamples);
                    task.Control(TaskAction.Verify);

                    DigitalSingleChannelReader diread = new DigitalSingleChannelReader(task.Stream);
                    DigitalWaveform waveform;
                    for (int i = 0; i < repeat; i++) {
                        waveform = diread.ReadWaveform(sampleRate);
                        foreach(DigitalWaveformSignal signal in waveform.Signals){
                            foreach (DigitalState state in signal.States) {
                                if (state == DigitalState.ForceDown) {
                                    Console.Write(0);
                                } else if (state == DigitalState.ForceUp) {
                                    Console.Write(1);
                                } else {
                                    Console.Write("?");
                                }
                            }
                            Console.WriteLine();
                        }
                        Console.Out.WriteLine("Acquire " + i + "th try");
                    }
                    StreamWriter writer = new StreamWriter(File.Open("di.txt", FileMode.Create));
                    int c = 0;
                    foreach (double d in datalist) {
                        writer.WriteLine(String.Format("{0} {1}", c, d));
                        c++;
                    }
                    writer.Close();
                }
            } catch (DaqException e) {
                Console.Out.WriteLine(e.Message);
            }
        }
开发者ID:kodack64,项目名称:NIDAQ_Control,代码行数:40,代码来源:Program.cs

示例7: ChannelOutput

        internal ChannelOutput(double samplingRate, double outputRefreshTime, double inputRefreshTime, Task spikeTask, String NIDevice, int NIChannel)
        {
            //Compute buffer length, instantiate buffer
            int multiple = (int)(Math.Round(outputRefreshTime / inputRefreshTime)); //Get number of input buffer reads that approximate the desired output rate
            if (multiple < 1) multiple = 1; //Ensure the multiple is at least 1
            int bufferLength = (int)((double)multiple * inputRefreshTime * samplingRate); //Calculate length
            buffer = new double[bufferLength];

            //Create new task
            analogOutputTask = new Task("Playback Analog Output Task");
            analogOutputTask.AOChannels.CreateVoltageChannel(NIDevice + "/ao" + NIChannel, "",
                            -10.0, 10.0, AOVoltageUnits.Volts);
            analogOutputTask.Timing.ReferenceClockSource = spikeTask.Timing.ReferenceClockSource;
            analogOutputTask.Timing.ReferenceClockRate = spikeTask.Timing.ReferenceClockRate;
            analogOutputTask.Timing.ConfigureSampleClock("", samplingRate,
                            SampleClockActiveEdge.Rising, SampleQuantityMode.ContinuousSamples, bufferLength);
            analogOutputTask.Control(TaskAction.Verify);

            //Create writer
            analogOutputWriter = new AnalogSingleChannelWriter(analogOutputTask.Stream);
            analogOutputWriter.SynchronizeCallbacks = false;
        }
开发者ID:rzellertownson,项目名称:neurorighter,代码行数:22,代码来源:ChannelOutput.cs

示例8: ConfigureReadAI

 //AND CAVITY VOLTAGE!!!
 //The photodiode inputs have been bundled into one task. We never read one photodiode without reading
 //the other.
 public void ConfigureReadAI(int numberOfMeasurements, bool autostart)
 {
     readAIsTask = new Task("readAI");
     referenceLaserChannel = (AnalogInputChannel)Environs.Hardware.AnalogInputChannels[masterPDChannelName];
     lockingLaserChannel = (AnalogInputChannel)Environs.Hardware.AnalogInputChannels[slavePDChannelName];
     cavityVoltageChannel = (AnalogInputChannel)Environs.Hardware.AnalogInputChannels[cavityReadChannelName];
     referenceLaserChannel.AddToTask(readAIsTask, 0, 10);
     lockingLaserChannel.AddToTask(readAIsTask, 0, 10);
     cavityVoltageChannel.AddToTask(readAIsTask, 0, 10);
     if (autostart == false)
     {
          readAIsTask.Timing.ConfigureSampleClock(
             "",
             66000,
             SampleClockActiveEdge.Rising,
             SampleQuantityMode.FiniteSamples, numberOfMeasurements);
         readAIsTask.Triggers.StartTrigger.ConfigureDigitalEdgeTrigger(
             (string)Environs.Hardware.GetInfo(AITriggerInputName),
             DigitalEdgeStartTriggerEdge.Rising);
     }
     readAIsTask.Control(TaskAction.Verify);
     analogReader = new AnalogMultiChannelReader(readAIsTask.Stream);
 }
开发者ID:akaushik1,项目名称:EDMSuite,代码行数:26,代码来源:DAQMxTCL2012HelperExtTriggeredMultiRead.cs

示例9: radioButton_stimVoltageControlled_Click

        private void radioButton_stimVoltageControlled_Click(object sender, EventArgs e)
        {
            if (radioButton_stimVoltageControlled.Checked)
            {
                Properties.Settings.Default.StimVoltageControlled = true;
                if (Properties.Settings.Default.UseStimulator)
                {
                    //this line goes high (TTL-wise) when we're doing current-controlled stim, low for voltage-controlled
                    stimIvsVTask = new Task("stimIvsV");
                    stimIvsVTask.DOChannels.CreateChannel(Properties.Settings.Default.StimIvsVDevice + "/Port1/line0", "",
                        ChannelLineGrouping.OneChannelForAllLines);
                    stimIvsVWriter = new DigitalSingleChannelWriter(stimIvsVTask.Stream);
                    stimIvsVTask.Control(TaskAction.Verify);
                    stimIvsVWriter.WriteSingleSampleSingleLine(true, false);
                    stimIvsVTask.WaitUntilDone();
                    stimIvsVTask.Stop();
                    stimIvsVTask.Dispose();
                }

                radioButton_impVoltage.Checked = true;
            }
        }
开发者ID:rzellertownson,项目名称:neurorighter,代码行数:22,代码来源:stim.cs

示例10: Initialize

        public void Initialize()
        {
            //    counterTask = new Task("");
            //    this.counterTask.CIChannels.CreateFrequencyChannel(
            //        currentLeakageCounterChannel.PhysicalChannel,
            //        "",
            //        0,
            //        150000,
            //        CIFrequencyStartingEdge.Rising,
            //      CIFrequencyMeasurementMethod.HighFrequencyTwoCounter,
            //       // the units of measurement time are not specified anywhere in the docs :-(
            //       measurementTime,
            //        // this has to be more than four to stop NIDAQ crashing, even though it is not used in this mode!
            //        100,
            //        CIFrequencyUnits.Hertz
            //        );
            //    counterTask.Stream.Timeout = (int)(10.1 * 1000 * measurementTime);
            //    leakageReader = new CounterReader(counterTask.Stream);

            monitorTask = new Task("EDMHCIn" + leakageChannel);
            ((AnalogInputChannel)Environs.Hardware.AnalogInputChannels[leakageChannel]).AddToTask(
                monitorTask,
                0,
                10
            );
            monitorTask.Control(TaskAction.Verify);
            leakageReader = new AnalogSingleChannelReader(monitorTask.Stream);
        }
开发者ID:ColdMatter,项目名称:EDMSuite,代码行数:28,代码来源:LeakageMonitor.cs

示例11: ConfigureReadPhotodiodes

        //The photodiode inputs have been bundled into one task. We never read one photodiode without reading
        //the other.
        public void ConfigureReadPhotodiodes(int numberOfMeasurements, bool autostart)
        {
            readPhotodiodesTask = new Task("ReadPhotodiodes");
            referenceLaserChannel = (AnalogInputChannel)Environs.Hardware.AnalogInputChannels[masterPDChannelName];
            lockingLaserChannel = (AnalogInputChannel)Environs.Hardware.AnalogInputChannels[slavePDChannelName];
            referenceLaserChannel.AddToTask(readPhotodiodesTask, 0, 10);
            lockingLaserChannel.AddToTask(readPhotodiodesTask, 0, 10);

            if (!autostart)
            {
                readPhotodiodesTask.Timing.ConfigureSampleClock(
                   "",
                   500,
                   SampleClockActiveEdge.Rising,
                   SampleQuantityMode.FiniteSamples, 2 * numberOfMeasurements);
                readPhotodiodesTask.Triggers.StartTrigger.ConfigureDigitalEdgeTrigger(
                    (string)Environs.Hardware.GetInfo(photodiodeTriggerInputName),
                    DigitalEdgeStartTriggerEdge.Rising);
            }
            readPhotodiodesTask.AIChannels[0].DataTransferMechanism = AIDataTransferMechanism.UsbBulk;
            readPhotodiodesTask.AIChannels[1].DataTransferMechanism = AIDataTransferMechanism.UsbBulk;
            readPhotodiodesTask.Control(TaskAction.Verify);
            photodiodesReader = new AnalogMultiChannelReader(readPhotodiodesTask.Stream);
        }
开发者ID:ColdMatter,项目名称:EDMSuite,代码行数:26,代码来源:DAQMxTransferCavityLockHelper.cs

示例12: ReadAnalogInput

        private double ReadAnalogInput(Task task, double sampleRate, int numOfSamples)
        {
            //Configure the timing parameters of the task
            task.Timing.ConfigureSampleClock("", sampleRate,
                SampleClockActiveEdge.Rising, SampleQuantityMode.FiniteSamples, numOfSamples);

            //Read in multiple samples
            AnalogSingleChannelReader reader = new AnalogSingleChannelReader(task.Stream);
            double[] valArray = reader.ReadMultiSample(numOfSamples);
            task.Control(TaskAction.Unreserve);

            //Calculate the average of the samples
            double sum = 0;
            for (int j = 0; j < numOfSamples; j++)
            {
                sum = sum + valArray[j];
            }
            double val = sum / numOfSamples;
            return val;
        }
开发者ID:jadevlin,项目名称:EDMSuite,代码行数:20,代码来源:Controller.cs

示例13: button_electrolesioningStart_Click

        private void button_electrolesioningStart_Click(object sender, EventArgs e)
        {
            //Change mouse cursor to waiting cursor
            this.Cursor = Cursors.WaitCursor;

            //Grab values from UI
            double voltage = Convert.ToDouble(numericUpDown_electrolesioningVoltage.Value);
            double duration = Convert.ToDouble(numericUpDown_electrolesioningDuration.Value);
            List<Int32> chList = new List<int>(listBox_electrolesioningChannels.SelectedIndices.Count);
            for (int i = 0; i < listBox_electrolesioningChannels.SelectedIndices.Count; ++i)
                chList.Add(listBox_electrolesioningChannels.SelectedIndices[i] + 1); //+1 since indices are 0-based but channels are 1-base

            //Disable buttons, so users don't try running two experiments at once
            button_electrolesioningStart.Enabled = false;
            button_electrolesioningSelectAll.Enabled = false;
            button_electrolesioningSelectNone.Enabled = false;
            button_electrolesioningStart.Refresh();

            //Refresh stim task
            stimDigitalTask.Dispose();
            stimDigitalTask = new Task("stimDigitalTask_Electrolesioning");
            if (Properties.Settings.Default.StimPortBandwidth == 32)
                stimDigitalTask.DOChannels.CreateChannel(Properties.Settings.Default.StimulatorDevice + "/Port0/line0:31", "",
                    ChannelLineGrouping.OneChannelForAllLines); //To control MUXes
            else if (Properties.Settings.Default.StimPortBandwidth == 8)
                stimDigitalTask.DOChannels.CreateChannel(Properties.Settings.Default.StimulatorDevice + "/Port0/line0:7", "",
                    ChannelLineGrouping.OneChannelForAllLines); //To control MUXes
            stimDigitalWriter = new DigitalSingleChannelWriter(stimDigitalTask.Stream);

            //Refresh pulse task
            stimPulseTask.Dispose();
            stimPulseTask = new Task("stimPulseTask");
            if (Properties.Settings.Default.StimPortBandwidth == 32)
            {
                stimPulseTask.AOChannels.CreateVoltageChannel(Properties.Settings.Default.StimulatorDevice + "/ao0", "", -10.0, 10.0, AOVoltageUnits.Volts); //Triggers
                stimPulseTask.AOChannels.CreateVoltageChannel(Properties.Settings.Default.StimulatorDevice + "/ao1", "", -10.0, 10.0, AOVoltageUnits.Volts); //Triggers
                stimPulseTask.AOChannels.CreateVoltageChannel(Properties.Settings.Default.StimulatorDevice + "/ao2", "", -10.0, 10.0, AOVoltageUnits.Volts); //Actual Pulse
                stimPulseTask.AOChannels.CreateVoltageChannel(Properties.Settings.Default.StimulatorDevice + "/ao3", "", -10.0, 10.0, AOVoltageUnits.Volts); //Timing
            }
            else if (Properties.Settings.Default.StimPortBandwidth == 8)
            {
                stimPulseTask.AOChannels.CreateVoltageChannel(Properties.Settings.Default.StimulatorDevice + "/ao0", "", -10.0, 10.0, AOVoltageUnits.Volts);
                stimPulseTask.AOChannels.CreateVoltageChannel(Properties.Settings.Default.StimulatorDevice + "/ao1", "", -10.0, 10.0, AOVoltageUnits.Volts);
            }

            stimPulseWriter = new AnalogMultiChannelWriter(stimPulseTask.Stream);

            stimPulseTask.Timing.ConfigureSampleClock("",
                StimPulse.STIM_SAMPLING_FREQ, SampleClockActiveEdge.Rising, SampleQuantityMode.FiniteSamples);
            stimPulseTask.Timing.SamplesPerChannel = 2;

            stimDigitalTask.Control(TaskAction.Verify);
            stimPulseTask.Control(TaskAction.Verify);

            //For each channel, deliver lesioning pulse
            for (int i = 0; i < chList.Count; ++i)
            {
                int channel = chList[i];
                UInt32 data = StimPulse.channel2MUX((double)channel);

                //Setup digital waveform, open MUX channel
                stimDigitalWriter.WriteSingleSamplePort(true, data);
                stimDigitalTask.WaitUntilDone();
                stimDigitalTask.Stop();

                //Write voltage to channel, wait duration, stop
                stimPulseWriter.WriteMultiSample(true, new double[,] { { 0, 0 }, { 0, 0 }, { voltage, voltage }, { 0, 0 } });
                stimPulseTask.WaitUntilDone();
                stimPulseTask.Stop();
                Thread.Sleep((int)(Math.Round(duration * 1000))); //Convert to ms
                stimPulseWriter.WriteMultiSample(true, new double[,] { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 } });
                stimPulseTask.WaitUntilDone();
                stimPulseTask.Stop();

                //Close MUX
                stimDigitalWriter.WriteSingleSamplePort(true, 0);
                stimDigitalTask.WaitUntilDone();
                stimDigitalTask.Stop();
            }

            bool[] fData = new bool[Properties.Settings.Default.StimPortBandwidth];
            stimDigitalWriter.WriteSingleSampleMultiLine(true, fData);
            stimDigitalTask.WaitUntilDone();
            stimDigitalTask.Stop();

            button_electrolesioningSelectAll.Enabled = true;
            button_electrolesioningSelectNone.Enabled = true;
            button_electrolesioningStart.Enabled = true;

            //Now, destroy the objects we made
            updateSettings();
            this.Cursor = Cursors.Default;
        }
开发者ID:rzellertownson,项目名称:neurorighter,代码行数:93,代码来源:elesion.cs

示例14: SetAnalogOutput

 /// <summary>
 /// Method for outputing a voltage on the DAQ
 /// </summary>
 /// <param name="task">NI-DAQ output task</param>
 /// <param name="voltage">Voltage to output. 
 /// Note must be between the limits outMax and outMin.
 /// The range is limited elsewhere in the code</param>
 private void SetAnalogOutput(Task task, double voltage)
 {
     AnalogSingleChannelWriter writer = new AnalogSingleChannelWriter(task.Stream);
     writer.WriteSingleSample(true, voltage);
     task.Control(TaskAction.Unreserve);
 }
开发者ID:ColdMatter,项目名称:EDMSuite,代码行数:13,代码来源:Controller.cs

示例15: Initialize

        public void Initialize()
        {
            _logger.Info("Initializing analog Stage....");

            // Setup an Analog Out task to move the stage along X and Y.
            Task _daqtskTask = new Task();

            try
            {
                // Add AO channels.
                _daqtskTask.AOChannels.CreateVoltageChannel("/" + this.m_sDevice + "/ao0", "aoChannelX", m_dVoltageMin, m_dVoltageMax, AOVoltageUnits.Volts);
                _daqtskTask.AOChannels.CreateVoltageChannel("/" + this.m_sDevice + "/ao1", "aoChannelY", m_dVoltageMin, m_dVoltageMax, AOVoltageUnits.Volts);
                _daqtskTask.AOChannels.CreateVoltageChannel("/" + this.m_sDevice + "/ao2", "aoChannelZ", m_dVoltageMin, m_dVoltageMax, AOVoltageUnits.Volts);

                // checked IFilteredTypeDescriptor everything is OK.
                _daqtskTask.Control(TaskAction.Verify);

                // Assign the task.
                this.m_daqtskMoveStage = _daqtskTask;

                // Return a status indication for the stage.
                this.m_bIsInitialized = true;
            }

            catch (DaqException exception)
            {
                if (_daqtskTask != null)
                {
                    _daqtskTask.Dispose();
                }

                this.m_bIsInitialized = false;

                _logger.Error("Unable to connect set up AO channels for Move task!" + exception.Message);
            }

            // If everything went well, tell everyone.
            if (EngagedChanged != null)
            {
                EngagedChanged(this, new EventArgs());
            }

            _logger.Info("Init Stage Done!");
        }
开发者ID:KrisJanssen,项目名称:SIS,代码行数:44,代码来源:NIAnalogStage.cs


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