public void ExternalDeviceStreams()
        {
            var ed = new UnitConvertingExternalDevice("TestDevice", UNUSED_DEVICE_MANUFACTURER, UNUSED_BACKGROUND);

            DAQInputStream  in0  = new DAQInputStream("In-0");
            DAQOutputStream out0 = new DAQOutputStream("Out-0");

            ed.BindStream(in0).BindStream(out0);

            Assert.IsTrue(ed.Streams.ContainsKey(in0.Name));
            Assert.IsTrue(in0.Devices.Contains(ed));
            Assert.IsTrue(ed.Streams.ContainsKey(out0.Name));
            Assert.IsTrue(out0.Device == ed);

            ed.UnbindStream("In-0");
            Assert.IsFalse(ed.Streams.ContainsKey(in0.Name));
            Assert.IsFalse(in0.Devices.Contains(ed));
            Assert.IsTrue(ed.Streams.ContainsKey(out0.Name));
            Assert.IsTrue(out0.Device == ed);

            ed.UnbindStream("Out-0");
            Assert.IsFalse(ed.Streams.ContainsKey(in0.Name));
            Assert.IsFalse(in0.Devices.Contains(ed));
            Assert.IsFalse(ed.Streams.ContainsKey(out0.Name));
            Assert.IsFalse(out0.Device == ed);
        }
        public void InactiveStreamDoesNotHaveMoreData()
        {
            DAQOutputStream s = new DAQOutputStream("OUT");

            Assert.False(s.Active);
            Assert.False(s.HasMoreData);
        }
        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();
        }
        public void ShouldSurfaceExceptionInPersistorTask()
        {
            var  c   = new Controller();
            bool evt = false;

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

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

            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);

            Assert.That(() => c.RunEpoch(e, persistor), Throws.TypeOf <SymphonyControllerException>());
        }
        public void OutputPipelineContinuity(
            [Values(1000, 5000, 10000, 15000, 20000)] double sampleRate,
            [Values(0.1, 0.5, 1, 5)] double blockDurationSeconds
            )
        {
            const double epochDuration = 2; //seconds
            var srate = new Measurement((decimal) sampleRate, "Hz");

            var daq = new TestDAQController();
            var outStream = new DAQOutputStream("OUT")
                                {
                                    SampleRate = srate,
                                    MeasurementConversionTarget = "V"
                                };
            var inStream = new DAQInputStream("IN")
                                {
                                    SampleRate = srate,
                                    MeasurementConversionTarget = "V"
                                };

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

            var dev = new UnitConvertingExternalDevice("dev", "co", controller, new Measurement(0, "V"))
                          {
                              Clock = daq,
                              MeasurementConversionTarget = "V",
                              OutputSampleRate = srate,
                              InputSampleRate = srate
                          };
            dev.BindStream(outStream).BindStream(inStream);

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

            var nSamples = (int)TimeSpan.FromSeconds(epochDuration).Samples(srate);
            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();
            IOutputData stimOutputData = new OutputData(stimData, srate);

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

            controller.EnqueueEpoch(e);

            var blockSpan = TimeSpan.FromSeconds(blockDurationSeconds);
            foreach (var stimBlock in stim.DataBlocks(blockSpan))
            {
                var cons = stimOutputData.SplitData(blockSpan);
                var expected = cons.Head.Data;
                stimOutputData = cons.Rest;

                Assert.That(stimBlock.Data, Is.EqualTo(expected));
            }
        }
        public void ShouldNotSetBackgroundWhenStreamDoesNotUseThisController()
        {
            var c = new SimpleDAQController(new IDAQStream[0])
            {
                BackgroundSet = false
            };
            var s = new DAQOutputStream("test", null);

            Assert.That(() => c.ApplyStreamBackground(s), Throws.Exception.TypeOf <DAQException>());
        }
        public void FiresStimulusOutputEvents()
        {
            var c         = new TestDAQController();
            var srate     = new Measurement(10, "Hz");
            var outStream = new DAQOutputStream("out")
            {
                MeasurementConversionTarget = "V",
                SampleRate = srate
            };
            var inStream = new DAQInputStream("in")
            {
                MeasurementConversionTarget = "V",
                SampleRate = srate
            };

            var outputData   = new Dictionary <IDAQOutputStream, Queue <IOutputData> >();
            var dataQueue    = new Queue <IOutputData>();
            var outputIOData = new OutputData(
                Enumerable.Range(0, 100).Select(i => new Measurement(i, "V")),
                new Measurement(10, "Hz")
                );

            dataQueue.Enqueue(outputIOData);

            outputData[outStream] = dataQueue;

            var dev = new TestDevice("test", outputData)
            {
                MeasurementConversionTarget = "V"
            };

            dev.BindStream(outStream);

            bool fired = false;

            c.StimulusOutput += (daq, args) =>
            {
                Assert.That(args.Stream == outStream);
                Assert.That(args.Data != null);
                Assert.That(args.Data.Configuration.Count() > 0);
                fired = true;
            };
            c.ProcessIteration += (daq, args) => ((IDAQController)daq).RequestStop();

            c.AddStreamMapping(outStream, inStream);

            c.Start(false);

            while (c.Running)
            {
                ;
            }

            Assert.That(fired, Is.True.After(1000, 10));
        }
        public void OutputStreamShouldApplyBackground()
        {
            var controller = new DynamicMock(typeof(IDAQController));
            var s          = new DAQOutputStream("test", controller.MockInstance as IDAQController);

            controller.Expect("ApplyStreamBackground", s);

            s.ApplyBackground();

            controller.Verify();
        }
