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


C# Controller.RunEpoch方法代码示例

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


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

示例1: RunEpochThrowsGivenIndefiniteEpochWithResponses

        public void RunEpochThrowsGivenIndefiniteEpochWithResponses()
        {
            var c = new Controller();

            var e = new Epoch(UNUSED_PROTOCOL);
            var dev2 = new UnitConvertingExternalDevice("dev2", "co", c, new Measurement(0, "V"));

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

            e.Stimuli[dev2] = new DelegatedStimulus("ID2", "units",
                                                    new Dictionary<string, object>(),
                                                    (x, y) => null,
                                                    (p) => Option<TimeSpan>.None());
            e.Responses[dev2] = new Response();

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

示例2: ShouldDiscardEpochsWithExceptionalStop

        public void ShouldDiscardEpochsWithExceptionalStop()
        {
            var c = new Controller();
            bool evt = false;

            c.DAQController = new ExceptionThrowingDAQController();
            c.DAQController.Clock = c.DAQController as IClock;
            c.Clock = c.DAQController as IClock;
            var persistor = new FakeEpochPersistor();

            c.DiscardedEpoch += (co, args) => evt = true;

            var e = new Epoch(UNUSED_PROTOCOL);

            try
            {
                c.RunEpoch(e, persistor);
            }
            catch (Exception)
            { }

            Assert.True(evt);
            Assert.False(persistor.PersistedEpochs.ToList().Contains(e));
        }
开发者ID:physion,项目名称:symphony-core,代码行数:24,代码来源:ControllerTests.cs

示例3: RunEpochShouldDiscardEpochWhenCancelEpochCalled

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

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

            var e = new Epoch(UNUSED_PROTOCOL);
            var dev1 = new UnitConvertingExternalDevice("dev1", "co", c, new Measurement(0, "V"))
                           {
                               MeasurementConversionTarget = "V",
                               Clock = c.Clock
                           };

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

            e.Stimuli[dev1] = new DelegatedStimulus("ID1", "units", new Dictionary<string, object>(),
                                                    (parameters, duration) =>
                                                    new OutputData(new List<IMeasurement>(), sampleRate, false),
                                                    objects => Option<TimeSpan>.None());

            bool epochDiscarded = false;
            c.DiscardedEpoch += (sender, args) =>
                                    {
                                        epochDiscarded = true;
                                    };

            c.DAQController.ProcessIteration += (o, eventArgs) =>
                                       {
                                           Console.WriteLine("Process iteration");
                                           c.CancelEpoch();
                                       };

            c.RunEpoch(e, new FakeEpochPersistor());

            Assert.True(epochDiscarded);
        }
开发者ID:physion,项目名称:symphony-core,代码行数:39,代码来源:ControllerTests.cs

