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


C# Controller.StartAsync方法代码示例

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


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

示例1: ContinuousAcquisition

        public void ContinuousAcquisition(
            [Values(1000, 10000, 20000, 50000)] double sampleRate,
            [Values(20)] int nEpochs)
        {
            Converters.Clear();
            HekaDAQInputStream.RegisterConverters();
            HekaDAQOutputStream.RegisterConverters();

            Assert.That(HekaDAQController.AvailableControllers().Count(), Is.GreaterThan(0));
            foreach (var daq in HekaDAQController.AvailableControllers())
            {
                const double epochDuration = 1; //s

                try
                {
                    daq.InitHardware();
                    daq.SampleRate = new Measurement((decimal)sampleRate, "Hz");

                    var controller = new Controller { Clock = daq.Clock, DAQController = daq };

                    var dev0 = new UnitConvertingExternalDevice("Device0", "Manufacturer", controller, new Measurement(0, "V"))
                    {
                        MeasurementConversionTarget = "V",
                        Clock = daq.Clock,
                        OutputSampleRate = daq.SampleRate,
                        InputSampleRate = daq.SampleRate
                    };
                    dev0.BindStream((IDAQOutputStream)daq.GetStreams("ao0").First());
                    dev0.BindStream((IDAQInputStream)daq.GetStreams("ai0").First());

                    var dev1 = new UnitConvertingExternalDevice("Device1", "Manufacturer", controller, new Measurement(0, "V"))
                    {
                        MeasurementConversionTarget = "V",
                        Clock = daq.Clock,
                        OutputSampleRate = daq.SampleRate,
                        InputSampleRate = daq.SampleRate
                    };
                    dev1.BindStream((IDAQOutputStream)daq.GetStreams("ao1").First());
                    dev1.BindStream((IDAQInputStream)daq.GetStreams("ai1").First());

                    var nDAQStarts = 0;
                    daq.Started += (evt, args) =>
                        {
                            nDAQStarts++;
                        };

                    var completedEpochs = new Queue<Epoch>();
                    controller.CompletedEpoch += (evt, args) =>
                        {
                            completedEpochs.Enqueue(args.Epoch);
                            if (completedEpochs.Count >= nEpochs)
                            {
                                controller.RequestStop();
                            }
                        };

                    var epochs = new Queue<Epoch>();
                    var nSamples = (int)TimeSpan.FromSeconds(epochDuration).Samples(daq.SampleRate);

                    // Triangle wave
                    var data = Enumerable.Range(0, nSamples/2)
                                         .Select(k => new Measurement(k/(nSamples/2.0/10.0), "V") as IMeasurement)
                                         .ToList();
                    var stimData = data.Concat(Enumerable.Reverse(data)).ToList();

                    var fakeEpochPersistor = new FakeEpochPersistor();

                    bool start = true;

                    for (int j = 0; j < nEpochs; j++)
                    {
                        var e = new Epoch("HekaIntegration" + j);

                        e.Stimuli[dev0] = new RenderedStimulus("Stim",
                                                               new Dictionary<string, object>(),
                                                               new OutputData(stimData, daq.SampleRate));
                        e.Responses[dev0] = new Response();

                        e.SetBackground(dev1, new Measurement(1, "V"), daq.SampleRate);
                        e.Responses[dev1] = new Response();

                        epochs.Enqueue(e);

                        controller.EnqueueEpoch(e);

                        if (start)
                        {
                            controller.StartAsync(fakeEpochPersistor);
                            start = false;
                        }
                    }

                    while (controller.IsRunning)
                    {
                        Thread.Sleep(1);
                    }

                    controller.WaitForCompletedEpochTasks();
                    var stopTime = controller.Clock.Now;

//.........这里部分代码省略.........
开发者ID:Symphony-DAS,项目名称:symphony-core,代码行数:101,代码来源:HekaIntegration.cs

示例2: RunEpochThrowsWhenRunningSimultaneousEpochs

        public void RunEpochThrowsWhenRunningSimultaneousEpochs()
        {
            Converters.Register("V", "V",
                // just an identity conversion for now, to pass Validate()
                                (IMeasurement m) => m);

            var c = new Controller { DAQController = new SimpleDAQController() };
            c.DAQController.Clock = c.DAQController as IClock;

            var sampleRate = new Measurement(1, "Hz");

            var e = new Epoch(UNUSED_PROTOCOL);
            var dev = new UnitConvertingExternalDevice("dev", "co", c, new Measurement(0, "V"))
            {
                MeasurementConversionTarget = "V",
                Clock = c.Clock,
                OutputSampleRate = sampleRate
            };
            var outStream = new DAQOutputStream("out")
            {
                MeasurementConversionTarget = "V",
                Clock = c.Clock
            };
            dev.BindStream(outStream);

            e.Stimuli[dev] = new DelegatedStimulus("ID1", "units", sampleRate, new Dictionary<string, object>(),
                                                    (parameters, duration) => null,
                                                    objects => Option<TimeSpan>.None());

            bool started = false;
            c.Started += (evt, args) =>
            {
                started = true;
            };

            c.EnqueueEpoch(e);
            c.StartAsync(null);

            while (!started)
            {
                Thread.Sleep(1);
            }

            Assert.That(() => c.RunEpoch(e, new FakeEpochPersistor()), Throws.Exception.TypeOf<SymphonyControllerException>());
        }
开发者ID:Symphony-DAS,项目名称:symphony-core,代码行数:45,代码来源:ControllerTests.cs


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