Esempio n. 9
0
        public void ShouldRaiseExceptionIfPullingLessThanOneSample()
        {
            var e      = new UnitConvertingExternalDevice(UNUSED_NAME, null, new Measurement(0, "V"));
            var stream = new DAQOutputStream(UNUSED_NAME);

            e.BindStream(stream);

            stream.SampleRate = new Measurement(1, "Hz");

            Assert.Throws <ExternalDeviceException>(() => e.PullOutputData(stream, TimeSpan.FromMilliseconds(0.1)));
        }
Esempio n. 10
0
        public void OutputPipelineContinuity(
            [Values(1000, 5000, 10000, 15000, 20000)] double sampleRate,
            [Values(0.1, 0.5, 1, 5)] double blockDurationSeconds
            )
        {

            const double epochDuration = 2; //seconds
            var srate = new Measurement((decimal) sampleRate, "Hz");

            var daq = new TestDAQController();
            var outStream = new DAQOutputStream("OUT")
                                {
                                    SampleRate = srate,
                                    MeasurementConversionTarget = "V"
                                };

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

            var dev = new UnitConvertingExternalDevice("dev", "co", controller, new Measurement(0, "V"))
                          {
                              Clock = daq,
                              MeasurementConversionTarget = "V"
                          };
            dev.BindStream(outStream);

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

            var nSamples = (int)TimeSpan.FromSeconds(epochDuration).Samples(srate);
            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();
            IOutputData stimOutputData = new OutputData(stimData, srate);

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

            controller.EnqueueEpoch(e);
            controller.NextEpoch();

            var blockSpan = TimeSpan.FromSeconds(blockDurationSeconds);
            foreach (var stimBlock in stim.DataBlocks(blockSpan))
            {
                var cons = stimOutputData.SplitData(blockSpan);
                var expected = cons.Head.Data;
                stimOutputData = cons.Rest;

                Assert.That(stimBlock.Data, Is.EqualTo(expected));
            }

        }
        public void FiresStimulusOutputEvents()
        {
            var c = new TestDAQController();
            var srate = new Measurement(10, "Hz");
            var outStream = new DAQOutputStream("out")
                                {
                                    MeasurementConversionTarget = "V",
                                    SampleRate = srate
                                };
            var inStream = new DAQInputStream("in")
                               {
                                   MeasurementConversionTarget = "V",
                                   SampleRate = srate
                               };

            var outputData = new Dictionary<IDAQOutputStream, Queue<IOutputData>>();
            var dataQueue = new Queue<IOutputData>();
            var outputIOData = new OutputData(
                Enumerable.Range(0, 100).Select(i => new Measurement(i, "V")),
                new Measurement(10, "Hz")
                );

            dataQueue.Enqueue(outputIOData);

            outputData[outStream] = dataQueue;

            var dev = new TestDevice("test", outputData) { MeasurementConversionTarget = "V" };

            dev.BindStream(outStream);

            bool fired = false;
            c.StimulusOutput += (daq, args) =>
                                    {
                                        Assert.That(args.Stream == outStream);
                                        Assert.That(args.Data != null);
                                        Assert.That(args.Data.Configuration.Count() > 0);
                                        fired = true;

                                        ((IDAQController) daq).RequestStop();
                                    };

            c.AddStreamMapping(outStream, inStream);

            c.Start(false);

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

            Assert.That(fired, Is.True);
        }
Esempio n. 12
0
        public void BackgroundProxiesExternalDevice()
        {
            var background = new Measurement(1.3m, "units");
            var dev = new UnitConvertingExternalDevice(UNUSED_NAME, UNUSED_DEVICE_MANUFACTURER, background)
                          {
                              MeasurementConversionTarget = "units"
                          };

            var stream = new DAQOutputStream(UNUSED_NAME);
            stream.Device = dev;

            Assert.AreEqual(background.QuantityInBaseUnit, stream.Background.QuantityInBaseUnit);
        }
Esempio n. 13
0
        public void StreamSetSampleRate()
        {
            DAQInputStream s1       = new DAQInputStream("");
            Measurement    expected = new Measurement(10, "Hz");

            s1.SampleRate = expected;
            Assert.AreEqual(expected, s1.SampleRate);

            DAQOutputStream s2 = new DAQOutputStream("");

            s2.SampleRate = expected;

            Assert.AreEqual(expected, s2.SampleRate);
        }
Esempio n. 14
0
        public void BackgroundProxiesExternalDevice()
        {
            var background = new Measurement(1.3m, "units");
            var dev        = new UnitConvertingExternalDevice(UNUSED_NAME, UNUSED_DEVICE_MANUFACTURER, background)
            {
                MeasurementConversionTarget = "units"
            };

            var stream = new DAQOutputStream(UNUSED_NAME);

            stream.Device = dev;

            Assert.AreEqual(background.QuantityInBaseUnit, stream.Background.QuantityInBaseUnit);
        }
        public void GetStreamReturnsNullForUnknownName()
        {
            var c = new SimpleDAQController();

            const string name       = "stream-name";
            const string distractor = "distractor-name";
            var          outStream  = new DAQOutputStream(name);

            (c as IMutableDAQController).AddStream(outStream);

            Assert.That(c.GetStream <IDAQOutputStream>(distractor), Is.Null);
            Assert.That(c.GetStream <IDAQInputStream>(distractor), Is.Null);
            Assert.That(c.GetStream <IDAQInputStream>(name), Is.Null);
        }
        public void GetStreamReturnsStreamWithName()
        {
            var c = new SimpleDAQController();

            const string name      = "stream-name";
            var          outStream = new DAQOutputStream(name);

            (c as IMutableDAQController).AddStream(outStream);
            var inputStream = new DAQInputStream(name);

            (c as IMutableDAQController).AddStream(inputStream);

            Assert.That(c.GetStream <IDAQOutputStream>(name), Is.EqualTo(outStream));
            Assert.That(c.GetStream <IDAQInputStream>(name), Is.EqualTo(inputStream));
        }