示例4: RunEpochThrowsGivenEpochWithInconsistentStimulusDurations

        public void RunEpochThrowsGivenEpochWithInconsistentStimulusDurations()
        {
            var c = new Controller();

            var e = new Epoch(UNUSED_PROTOCOL);
            var dev1 = new UnitConvertingExternalDevice("dev1", "co", c, new Measurement(0, "V"));
            var dev2 = new UnitConvertingExternalDevice("dev2", "co", c, new Measurement(0, "V"));

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

            e.Stimuli[dev1] = new RenderedStimulus((string) "ID1",
                                                   (IDictionary<string, object>) new Dictionary<string, object>(),
                                                   (IOutputData) new OutputData(new List<IMeasurement> { new Measurement(1, "V") },
                                                                                sampleRate, true));

            e.Stimuli[dev2] = new RenderedStimulus((string) "ID2",
                                                   (IDictionary<string, object>) new Dictionary<string, object>(),
                                                   (IOutputData) new OutputData(new List<IMeasurement> { new Measurement(1, "V"), new Measurement(1, "V") },
                                                                                sampleRate, true));

            Assert.That(() => c.RunEpoch(e, new FakeEpochPersistor()), Throws.Exception.TypeOf<ArgumentException>());

            e.Stimuli[dev2] = new DelegatedStimulus("ID2", "V",
                                                    new Dictionary<string, object>(),
                                                    (x, y) => null,
                                                    (p) => Option<TimeSpan>.None());

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

示例5: ShouldSetStreamBackgroundOnStop

        public void ShouldSetStreamBackgroundOnStop(
            [Values(10000, 20000)] double sampleRate
            )
        {
            Converters.Clear();
            Converters.Register("V", "V",
                // just an identity conversion for now, to pass Validate()
                                (IMeasurement m) => m);
            HekaDAQInputStream.RegisterConverters();
            HekaDAQOutputStream.RegisterConverters();

            Assert.That(HekaDAQController.AvailableControllers().Count(), Is.GreaterThan(0));

            foreach (var daq in HekaDAQController.AvailableControllers())
            {

                const double epochDuration = 1; //s
                //Configure DAQ
                daq.InitHardware();
                try
                {
                    daq.SampleRate = new Measurement((decimal)sampleRate, "Hz");

                    var controller = new Controller();
                    controller.Clock = daq.Clock;
                    controller.DAQController = daq;

                    const decimal expectedBackgroundVoltage = -3.2m;
                    var expectedBackground = new Measurement(expectedBackgroundVoltage, "V");
                    var dev0 = new UnitConvertingExternalDevice("Device0", "Manufacturer", controller, expectedBackground)
                        {
                            MeasurementConversionTarget = "V",
                            OutputSampleRate = daq.SampleRate,
                            InputSampleRate = daq.SampleRate
                        };
                    dev0.BindStream(daq.GetStreams("ao0").First() as IDAQOutputStream);
                    dev0.BindStream(daq.GetStreams("ai0").First() as IDAQInputStream);
                    dev0.Clock = daq.Clock;

                    controller.DiscardedEpoch += (c, args) => Console.WriteLine("Discarded epoch: " + args.Epoch);

                    // Setup Epoch
                    var e = new Epoch("HekaIntegration");

                    var nSamples = (int)TimeSpanExtensions.Samples(TimeSpan.FromSeconds(epochDuration), daq.SampleRate);
                    IList<IMeasurement> stimData = (IList<IMeasurement>)Enumerable.Range(0, nSamples)
                                                               .Select(i => new Measurement((decimal)(8 * Math.Sin(((double)i) / (nSamples / 10.0))), "V") as IMeasurement)
                                                               .ToList();

                    var stim = new RenderedStimulus((string) "RenderedStimulus", (IDictionary<string, object>) new Dictionary<string, object>(),
                                                    (IOutputData) new OutputData(stimData, daq.SampleRate, false));
                    e.Stimuli[dev0] = stim;
                    e.Responses[dev0] = new Response();
                    e.Backgrounds[dev0] = new Background(expectedBackground, daq.SampleRate);

                    //Run single epoch
                    var fakeEpochPersistor = new FakeEpochPersistor();

                    controller.RunEpoch(e, fakeEpochPersistor);

                    Thread.Sleep(TimeSpan.FromMilliseconds(100)); //allow DAC to settle

                    var actual = ((HekaDAQController)controller.DAQController).ReadStreamAsync(
                        daq.GetStreams("ai0").First() as IDAQInputStream);

                    //Should be within +/- 0.025 volts
                    Assert.That(actual.Data.First().QuantityInBaseUnits, Is.InRange(expectedBackground.QuantityInBaseUnits - (decimal)0.025,
                        expectedBackground.QuantityInBaseUnits + (decimal)0.025));
                }
                finally
                {
                    if (daq.IsHardwareReady)
                        daq.CloseHardware();
                }

            }
        }
开发者ID:Symphony-DAS,项目名称:symphony-core,代码行数:77,代码来源:HekaIntegration.cs

示例6: EpochValidates

        public void EpochValidates()
        {
            var c = new Controller();

            var e = new Epoch(UNUSED_PROTOCOL);
            var dev2 = new UnitConvertingExternalDevice("dev2", "co", c, new Measurement(0, "V"));

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

            e.Stimuli[dev2] = new DelegatedStimulus("ID2", "units",
                                                    new Dictionary<string, object>(),
                                                    (x, y) => null,
                                                    (p) => Option<TimeSpan>.None());

            try
            {
                Assert.That(() => c.RunEpoch(e, new FakeEpochPersistor()), Throws.Nothing);
            }
            catch (Exception)
            {
                //pass
            }
        }
开发者ID:physion,项目名称:symphony-core,代码行数:23,代码来源:ControllerTests.cs

示例7: RenderedStimulus

        public void RenderedStimulus(
            [Values(1000, 10000, 20000, 50000)] double sampleRate,
            [Values(2)] int nEpochs
            )
        {
            Converters.Clear();
            Converters.Register("V", "V",
                // just an identity conversion for now, to pass Validate()
                                (IMeasurement m) => m);
            HekaDAQInputStream.RegisterConverters();
            HekaDAQOutputStream.RegisterConverters();

            Assert.That(HekaDAQController.AvailableControllers().Count(), Is.GreaterThan(0));
            foreach (var daq in HekaDAQController.AvailableControllers())
            {

                const double epochDuration = 5; //s

                daq.InitHardware();
                try
                {
                    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());

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

                        var nSamples = (int)TimeSpan.FromSeconds(epochDuration).Samples(daq.SampleRate);
                        IList<IMeasurement> stimData = (IList<IMeasurement>)Enumerable.Range(0, nSamples)
                                                                   .Select(i => new Measurement((decimal)(8 * Math.Sin(((double)i) / (nSamples / 10.0))), "V") as IMeasurement)
                                                                   .ToList();

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

                        e.Stimuli[dev1] = new RenderedStimulus((string) "RenderedStimulus", (IDictionary<string, object>) new Dictionary<string, object>(),
                                                       (IOutputData) new OutputData(Enumerable.Range(0, nSamples)
                                                                                        .Select(i => new Measurement((decimal)(8 * Math.Sin(((double)i) / (nSamples / 10.0))), "V"))
                                                                                        .ToList(),
                                                                                    daq.SampleRate));
                        e.Responses[dev1] = new Response();

                        //Run single epoch
                        var fakeEpochPersistor = new FakeEpochPersistor();

                        controller.RunEpoch(e, fakeEpochPersistor);

                        Assert.That((bool)e.StartTime, Is.True);
                        Assert.That((DateTimeOffset)e.StartTime, Is.LessThanOrEqualTo(controller.Clock.Now));
                        Assert.That(e.Responses[dev0].Duration, Is.EqualTo(((TimeSpan)e.Duration))
                                                                      .Within(TimeSpanExtensions.FromSamples(1,
                                                                                                             daq.
                                                                                                                 SampleRate)));
                        Assert.That(e.Responses[dev1].Duration, Is.EqualTo(((TimeSpan)e.Duration))
                                                                      .Within(TimeSpanExtensions.FromSamples(1,
                                                                                                             daq.
                                                                                                                 SampleRate)));
                        Assert.That(fakeEpochPersistor.PersistedEpochs, Contains.Item(e));

                        var failures0 =
                            e.Responses[dev0].Data.Select(
                                (t, i) => new { index = i, diff = t.QuantityInBaseUnits - stimData[i].QuantityInBaseUnits })
                                .Where(dif => Math.Abs(dif.diff) > (decimal)MAX_VOLTAGE_DIFF);

                        foreach (var failure in failures0.Take(10))
                            Console.WriteLine("{0}: {1}", failure.index, failure.diff);

                        /*
                         * According to Telly @ Heka, a patch cable may introduce 3-4 offset points
                         */
                        Assert.That(failures0.Count(), Is.LessThanOrEqualTo(4));

                        /*
                        //Since we only have one patch cable on the test rig,
                        //we're not checking second device response values

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

示例8: RunEpochThrowsGivenEpochWithInconsistentStimulusDurations

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

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

            var e = new Epoch(UNUSED_PROTOCOL);
            var dev1 = new UnitConvertingExternalDevice("dev1", "co", c, new Measurement(0, "V"))
            {
                MeasurementConversionTarget = "V",
                Clock = c.Clock
            };

            var dev2 = new UnitConvertingExternalDevice("dev2", "co", c, new Measurement(0, "V"))
            {
                MeasurementConversionTarget = "V",
                Clock = c.Clock
            };

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

            e.Stimuli[dev1] = new RenderedStimulus((string) "ID1",
                                                   (IDictionary<string, object>) new Dictionary<string, object>(),
                                                   (IOutputData) new OutputData(new List<IMeasurement> { new Measurement(1, "V") },
                                                                                sampleRate, true));

            e.Stimuli[dev2] = new RenderedStimulus((string) "ID2",
                                                   (IDictionary<string, object>) new Dictionary<string, object>(),
                                                   (IOutputData) new OutputData(new List<IMeasurement> { new Measurement(1, "V"), new Measurement(1, "V") },
                                                                                sampleRate, true));

            Assert.That(() => c.RunEpoch(e, new FakeEpochPersistor()), Throws.Exception.TypeOf<ArgumentException>());

            e.Stimuli[dev2] = new DelegatedStimulus("ID2", "V", sampleRate,
                                                    new Dictionary<string, object>(),
                                                    (x, y) => null,
                                                    (p) => Option<TimeSpan>.None());

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

示例9: LongEpochPersistence

        public void LongEpochPersistence(
            [Values(5,60)] double epochDuration, //seconds
            [Values(2)] int nEpochs
            )
        {
            const decimal sampleRate = 10000m;

            const string h5Path = "..\\..\\..\\LongEpochPersistence.h5";
            if (File.Exists(h5Path))
                File.Delete(h5Path);

            Converters.Clear();
            Converters.Register("V", "V",
                // just an identity conversion for now, to pass Validate()
                                (IMeasurement m) => m);
            HekaDAQInputStream.RegisterConverters();
            HekaDAQOutputStream.RegisterConverters();

            Assert.That(HekaDAQController.AvailableControllers().Count(), Is.GreaterThan(0));

            using (var persistor = H5EpochPersistor.Create(h5Path))
            {
                persistor.AddSource("source", null);
            }

            foreach (var daq in HekaDAQController.AvailableControllers())
            {

                try
                {

                    daq.InitHardware();
                    daq.SampleRate = new Measurement(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());

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

                        var nSamples = (int) TimeSpan.FromSeconds(epochDuration).Samples(daq.SampleRate);
                        IList<IMeasurement> stimData = (IList<IMeasurement>) Enumerable.Range(0, nSamples)
                                                                                 .Select(
                                                                                     i =>
                                                                                     new Measurement(
                                                                                         (decimal)
                                                                                         (8*
                                                                                          Math.Sin(((double) i)/
                                                                                                   (nSamples/10.0))),
                                                                                         "V") as IMeasurement)
                                                                                 .ToList();

                        e.Stimuli[dev0] = new RenderedStimulus((string) "RenderedStimulus", (IDictionary<string, object>) new Dictionary<string, object>(),
                                                               (IOutputData) new OutputData(stimData, daq.SampleRate));
                        e.Responses[dev0] = new Response();
                        e.Backgrounds[dev0] = new Background(new Measurement(0, "V"), daq.SampleRate);

                        //Run single epoch
                        using (var persistor = new H5EpochPersistor(h5Path))
                        {
                            var source = persistor.Experiment.Sources.First();

                            persistor.BeginEpochGroup("label", source, DateTimeOffset.Now);
                            persistor.BeginEpochBlock(e.ProtocolID, e.ProtocolParameters, DateTimeOffset.Now);

                            controller.RunEpoch(e, persistor);

                            persistor.EndEpochBlock(DateTimeOffset.Now);
                            persistor.EndEpochGroup();
                        }

                        Assert.That((bool) e.StartTime, Is.True);
                        Assert.That((DateTimeOffset) e.StartTime, Is.LessThanOrEqualTo(controller.Clock.Now));
                        Assert.That(e.Responses[dev0].Duration, Is.EqualTo(((TimeSpan) e.Duration))
                                                                    .Within(TimeSpanExtensions.FromSamples(1,
                                                                                                           daq.
                                                                                                               SampleRate)));
                        //Assert.That(e.Responses[dev1].Duration, Is.EqualTo(((TimeSpan) e.Duration))
                        //                                            .Within(TimeSpanExtensions.FromSamples(1,
                        //                                                                                   daq.
                        //                                                                                       SampleRate)));
                    }
                }
                finally
                {
                    if (File.Exists(h5Path))
                        File.Delete(h5Path);

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

示例10: MaxBandwidth

        public void MaxBandwidth(
            [Values(1000,10000,25000,50000)] decimal sampleRate,
            [Values(1,1,1,1)] int nEpochs,
            [Values(4,4,4,4)] int nOut,
            [Values(8,8,8,4)] int nIn
            )
        {
            Converters.Clear();
            HekaDAQInputStream.RegisterConverters();
            HekaDAQOutputStream.RegisterConverters();

            Assert.That(HekaDAQController.AvailableControllers().Count(), Is.GreaterThan(0));

            foreach (var daq in HekaDAQController.AvailableControllers())
            {

                const double epochDuration = 10; //s

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

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

                    var outDevices = Enumerable.Range(0, nOut)
                        .Select(i =>
                                    {
                                        var dev0 = new UnitConvertingExternalDevice("Device_OUT_" + i, "Manufacturer", controller,
                                                                                    new Measurement(0, "V"))
                                                       {
                                                           MeasurementConversionTarget = "V",
                                                           Clock = daq.Clock,
                                                           OutputSampleRate = daq.SampleRate
                                                       };
                                        dev0.BindStream((IDAQOutputStream)daq.GetStreams("ao" + i).First());

                                        return dev0;
                                    })
                                    .ToList();

                    var inDevices = Enumerable.Range(0, nIn)
                        .Select(i =>
                        {
                            var dev0 = new UnitConvertingExternalDevice("Device_IN_" + i, "Manufacturer", controller,
                                                                        new Measurement(0, "V"))
                            {
                                MeasurementConversionTarget = "V",
                                Clock = daq.Clock,
                                InputSampleRate = daq.SampleRate
                            };
                            dev0.BindStream((IDAQInputStream)daq.GetStreams("ai" + i).First());

                            return dev0;
                        })
                                    .ToList();

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

                        var nSamples = (int)TimeSpan.FromSeconds(epochDuration).Samples(daq.SampleRate);
                        IList<IMeasurement> stimData = Enumerable.Range(0, nSamples)
                                                                   .Select(i => new Measurement((decimal)(8 * Math.Sin(((double)i) / (nSamples / 10.0))), "V") as IMeasurement)
                                                                   .ToList();

                        foreach (var outDev in outDevices)
                        {
                            e.Stimuli[outDev] = new RenderedStimulus((string) "RenderedStimulus", (IDictionary<string, object>) new Dictionary<string, object>(),
                                                        (IOutputData) new OutputData(stimData, daq.SampleRate));

                            e.Backgrounds[outDev] = new Background(new Measurement(0, "V"), daq.SampleRate);
                        }

                        foreach (var inDev in inDevices)
                        {
                            e.Responses[inDev] = new Response();
                        }

                        //Run single epoch
                        var fakeEpochPersistor = new FakeEpochPersistor();

                        controller.RunEpoch(e, fakeEpochPersistor);

                        Assert.That((bool)e.StartTime, Is.True);
                        Assert.That((DateTimeOffset)e.StartTime, Is.LessThanOrEqualTo(controller.Clock.Now));
                        Assert.That(fakeEpochPersistor.PersistedEpochs, Contains.Item(e));

                    }

                }
                finally
                {
                    if (daq.IsHardwareReady)
                        daq.CloseHardware();
                }

            }
        }
开发者ID:Symphony-DAS,项目名称:symphony-core,代码行数:100,代码来源:HekaIntegration.cs

示例11: ShouldPersistCompletedEpochs

        public void ShouldPersistCompletedEpochs()
        {
            Converters.Register("V", "V",
                (IMeasurement m) => m);

            var c = new Controller();
            bool evt = false;

            c.DAQController = new TestDAQController();
            c.Clock = c.DAQController as IClock;
            var persistor = new FakeEpochPersistor();

            c.SavedEpoch += (co, args) =>
                                {
                                    evt = true;
                                };

            var srate = new Measurement(10, "Hz");

            var dev = new UnitConvertingExternalDevice(UNUSED_DEVICE_NAME, UNUSED_DEVICE_MANUFACTURER, c, UNUSED_BACKGROUND)
                          {
                              MeasurementConversionTarget = "V",
                              Clock = c.Clock,
                              OutputSampleRate = srate,
                              InputSampleRate = srate
                          };

            var outStream = new DAQOutputStream("outStream") { MeasurementConversionTarget = "V", Clock = c.Clock };

            var inStream = new DAQInputStream("inStream") { MeasurementConversionTarget = "V", Clock = c.Clock };

            (c.DAQController as IMutableDAQController).AddStream(outStream);
            (c.DAQController as IMutableDAQController).AddStream(inStream);

            outStream.SampleRate = srate;
            inStream.SampleRate = srate;

            dev.BindStream(outStream);
            dev.BindStream(inStream);

            var e = new Epoch(UNUSED_PROTOCOL);
            var samples = new List<IMeasurement> { new Measurement(1.0m, "V"), new Measurement(1.0m, "V"), new Measurement(1.0m, "V") };
            var data = new OutputData(samples,
                srate,
                true);

            e.Stimuli[dev] = new RenderedStimulus((string) "stimID",
                                                  (IDictionary<string, object>) new Dictionary<string, object>(),
                                                  (IOutputData) data);
            e.Responses[dev] = new Response();
            e.Backgrounds[dev] = new Background(new Measurement(0, "V"), srate);

            ((TestDAQController)c.DAQController).AddStreamMapping(outStream, inStream);

            c.RunEpoch(e, persistor);

            Assert.That(evt, Is.True.After(10*1000,100));
            Assert.That(persistor.PersistedEpochs, Has.Member(e));
        }
开发者ID:Symphony-DAS,项目名称:symphony-core,代码行数:59,代码来源:ControllerTests.cs

示例12: 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

示例13: RunEpochThrowsGivenIndefiniteEpochWithResponses

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

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

            var e = new Epoch(UNUSED_PROTOCOL);
            var dev2 = new UnitConvertingExternalDevice("dev2", "co", c, new Measurement(0, "V"))
            {
                MeasurementConversionTarget = "V",
                Clock = c.Clock
            };

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

            e.Stimuli[dev2] = new DelegatedStimulus("ID2", "units", new Measurement(10, "Hz"),
                                                    new Dictionary<string, object>(),
                                                    (x, y) => null,
                                                    (p) => Option<TimeSpan>.None());
            e.Responses[dev2] = new Response();

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

示例14: ShouldNotPersistEpochGivenNullPersistor

        public void ShouldNotPersistEpochGivenNullPersistor()
        {
            var c = new Controller();
            bool evt = false;

            c.DAQController = new TestDAQController();
            c.Clock = c.DAQController as IClock;

            c.DiscardedEpoch += (co, args) => Assert.Fail("Run failed");

            var dev = new UnitConvertingExternalDevice(UNUSED_DEVICE_NAME, UNUSED_DEVICE_MANUFACTURER, UNUSED_BACKGROUND)
            {
                Controller = c,
                MeasurementConversionTarget = "V"
            };

            var outStream = new DAQOutputStream("outStream") { MeasurementConversionTarget = "V" };

            var inStream = new DAQInputStream("inStream") { MeasurementConversionTarget = "V" };

            (c.DAQController as IMutableDAQController).AddStream(outStream);
            (c.DAQController as IMutableDAQController).AddStream(inStream);

            var srate = new Measurement(10, "Hz");
            outStream.SampleRate = srate;
            inStream.SampleRate = srate;

            dev.BindStream(outStream);
            dev.BindStream(inStream);

            var e = new Epoch(UNUSED_PROTOCOL);
            var samples = new List<IMeasurement> { new Measurement(1.0m, "V"), new Measurement(1.0m, "V"), new Measurement(1.0m, "V") };
            var data = new OutputData(samples,
                srate,
                true);

            e.Stimuli[dev] = new RenderedStimulus((string) "stimID",
                                                  (IDictionary<string, object>) new Dictionary<string, object>(),
                                                  (IOutputData) data);
            e.Responses[dev] = new Response();
            e.Background[dev] = new Epoch.EpochBackground(new Measurement(0, "V"), srate);

            ((TestDAQController)c.DAQController).AddStreamMapping(outStream, inStream);

            c.RunEpoch(e, null);

            Assert.Pass();
        }
开发者ID:physion,项目名称:symphony-core,代码行数:48,代码来源:ControllerTests.cs

示例15: SealLeak

        public void SealLeak(
            [Values(10000, 20000, 50000)] double sampleRate
            )
        {
            Converters.Clear();
            Converters.Register("V", "V",
                // just an identity conversion for now, to pass Validate()
                                (IMeasurement m) => m);
            HekaDAQInputStream.RegisterConverters();
            HekaDAQOutputStream.RegisterConverters();

            Assert.That(HekaDAQController.AvailableControllers().Count(), Is.GreaterThan(0));

            foreach (var daq in HekaDAQController.AvailableControllers())
            {
                const double epochDuration = 10; //s

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

                    var controller = new Controller();
                    controller.Clock = daq.Clock;
                    controller.DAQController = daq;

                    const decimal expectedBackgroundVoltage = 3.2m;
                    var expectedBackground = new Measurement(expectedBackgroundVoltage, "V");
                    var dev0 = new UnitConvertingExternalDevice("Device0", "Manufacturer", controller, expectedBackground)
                                   {
                                       MeasurementConversionTarget = "V",
                                       Clock = daq.Clock,
                                       OutputSampleRate = daq.SampleRate,
                                       InputSampleRate = daq.SampleRate
                                   };
                    dev0.BindStream(daq.GetStreams("ao0").First() as IDAQOutputStream);
                    dev0.BindStream(daq.GetStreams("ai0").First() as IDAQInputStream);

                    controller.DiscardedEpoch += (c, args) => Console.WriteLine("Discarded epoch: " + args.Epoch);

                    // Setup Epoch
                    var e = new Epoch("HekaIntegration");

                    HekaDAQController cDAQ = daq;
                    var stim = new DelegatedStimulus("TEST_ID", "V", cDAQ.SampleRate, new Dictionary<string, object>(),
                                                     (parameters, duration) =>
                                                     DataForDuration(duration, cDAQ.SampleRate),
                                                     parameters => Option<TimeSpan>.None()
                        );

                    e.Stimuli[dev0] = stim;
                    e.Backgrounds[dev0] = new Background(expectedBackground, daq.SampleRate);

                    //Run single epoch
                    var fakeEpochPersistor = new FakeEpochPersistor();

                    new TaskFactory().StartNew(() =>
                                                   {
                                                       Thread.Sleep(TimeSpan.FromSeconds(epochDuration));
                                                       controller.RequestStop();
                                                   },
                                               TaskCreationOptions.LongRunning
                        );

                    controller.RunEpoch(e, fakeEpochPersistor);
                }
                finally
                {
                    if (daq.IsHardwareReady)
                        daq.CloseHardware();
                }
            }
        }
开发者ID:Symphony-DAS,项目名称:symphony-core,代码行数:74,代码来源:HekaIntegration.cs


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