Esempio n. 17
0
        public void OutputStreamShouldPropagateOutputConfiguration()
        {
            var s      = new DAQOutputStream("test");
            var device = new DynamicMock(typeof(IExternalDevice));

            DateTimeOffset time   = DateTime.Now;
            var            config = new List <IPipelineNodeConfiguration>();

            device.Expect("DidOutputData", new object[] { s, time, TimeSpan.FromSeconds(0.1), config });

            s.Device = device.MockInstance as IExternalDevice;

            s.DidOutputData(time, TimeSpan.FromSeconds(0.1), config);

            device.Verify();
        }
        public void ShouldConvertBackgroundValue()
        {
            var bg = new Measurement(7.5, "units");

            var d = new CalibratedDevice(UNUSED_NAME, null, bg, LUT)
                {
                    MeasurementConversionTarget = "units"
                };

            var stream = new DAQOutputStream(UNUSED_NAME);
            d.BindStream(stream);

            var expected = new Measurement(150, bg.Exponent, bg.BaseUnits);

            Assert.That(d.OutputBackground, Is.EqualTo(expected));
        }
Esempio n. 19
0
        private static void OrderedFakeInputData(out IInputData d1, out IInputData d2)
        {
            Random random = new Random();
            IList <IMeasurement>         data   = (IList <IMeasurement>)Enumerable.Repeat(0, 100).Select(i => random.Next()).Select(v => new Measurement(v, "V") as IMeasurement).ToList();;//generate random data
            IMeasurement                 srate  = new Measurement(1000, "Hz");
            DateTimeOffset               time1  = DateTimeOffset.Now;
            IDictionary <string, object> config = new Dictionary <string, object>();
            var dev    = new UnitConvertingExternalDevice("DevName", "DevManufacturer", new Measurement(0, "V"));
            var stream = new DAQOutputStream("StreamName");

            d1 = new InputData(data, srate, time1)
                 .DataWithExternalDeviceConfiguration(dev, config)
                 .DataWithStreamConfiguration(stream, config);

            DateTimeOffset time2 = time1.AddSeconds((double)(data.Count / srate.Quantity));

            d2 = new InputData(data, srate, time2)
                 .DataWithExternalDeviceConfiguration(dev, config)
                 .DataWithStreamConfiguration(stream, config);
        }
Esempio n. 20
0
        public void ShouldConvertBackgoundUnits()
        {
            Converters.Register("xfromUnits", "toUnits", m => new Measurement(2 * m.Quantity, m.Exponent, m.BaseUnit));

            var bg = new Measurement(1, "xfromUnits");
            var e = new UnitConvertingExternalDevice(UNUSED_NAME,
                                                     null,
                                                     bg)
                        {
                            MeasurementConversionTarget = "toUnits"
                        };

            var stream = new DAQOutputStream(UNUSED_NAME);
            e.BindStream(stream);

            var expected = new Measurement(bg.Quantity * 2,
                                           bg.Exponent,
                                           bg.BaseUnit);

            Assert.That(e.OutputBackground, Is.EqualTo(expected));
        }
Esempio n. 21
0
        private static void OutputStreamFixture(out IList <IOutputData> data, out DAQOutputStream s, int numData)
        {
            data = new List <IOutputData>(3);

            var measurements = new List <IMeasurement>(2)
            {
                new Measurement(1, "V"), new Measurement(2, "V")
            };

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

            for (int i = 0; i < numData; i++)
            {
                bool last = i == numData - 1 ? true : false;

                IOutputData outputData = new OutputData(measurements,
                                                        sampleRate,
                                                        last);
                data.Add(outputData);
            }


            s = new DAQOutputStream("OUT")
            {
                MeasurementConversionTarget = measurements.First().BaseUnit,
                SampleRate = sampleRate
            };

            var outData = new Dictionary <IDAQOutputStream, Queue <IOutputData> >(1);

            outData[s] = new Queue <IOutputData>(data);

            var outDevice = new TestDevice("OUT-DEVICE", outData)
            {
                Controller = new Controller(),
                MeasurementConversionTarget = "V"
            };

            s.Device = outDevice;
        }
Esempio n. 22
0
        public void ShouldConvertBackgoundUnits()
        {
            Converters.Register("xfromUnits", "toUnits", m => new Measurement(2 * m.Quantity, m.Exponent, m.BaseUnit));

            var bg = new Measurement(1, "xfromUnits");
            var e  = new UnitConvertingExternalDevice(UNUSED_NAME,
                                                      null,
                                                      bg)
            {
                MeasurementConversionTarget = "toUnits"
            };

            var stream = new DAQOutputStream(UNUSED_NAME);

            e.BindStream(stream);

            var expected = new Measurement(bg.Quantity * 2,
                                           bg.Exponent,
                                           bg.BaseUnit);

            Assert.That(e.OutputBackground, Is.EqualTo(expected));
        }
        public void ShouldSetStreamBackgroundWhenStopped()
        {
            var c = new SimpleDAQController(new IDAQStream[0])
            {
                BackgroundSet = false, AsyncBackground = null
            };
            var s = new DAQOutputStream("test", c);

            c.AddStream(s);
            c.SetRunning(false);

            var device     = new DynamicMock(typeof(IExternalDevice));
            var background = new Measurement(0, "V");

            device.ExpectAndReturn("get_OutputBackground", background);

            s.MeasurementConversionTarget = "V";
            s.Device = device.MockInstance as IExternalDevice;

            s.ApplyBackground();

            Assert.That(c.AsyncBackground, Is.EqualTo(background));
        }
Esempio n. 24
0
        public void ThrowsIfDeviceOutputDataSampleRateMismatch()
        {
            IList <IOutputData> data = new List <IOutputData>(3);

            List <IMeasurement> measurements = new List <IMeasurement>(2);

            measurements.Add(new Measurement(1, "V"));
            measurements.Add(new Measurement(2, "V"));

            IMeasurement sampleRate = new Measurement(1000, "Hz");

            data.Add(new OutputData(measurements,
                                    sampleRate, false));
            data.Add(new OutputData(measurements,
                                    sampleRate, false));

            data.Add(new OutputData(measurements,
                                    sampleRate, false));


            DAQOutputStream s = new DAQOutputStream("OUT");

            s.MeasurementConversionTarget = measurements.First().BaseUnit;

            s.SampleRate = new Measurement(sampleRate.QuantityInBaseUnit * 2, "Hz");

            var outData = new Dictionary <IDAQOutputStream, Queue <IOutputData> >(1);

            outData[s] = new Queue <IOutputData>(data);

            TestDevice outDevice = new TestDevice("OUT-DEVICE", outData);

            outDevice.Controller = new Controller();
            s.Device             = outDevice;

            s.PullOutputData(new TimeSpan(100));
        }
        public void GetsStreamsByName()
        {
            string name1 = "IN1";
            string name2 = "IN2";
            string name3 = "OUT1";

            IDAQStream in1  = new DAQInputStream(name1);
            IDAQStream in2  = new DAQInputStream(name2);
            IDAQStream in3  = new DAQInputStream(name1);
            IDAQStream out1 = new DAQOutputStream(name3);
            var        c    = new SimpleDAQController();

            (c as IMutableDAQController).AddStream(in1);
            (c as IMutableDAQController).AddStream(in2);
            (c as IMutableDAQController).AddStream(in3);
            (c as IMutableDAQController).AddStream(out1);

            Assert.AreEqual(2, c.GetStreams(name1).Count());
            Assert.AreEqual(1, c.GetStreams(name2).Count());
            Assert.AreEqual(1, c.GetStreams(name3).Count());

            Assert.AreEqual(in2, c.GetStreams(name2).First());
            Assert.AreEqual(out1, c.GetStreams(name3).First());
        }
        public void GetStreamReturnsNullForUnknownName()
        {
            var c = new SimpleDAQController();

            const string name = "stream-name";
            const string distractor = "distractor-name";
            var outStream = new DAQOutputStream(name);
            (c as IMutableDAQController).AddStream(outStream);

            Assert.That(c.GetStream<IDAQOutputStream>(distractor), Is.Null);
            Assert.That(c.GetStream<IDAQInputStream>(distractor), Is.Null);
            Assert.That(c.GetStream<IDAQInputStream>(name), Is.Null);
        }
        public void ShouldNotApplyBackgroundToRunningStreams()
        {
            const string units = "V";
            const MultiClampInterop.OperatingMode vclampMode = MultiClampInterop.OperatingMode.VClamp;
            const MultiClampInterop.OperatingMode iclampMode = MultiClampInterop.OperatingMode.IClamp;

            var c = new Controller();
            var mc = new FakeMulticlampCommander();

            var vclampBackground = new Measurement(2, -3, units);

            var background = new Dictionary<MultiClampInterop.OperatingMode, IMeasurement>()
                                 {
                                     { vclampMode, vclampBackground }
                                 };

            var dataVClamp = new MultiClampInterop.MulticlampData()
            {
                OperatingMode = vclampMode,
                ExternalCommandSensitivity = 2.5,
                ExternalCommandSensitivityUnits = MultiClampInterop.ExternalCommandSensitivityUnits.V_V
            };

            var daq = new DynamicMock(typeof(IDAQController));
            var s = new DAQOutputStream("test", daq.MockInstance as IDAQController);

            var mcd = new MultiClampDevice(mc, c, background);
            mcd.BindStream(s);

            daq.ExpectAndReturn("get_Running", true);
            daq.ExpectNoCall("ApplyStreamBackground");

            mc.FireParametersChanged(DateTimeOffset.Now, dataVClamp);

            daq.Verify();
        }
Esempio n. 28
0
        public void OutputStreamSetSampleRateNegativeRate()
        {
            DAQOutputStream s = new DAQOutputStream("");

            s.SampleRate = new Measurement(-1, "Hz");
        }
Esempio n. 29
0
        public void PullWithoutDevice()
        {
            DAQOutputStream s = new DAQOutputStream("OUT");

            s.PullOutputData(new TimeSpan(1));
        }
        public void ShouldSetStreamBackgroundWhenStopped()
        {
            var c = new SimpleDAQController(new IDAQStream[0]) { BackgroundSet = false, AsyncBackground = null};
            var s = new DAQOutputStream("test", c);
            c.AddStream(s);
            c.SetRunning(false);

            var device = Substitute.For<IExternalDevice>();
            var background = new Measurement(0, "V");
            device.OutputBackground.Returns(background);

            s.MeasurementConversionTarget = "V";
            s.Devices.Add(device);

            s.ApplyBackground();

            var temp = device.Received().OutputBackground;

            Assert.That(c.AsyncBackground, Is.EqualTo(background));
        }
Esempio n. 31
0
        public void StreamSetSampleRate()
        {
            DAQInputStream s1 = new DAQInputStream("");
            Measurement expected = new Measurement(10, "Hz");

            s1.SampleRate = expected;
            Assert.AreEqual(expected, s1.SampleRate);

            DAQOutputStream s2 = new DAQOutputStream("");
            s2.SampleRate = expected;

            Assert.AreEqual(expected, s2.SampleRate);
        }
        public void ShouldRaiseExceptionIfPullingLessThanOneSample()
        {
            var e = new UnitConvertingExternalDevice(UNUSED_NAME, null, new Measurement(0, "V"));
            var stream = new DAQOutputStream(UNUSED_NAME);
            e.BindStream(stream);

            stream.SampleRate = new Measurement(1, "Hz");

            Assert.Throws<ExternalDeviceException>(() => e.PullOutputData(stream, TimeSpan.FromMilliseconds(0.1)));
        }
        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));
        }
Esempio n. 34
0
        private static void OrderedFakeInputData(out IInputData d1, out IInputData d2)
        {
            Random random = new Random();
            IList<IMeasurement> data = (IList<IMeasurement>) Enumerable.Repeat(0, 100).Select(i => random.Next()).Select(v => new Measurement(v, "V") as IMeasurement).ToList(); ;//generate random data
            IMeasurement srate = new Measurement(1000, "Hz");
            DateTimeOffset time1 = DateTimeOffset.Now;
            IDictionary<string, object> config = new Dictionary<string, object>();
            var dev = new UnitConvertingExternalDevice("DevName", "DevManufacturer", new Measurement(0, "V"));
            var stream = new DAQOutputStream("StreamName");

            d1 = new InputData(data, srate, time1)
                .DataWithExternalDeviceConfiguration(dev, config)
                .DataWithStreamConfiguration(stream, config);

            DateTimeOffset time2 = time1.AddSeconds((double) (data.Count / srate.Quantity));
            d2 = new InputData(data, srate, time2)
                .DataWithExternalDeviceConfiguration(dev, config)
                .DataWithStreamConfiguration(stream, config);
        }
        public void ShouldTruncateResponseAtEpochBoundary()
        {
            Converters.Register("V", "V",
                (IMeasurement m) => m);

            var daq = new SimpleDAQController();
            var c = new NonValidatingController { DAQController = daq };
            var dev = new UnitConvertingExternalDevice("dev", UNUSED_DEVICE_MANUFACTURER, c, UNUSED_BACKGROUND);
            var outStream = new DAQOutputStream("out");
            var inStream = new DAQInputStream("in");
            dev.BindStream(outStream).BindStream(inStream);

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

            var samples = new List<IMeasurement> { new Measurement(1, "V"), new Measurement(2, "V"), new Measurement(3, "V") };

            var data = new OutputData(samples,
                                      sampleRate, true);

            var e = new Epoch(UNUSED_PROTOCOL);

            e.Stimuli[dev] = new RenderedStimulus((string) "ID1",
                                                   (IDictionary<string, object>) new Dictionary<string, object>(),
                                                   (IOutputData) data);
            e.Responses[dev] = new Response();

            bool pushed = false;
            daq.Started += (evt, args) =>
            {
                c.PullOutputData(dev, data.Duration);
                c.PushInputData(dev, new InputData(samples.Concat(samples).ToList(),
                                                   sampleRate,
                                                   DateTimeOffset.Now)
                                         .DataWithStreamConfiguration(streamFake, new Dictionary<string, object>())
                                         .DataWithExternalDeviceConfiguration(devFake, new Dictionary<string, object>()));
                pushed = true;

                c.RequestStop();
            };

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

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

            Assert.That(((TimeSpan)e.Responses[dev].Duration), Is.EqualTo((TimeSpan)e.Duration));
        }
Esempio n. 36
0
        public void ShouldSurfaceExceptionInPersistorTask()
        {
            var c = new Controller();
            bool evt = false;

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

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

            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);

            Assert.That(() => c.RunEpoch(e, persistor), Throws.TypeOf<SymphonyControllerException>());
        }
Esempio n. 37
0
        public void OutputStreamShouldApplyBackground()
        {
            var controller = new DynamicMock(typeof (IDAQController));
            var s = new DAQOutputStream("test", controller.MockInstance as IDAQController);

            controller.Expect("ApplyStreamBackground", s);

            s.ApplyBackground();

            controller.Verify();
        }
        public void CreatePipeline()
        {
            // Based on the "Minimal Rig.pdf" in the docs folder
            Converters.Clear();

            // We need an IClock
            IClock clock = new FakeClock();

            // We need a controller ...
            Controller con = new Controller();

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

            con.Clock = clock;

            // Three ExternalDevices
            CoalescingDevice amp = new CoalescingDevice("Amp", UNUSED_DEVICE_MANUFACTURER, con, UNUSED_BACKGROUND)
            {
                MeasurementConversionTarget = "units"
            };
            var LED = new UnitConvertingExternalDevice("LED", UNUSED_DEVICE_MANUFACTURER, UNUSED_BACKGROUND)
            {
                MeasurementConversionTarget = "units"
            };
            var temp = new UnitConvertingExternalDevice("Temp", UNUSED_DEVICE_MANUFACTURER, UNUSED_BACKGROUND)
            {
                MeasurementConversionTarget = "units"
            };

            amp.Clock  = clock;
            LED.Clock  = clock;
            temp.Clock = clock;
            con.AddDevice(LED).AddDevice(temp);
            // There should be no difference whether we use the
            // ExternalDevice constructor to wire up the Controller
            // to the ExternalDevice, or the explicit Add() call


            Assert.IsNotNull(amp.Controller);
            Assert.IsNotNull(LED.Controller);
            Assert.IsNotNull(temp.Controller);

            Assert.IsTrue(amp.Controller == con);
            Assert.IsTrue(LED.Controller == con);
            Assert.IsTrue(temp.Controller == con);

            // Five DAQStreams
            DAQInputStream  in0  = new DAQInputStream("In-0"); in0.Clock = clock;
            DAQInputStream  in1  = new DAQInputStream("In-1"); in1.Clock = clock;
            DAQInputStream  in2  = new DAQInputStream("In-2"); in2.Clock = clock;
            DAQOutputStream out0 = new DAQOutputStream("Out-0"); out0.Clock = clock;
            DAQOutputStream out1 = new DAQOutputStream("Out-1"); out1.Clock = clock;

            in0.MeasurementConversionTarget  = "units";
            in1.MeasurementConversionTarget  = "units";
            in2.MeasurementConversionTarget  = "units";
            out0.MeasurementConversionTarget = "units";
            out1.MeasurementConversionTarget = "units";

            //amp.Coalesce = CoalescingDevice.OneItemCoalesce;
            amp.Configuration["CoalesceProc"] = "Symphony.Core.CoalescingDevice.OneItemCoalesce";

            LED.BindStream(out0);
            amp.BindStream(out1).BindStream(in0).BindStream(in1);
            amp.Connect(in0, in1);
            temp.BindStream(in2);

            Assert.IsTrue(LED.Streams.Count == 1);
            Assert.IsTrue(amp.Streams.Count == 3);
            Assert.IsTrue(temp.Streams.Count == 1);

            Assert.IsTrue(in0.Devices.Contains(amp));
            Assert.IsTrue(in1.Devices.Contains(amp));
            Assert.IsTrue(in2.Devices.Contains(temp));
            Assert.IsTrue(out0.Device == LED);
            Assert.IsTrue(out1.Device == amp);

            // One DAQController
            IDAQController dc =
                new SimpleDAQController(new IDAQStream[] { in0, in1, in2, out0, out1 });

            con.DAQController = dc;

            // DAQController-to-streams
            Assert.IsTrue(dc.InputStreams.Contains(in0));
            Assert.IsTrue(dc.InputStreams.Contains(in1));
            Assert.IsTrue(dc.InputStreams.Contains(in2));
            Assert.IsTrue(dc.OutputStreams.Contains(out0));
            Assert.IsTrue(dc.OutputStreams.Contains(out0));

            // Validate and report the validation results
            Maybe <string> conVal = con.Validate();

            Assert.IsTrue(conVal, conVal.Item2);

            Assert.IsTrue(amp.Coalesce == CoalescingDevice.OneItemCoalesce);
        }
        public void GetStreamReturnsStreamWithName()
        {
            var c = new SimpleDAQController();

            const string name = "stream-name";
            var outStream = new DAQOutputStream(name);
            (c as IMutableDAQController).AddStream(outStream);
            var inputStream = new DAQInputStream(name);
            (c as IMutableDAQController).AddStream(inputStream);

            Assert.That(c.GetStream<IDAQOutputStream>(name), Is.EqualTo(outStream));
            Assert.That(c.GetStream<IDAQInputStream>(name), Is.EqualTo(inputStream));
        }
        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>());
        }
        public void ShouldNotSetBackgroundWhenStreamDoesNotUseThisController()
        {
            var c = new SimpleDAQController(new IDAQStream[0]) { BackgroundSet = false };
            var s = new DAQOutputStream("test", null);

            Assert.That(()=> c.ApplyStreamBackground(s), Throws.Exception.TypeOf<DAQException>());
        }
        public void RunEpochShouldDiscardEpochWhenRequestStopCalled()
        {
            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 sampleRate = new Measurement(1, "Hz");

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

            e.Stimuli[dev1] = new DelegatedStimulus("ID1", "units", sampleRate, 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.RequestStop();
                                       };

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

            Assert.True(epochDiscarded);
        }
Esempio n. 43
0
        public void ThrowsIfDeviceOutputDataSampleRateMismatch()
        {
            IList<IOutputData> data = new List<IOutputData>(3);

            List<IMeasurement> measurements = new List<IMeasurement>(2);
            measurements.Add(new Measurement(1, "V"));
            measurements.Add(new Measurement(2, "V"));

            IMeasurement sampleRate = new Measurement(1000, "Hz");
            data.Add(new OutputData(measurements,
                sampleRate, false));
            data.Add(new OutputData(measurements,
                sampleRate, false));

            data.Add(new OutputData(measurements,
                sampleRate, false));

            DAQOutputStream s = new DAQOutputStream("OUT");
            s.MeasurementConversionTarget = measurements.First().BaseUnit;

            s.SampleRate = new Measurement(sampleRate.QuantityInBaseUnit * 2, "Hz");

            var outData = new Dictionary<IDAQOutputStream, Queue<IOutputData>>(1);
            outData[s] = new Queue<IOutputData>(data);

            TestDevice outDevice = new TestDevice("OUT-DEVICE", outData);
            outDevice.Controller = new Controller();
            s.Device = outDevice;

            s.PullOutputData(new TimeSpan(100));
        }
        public void PushesDataToEpoch()
        {
            const string UNUSED_NAME = "UNUSED";

            var daq = new SimpleDAQController();
            var c = new NonValidatingController { DAQController = daq };
            var dev = new UnitConvertingExternalDevice(UNUSED_NAME, UNUSED_DEVICE_MANUFACTURER, c, UNUSED_BACKGROUND);
            var outStream = new DAQOutputStream("out");
            var inStream = new DAQInputStream("in");

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

            var srate = new Measurement(100, "Hz");
            var samples = Enumerable.Range(0, 100).Select(i => new Measurement(1, "V")).ToList();

            var e = new Epoch("PushesDataToEpoch");
            e.Responses[dev] = new Response();

            e.Stimuli[dev] = new RenderedStimulus((string) "ID1", (IDictionary<string, object>) new Dictionary<string, object>(), (IOutputData) new OutputData(samples, srate, false));

            var data = new InputData(samples, srate, DateTimeOffset.Now).DataWithStreamConfiguration(inStream, new Dictionary<string, object>());
            bool pushed = false;

            daq.Started += (evt, args) =>
                {
                    c.PushInputData(dev, data);
                    pushed = true;

                    c.RequestStop();
                };

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

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

            Assert.That(e.Responses[dev].Data, Is.EqualTo(data.Data));
            Assert.That(e.Responses[dev].InputTime, Is.EqualTo(data.InputTime));
            Assert.That(e.Responses[dev].DataConfigurationSpans.First().Nodes.First(),
                Is.EqualTo(data.NodeConfigurationWithName(inStream.Name)));
        }
Esempio n. 45
0
 public void PullWithoutDevice()
 {
     DAQOutputStream s = new DAQOutputStream("OUT");
     s.PullOutputData(new TimeSpan(1));
 }
Esempio n. 46
0
 public void InactiveStreamDoesNotHaveMoreData()
 {
     DAQOutputStream s = new DAQOutputStream("OUT");
     Assert.False(s.Active);
     Assert.False(s.HasMoreData);
 }
Esempio n. 47
0
        public void OutputStreamShouldPropagateOutputConfiguration()
        {
            var s = new DAQOutputStream("test");
            var device = new DynamicMock(typeof (IExternalDevice));

            DateTimeOffset time = DateTime.Now;
            var config = new List<IPipelineNodeConfiguration>();
            device.Expect("DidOutputData", new object[] {s, time, TimeSpan.FromSeconds(0.1), config});

            s.Device = device.MockInstance as IExternalDevice;

            s.DidOutputData(time, TimeSpan.FromSeconds(0.1), config);

            device.Verify();
        }
Esempio n. 48
0
        private static void OutputStreamFixture(out IList<IOutputData> data, out DAQOutputStream s, int numData)
        {
            data = new List<IOutputData>(3);

            var measurements = new List<IMeasurement>(2) {new Measurement(1, "V"), new Measurement(2, "V")};

            var sampleRate = new Measurement(1000, "Hz");
            for (int i = 0; i < numData; i++)
            {
                bool last = i == numData - 1 ? true : false;

                IOutputData outputData = new OutputData(measurements,
                                                        sampleRate,
                                                        last);
                data.Add(outputData);
            }

            s = new DAQOutputStream("OUT")
                    {
                        MeasurementConversionTarget = measurements.First().BaseUnit,
                        SampleRate = sampleRate
                    };

            var outData = new Dictionary<IDAQOutputStream, Queue<IOutputData>>(1);
            outData[s] = new Queue<IOutputData>(data);

            var outDevice = new TestDevice("OUT-DEVICE", outData)
                                {
                                    Controller = new Controller(),
                                    MeasurementConversionTarget = "V"
                                };

            s.Device = outDevice;
        }
Esempio n. 49
0
        public void GetsStreamsByName()
        {
            string name1 = "IN1";
            string name2 = "IN2";
            string name3 = "OUT1";

            IDAQStream in1 = new DAQInputStream(name1);
            IDAQStream in2 = new DAQInputStream(name2);
            IDAQStream in3 = new DAQInputStream(name1);
            IDAQStream out1 = new DAQOutputStream(name3);
            var c = new SimpleDAQController();
            (c as IMutableDAQController).AddStream(in1);
            (c as IMutableDAQController).AddStream(in2);
            (c as IMutableDAQController).AddStream(in3);
            (c as IMutableDAQController).AddStream(out1);

            Assert.AreEqual(2, c.GetStreams(name1).Count());
            Assert.AreEqual(1, c.GetStreams(name2).Count());
            Assert.AreEqual(1, c.GetStreams(name3).Count());

            Assert.AreEqual(in2, c.GetStreams(name2).First());
            Assert.AreEqual(out1, c.GetStreams(name3).First());
        }
Esempio n. 50
0
        public void ExternalDeviceStreams()
        {
            var ed = new UnitConvertingExternalDevice("TestDevice", UNUSED_DEVICE_MANUFACTURER, UNUSED_BACKGROUND);

            DAQInputStream in0 = new DAQInputStream("In-0");
            DAQOutputStream out0 = new DAQOutputStream("Out-0");
            ed.BindStream(in0).BindStream(out0);

            Assert.IsTrue(ed.Streams.ContainsKey(in0.Name));
            Assert.IsTrue(in0.Devices.Contains(ed));
            Assert.IsTrue(ed.Streams.ContainsKey(out0.Name));
            Assert.IsTrue(out0.Device == ed);

            ed.UnbindStream("In-0");
            Assert.IsFalse(ed.Streams.ContainsKey(in0.Name));
            Assert.IsFalse(in0.Devices.Contains(ed));
            Assert.IsTrue(ed.Streams.ContainsKey(out0.Name));
            Assert.IsTrue(out0.Device == ed);

            ed.UnbindStream("Out-0");
            Assert.IsFalse(ed.Streams.ContainsKey(in0.Name));
            Assert.IsFalse(in0.Devices.Contains(ed));
            Assert.IsFalse(ed.Streams.ContainsKey(out0.Name));
            Assert.IsFalse(out0.Device == ed);
        }
Esempio n. 51
0
        public void OutputStreamSetSampleRateUnits()
        {
            DAQOutputStream s = new DAQOutputStream("");

            s.SampleRate = new Measurement(10, "A");
        }
Esempio n. 52
0
        public void CreatePipeline()
        {
            // Based on the "Minimal Rig.pdf" in the docs folder
            Converters.Clear();

            // We need an IClock
            IClock clock = new FakeClock();

            // We need a controller ...
            Controller con = new Controller();

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

            con.Clock = clock;

            // Three ExternalDevices
            CoalescingDevice amp = new CoalescingDevice("Amp", UNUSED_DEVICE_MANUFACTURER, con, UNUSED_BACKGROUND)
                                       {
                                           MeasurementConversionTarget = "units"
                                       };
            var LED = new UnitConvertingExternalDevice("LED", UNUSED_DEVICE_MANUFACTURER, UNUSED_BACKGROUND)
            {
                MeasurementConversionTarget = "units"
            };
            var temp = new UnitConvertingExternalDevice("Temp", UNUSED_DEVICE_MANUFACTURER, UNUSED_BACKGROUND)
            {
                MeasurementConversionTarget = "units"
            };
            amp.Clock = clock;
            LED.Clock = clock;
            temp.Clock = clock;
            con.AddDevice(LED).AddDevice(temp);
            // There should be no difference whether we use the
            // ExternalDevice constructor to wire up the Controller
            // to the ExternalDevice, or the explicit Add() call

            Assert.IsNotNull(amp.Controller);
            Assert.IsNotNull(LED.Controller);
            Assert.IsNotNull(temp.Controller);

            Assert.IsTrue(amp.Controller == con);
            Assert.IsTrue(LED.Controller == con);
            Assert.IsTrue(temp.Controller == con);

            // Five DAQStreams
            DAQInputStream in0 = new DAQInputStream("In-0"); in0.Clock = clock;
            DAQInputStream in1 = new DAQInputStream("In-1"); in1.Clock = clock;
            DAQInputStream in2 = new DAQInputStream("In-2"); in2.Clock = clock;
            DAQOutputStream out0 = new DAQOutputStream("Out-0"); out0.Clock = clock;
            DAQOutputStream out1 = new DAQOutputStream("Out-1"); out1.Clock = clock;
            in0.MeasurementConversionTarget = "units";
            in1.MeasurementConversionTarget = "units";
            in2.MeasurementConversionTarget = "units";
            out0.MeasurementConversionTarget = "units";
            out1.MeasurementConversionTarget = "units";

            //amp.Coalesce = CoalescingDevice.OneItemCoalesce;
            amp.Configuration["CoalesceProc"] = "Symphony.Core.CoalescingDevice.OneItemCoalesce";

            LED.BindStream(out0);
            amp.BindStream(out1).BindStream(in0).BindStream(in1);
            amp.Connect(in0, in1);
            temp.BindStream(in2);

            Assert.IsTrue(LED.Streams.Count == 1);
            Assert.IsTrue(amp.Streams.Count == 3);
            Assert.IsTrue(temp.Streams.Count == 1);

            Assert.IsTrue(in0.Devices.Contains(amp));
            Assert.IsTrue(in1.Devices.Contains(amp));
            Assert.IsTrue(in2.Devices.Contains(temp));
            Assert.IsTrue(out0.Device == LED);
            Assert.IsTrue(out1.Device == amp);

            // One DAQController
            IDAQController dc =
                new SimpleDAQController(new IDAQStream[] { in0, in1, in2, out0, out1 });

            con.DAQController = dc;

            // DAQController-to-streams
            Assert.IsTrue(dc.InputStreams.Contains(in0));
            Assert.IsTrue(dc.InputStreams.Contains(in1));
            Assert.IsTrue(dc.InputStreams.Contains(in2));
            Assert.IsTrue(dc.OutputStreams.Contains(out0));
            Assert.IsTrue(dc.OutputStreams.Contains(out0));

            // Validate and report the validation results
            Maybe<string> conVal = con.Validate();
            Assert.IsTrue(conVal, conVal.Item2);

            Assert.IsTrue(amp.Coalesce == CoalescingDevice.OneItemCoalesce);
        }
Esempio n. 53
0
        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();
        }
Esempio n. 54
0
        public void OutputStreamSetSampleRateUnits()
        {
            DAQOutputStream s = new DAQOutputStream("");

            s.SampleRate = new Measurement(10, "A");
        }