public void ExceptionalStopOnOutputUnderrun() { foreach (HekaDAQController daq in HekaDAQController.AvailableControllers()) { try { bool receivedExc = false; FixtureForController(daq, durationSeconds: 1.0); InputDevice.InputData[InputStream] = new List <IInputData>(); daq.ExceptionalStop += (c, args) => receivedExc = true; daq.Start(false); Assert.That(receivedExc, Is.True.After(1000, 10)); } finally { if (daq.HardwareReady) { daq.CloseHardware(); } } } }
public void ChannelInfoShouldGiveCompleteITCChannelInfo( [Values((ushort)0, (ushort)1, (ushort)8)] ushort channelNumber, [Values(StreamType.AO, StreamType.DO_PORT, StreamType.XO)] StreamType streamType ) { var controller = new HekaDAQController(); const string name = "UNUSED_NAME"; var s = new HekaDAQOutputStream(name, streamType, channelNumber, controller); const decimal sampleRate = 9000; var srate = new Measurement(sampleRate, "Hz"); controller.SampleRate = srate; ITCMM.ITCChannelInfo info = s.ChannelInfo; Assert.AreEqual(channelNumber, info.ChannelNumber); Assert.AreEqual((int)streamType, info.ChannelType); Assert.AreEqual(s.SampleRate.QuantityInBaseUnits, info.SamplingRate); Assert.AreEqual(ITCMM.USE_FREQUENCY, info.SamplingIntervalFlag); Assert.AreEqual(0, info.Gain); Assert.AreEqual(IntPtr.Zero, info.FIFOPointer); }
public void ChannelInfoShouldGiveCompleteITCChannelInfo( [Values((ushort)0, (ushort)1, (ushort)8)] ushort channelNumber, [Values(StreamType.ANALOG_OUT, StreamType.DIGITAL_OUT, StreamType.AUX_OUT)] StreamType streamType ) { var controller = new HekaDAQController(); const string name = "UNUSED_NAME"; var s = new HekaDAQOutputStream(name, streamType, channelNumber, controller); const decimal sampleRate = 9000; var srate = new Measurement(sampleRate, "Hz"); controller.SampleRate = srate; ITCMM.ITCChannelInfo info = s.ChannelInfo; Assert.AreEqual(channelNumber, info.ChannelNumber); Assert.AreEqual((int)streamType, info.ChannelType); Assert.AreEqual(s.SampleRate.QuantityInBaseUnit, info.SamplingRate); Assert.AreEqual(ITCMM.USE_FREQUENCY, info.SamplingIntervalFlag); Assert.AreEqual(0, info.Gain); Assert.AreEqual(IntPtr.Zero, info.FIFOPointer); }
public void RoundTripStreamITChannelInfo() { foreach (HekaDAQController daq in HekaDAQController.AvailableControllers()) { daq.InitHardware(); try { daq.ExceptionalStop += (c, arg) => { throw arg.Exception; }; foreach (HekaDAQStream stream in daq.Streams.Cast <HekaDAQStream>()) { daq.SampleRate = new Measurement(stream.ChannelNumber, 1, "Hz"); ITCMM.ITCChannelInfo info = stream.ChannelInfo; Assert.AreEqual(stream.ChannelNumber, info.ChannelNumber); Assert.AreEqual((uint)stream.ChannelType, info.ChannelType); //NO_SCALE is seconds scale (Hz) Assert.AreEqual(ITCMM.USE_FREQUENCY & ITCMM.NO_SCALE & ITCMM.ADJUST_RATE, info.SamplingIntervalFlag); Assert.That(info.SamplingRate, Is.EqualTo(stream.SampleRate.QuantityInBaseUnit)); Assert.AreEqual(IntPtr.Zero, info.FIFOPointer); Assert.AreEqual(0, info.Gain); } } finally { daq.CloseHardware(); } } }
public void ShouldOpenHardwareOnStart() { foreach (HekaDAQController daq in HekaDAQController.AvailableControllers()) { try { bool receivedExc = false; FixtureForController(daq, durationSeconds: 1.0); InputDevice.InputData[InputStream] = new List <IInputData>(); daq.ProcessIteration += (c, args) => { Console.WriteLine("Blowing up the pipeline."); throw new Exception("bam!"); }; daq.ExceptionalStop += (c, args) => receivedExc = true; daq.CloseHardware(); daq.Start(false); Assert.That(receivedExc, Is.True.After(1000, 10)); } finally { daq.CloseHardware(); } } }
public HekaDAQOutputStream(string name, StreamType streamType, ushort channelNumber, HekaDAQController controller) : base(name, controller) { this.ChannelType = streamType; this.ChannelNumber = channelNumber; this.MeasurementConversionTarget = (ChannelType == StreamType.DO_PORT || ChannelType == StreamType.XO) ? Measurement.UNITLESS : DAQCountUnits; this.Controller = controller; this.Clock = controller.Clock; }
public void DelegatesSampleRateToController() { var c = new HekaDAQController(); var s = new HekaDAQOutputStream("none", 0, 0, c); var srate = new Measurement(1000, "Hz"); c.SampleRate = srate; Assert.That(s.SampleRate, Is.EqualTo(c.SampleRate)); Assert.Throws<NotSupportedException>(() => s.SampleRate = srate); }
public void SampleRateMustBeInHz() { var c = new HekaDAQController(); c.SampleRate = new Measurement(1, "barry"); Assert.False((bool)c.Validate()); c.SampleRate = new Measurement(1, "Hz"); Assert.True((bool)c.Validate()); }
public HekaDAQInputStream(string name, StreamType streamType, ushort channelNumber, HekaDAQController controller) : base(name, controller) { this.ChannelType = streamType; this.ChannelNumber = channelNumber; this.MeasurementConversionTarget = (ChannelType == StreamType.DIGITAL_IN || ChannelType == StreamType.AUX_IN) ? Measurement.UNITLESS : "V"; this.Controller = controller; this.Clock = controller; }
public void ShouldStoreSampleRateInConfiguration() { var c = new HekaDAQController(); var expected = new Measurement(1000, "Hz"); c.SampleRate = expected; Assert.That(c.SampleRate, Is.EqualTo(expected)); Assert.That(c.Configuration.ContainsKey("SampleRate")); }
public void DelegatesSampleRateToController() { var c = new HekaDAQController(); var s = new HekaDAQOutputStream("none", 0, 0, c); var srate = new Measurement(1000, "Hz"); c.SampleRate = srate; Assert.That(s.SampleRate, Is.EqualTo(c.SampleRate)); Assert.Throws <NotSupportedException>(() => s.SampleRate = srate); }
private void FixtureForController(HekaDAQController controller, double durationSeconds = 10) { controller.Clock = controller; controller.SampleRate = new Measurement(10000, "Hz"); controller.InitHardware(); OutStream = controller.OutputStreams .OfType <HekaDAQOutputStream>() .Where(str => str.ChannelNumber == 0) .First(); InputStream = controller.InputStreams .OfType <HekaDAQInputStream>() .Where(str => str.ChannelNumber == 0) .First(); InputStream.Configuration["SampleRate"] = InputStream.SampleRate; OutStream.Configuration["SampleRate"] = OutStream.SampleRate; IDAQOutputStream s = OutStream; var dataQueue = new Dictionary <IDAQOutputStream, Queue <IOutputData> >(); dataQueue[s] = new Queue <IOutputData>(); Data = new OutputData( Enumerable.Range(0, (int)(TimeSpan.FromSeconds(durationSeconds).Samples(controller.SampleRate))) .Select(i => new Measurement(i % 10, "V")).ToList(), s.SampleRate, false); TimeSpan d = new TimeSpan(controller.ProcessInterval.Ticks / 2); var outData = (IOutputData)Data.Clone(); while (outData.Duration > TimeSpan.Zero) { var split = outData.SplitData(d); dataQueue[s].Enqueue(new OutputData(split.Head, split.Rest.Duration == TimeSpan.Zero)); outData = split.Rest; } OutDevice = new TestDevice("Output", dataQueue); InputDevice = new TestDevice("Intput", null); OutDevice.MeasurementConversionTarget = "V"; InputDevice.MeasurementConversionTarget = "V"; BindStreams(controller, OutDevice, InputDevice); }
public void SampleRateMustBeGreaterThanZero() { var c = new HekaDAQController(); c.SampleRate = new Measurement(0, "Hz"); Assert.False((bool)c.Validate()); c.SampleRate = new Measurement(-.1m, "Hz"); Assert.False((bool)c.Validate()); c.SampleRate = new Measurement(1, "Hz"); Assert.True((bool)c.Validate()); }
public void PreloadShouldFeedBuffer() { /* * We want to keep HardwareBufferTargetDuration available in the hardware buffer. */ Converters.Clear(); HekaDAQOutputStream.RegisterConverters(); var itcMock = new Mock <IHekaDevice>(); StreamType channelType = StreamType.ANALOG_OUT; ushort channelNumber = 0; var time = DateTimeOffset.Now; int availableSamplesStart = 1000000; int availableSamples = availableSamplesStart; //itcMock.Setup(itc => itc.AvailableSamples(channelType, channelNumber)).Returns(availableSamples); itcMock.Setup(itc => itc.PreloadSamples(channelType, channelNumber, It.IsAny <IList <short> >())) .Callback <StreamType, ushort, IList <short> >((type, number, sampleList) => availableSamples -= sampleList.Count); var controller = new HekaDAQController(); HekaDAQOutputStream s = new HekaDAQOutputStream("OUT", channelType, channelNumber, controller); s.MeasurementConversionTarget = "V"; controller.SampleRate = new Measurement(10000, 1, "Hz"); var dataQueue = new Dictionary <IDAQOutputStream, Queue <IOutputData> >(); dataQueue[s] = new Queue <IOutputData>(); var bigData = new OutputData(Enumerable.Range(0, 100000).Select(i => new Measurement(i % 5, "V")).ToList(), s.SampleRate, false); TimeSpan bufferDuration = TimeSpan.FromSeconds(0.45); dataQueue[s].Enqueue(bigData.SplitData(bufferDuration).Head); dataQueue[s].Enqueue(bigData.SplitData(bufferDuration).Head); TestDevice dev = new TestDevice("OUT-DEVICE", dataQueue); dev.BindStream(s); dev.Controller = new Controller(); s.Preload(itcMock.Object as IHekaDevice, new OutputData(dataQueue[s].Peek())); int expectedSamples = (int)Math.Ceiling(bufferDuration.TotalSeconds * (double)s.SampleRate.QuantityInBaseUnit); itcMock.VerifyAll(); Assert.AreEqual(availableSamplesStart - expectedSamples, availableSamples); //Preload should not affect buffer availablility because PRELOAD_FIFO is used }
public void StopDAQControllers() { foreach (HekaDAQController controller in HekaDAQController.AvailableControllers()) { if (controller.Running) { controller.Stop(); } if (controller.HardwareReady) { //controller.CloseHardware(); } } }
public void PreloadShouldFeedBuffer() { /* * We want to keep HardwareBufferTargetDuration available in the hardware buffer. */ Converters.Clear(); HekaDAQOutputStream.RegisterConverters(); var itcMock = new Mock<IHekaDevice>(); StreamType channelType = StreamType.AO; ushort channelNumber = 0; var time = DateTimeOffset.Now; int availableSamplesStart = 1000000; int availableSamples = availableSamplesStart; //itcMock.Setup(itc => itc.AvailableSamples(channelType, channelNumber)).Returns(availableSamples); itcMock.Setup(itc => itc.PreloadSamples(channelType, channelNumber, It.IsAny<IList<short>>())) .Callback<StreamType, ushort, IList<short>>((type, number, sampleList) => availableSamples -= sampleList.Count); var controller = new HekaDAQController(); HekaDAQOutputStream s = new HekaDAQOutputStream("OUT", channelType, channelNumber, controller); s.MeasurementConversionTarget = "V"; controller.SampleRate = new Measurement(10000, 1, "Hz"); var dataQueue = new Dictionary<IDAQOutputStream, Queue<IOutputData>>(); dataQueue[s] = new Queue<IOutputData>(); var bigData = new OutputData(Enumerable.Range(0, 100000).Select(i => new Measurement(i % 5, "V")).ToList(), s.SampleRate, false); TimeSpan bufferDuration = TimeSpan.FromSeconds(0.45); dataQueue[s].Enqueue(bigData.SplitData(bufferDuration).Head); dataQueue[s].Enqueue(bigData.SplitData(bufferDuration).Head); TestDevice dev = new TestDevice("OUT-DEVICE", dataQueue); dev.BindStream(s); dev.Controller = new Controller(); s.Preload(itcMock.Object as IHekaDevice, new OutputData(dataQueue[s].Peek())); int expectedSamples = (int)Math.Ceiling(bufferDuration.TotalSeconds * (double)s.SampleRate.QuantityInBaseUnits); itcMock.VerifyAll(); Assert.AreEqual(availableSamplesStart - expectedSamples, availableSamples); //Preload should not affect buffer availablility because PRELOAD_FIFO is used }
public void SegregatesStreams() { foreach (HekaDAQController controller in HekaDAQController.AvailableControllers()) { Assert.False(controller.HardwareReady); controller.InitHardware(); try { CollectionAssert.AllItemsAreInstancesOfType(controller.StreamsOfType(StreamType.ANALOG_IN), typeof(HekaDAQInputStream)); CollectionAssert.AllItemsAreInstancesOfType(controller.StreamsOfType(StreamType.ANALOG_OUT), typeof(HekaDAQOutputStream)); } finally { controller.CloseHardware(); } } }
public void InitializesHardware() { foreach (HekaDAQController controller in HekaDAQController.AvailableControllers()) { Assert.False(controller.HardwareReady); controller.InitHardware(); try { Assert.True(controller.HardwareReady); } finally { controller.CloseHardware(); Assert.False(controller.HardwareReady); } } }
public void SetsChannelInfo() { foreach (HekaDAQController daq in HekaDAQController.AvailableControllers()) { const decimal srate = 10000; daq.InitHardware(); Assert.True(daq.HardwareReady); Assert.False(daq.HardwareRunning); try { foreach (IDAQOutputStream s in daq.OutputStreams) { daq.SampleRate = new Measurement(srate, "Hz"); TestDevice externalDevice = new TestDevice("OUT-DEVICE", null); s.Device = externalDevice; } daq.ConfigureChannels(); foreach (HekaDAQStream s in daq.OutputStreams.Cast <HekaDAQStream>()) { ITCMM.ITCChannelInfo actual = daq.ChannelInfo(s.ChannelType, s.ChannelNumber); ITCMM.ITCChannelInfo expected = s.ChannelInfo; Assert.AreEqual(expected.ChannelNumber, actual.ChannelNumber); Assert.AreEqual(expected.ChannelType, actual.ChannelType); Assert.AreEqual(expected.SamplingIntervalFlag, actual.SamplingIntervalFlag); Assert.AreEqual(expected.SamplingRate, actual.SamplingRate); // Gain set by hardware. } } finally { daq.CloseHardware(); } } }
public void ShouldResetHardwareWhenStopsWithException() { foreach (HekaDAQController daq in HekaDAQController.AvailableControllers()) { bool receivedExc = false; FixtureForController(daq, durationSeconds: 1.0); InputDevice.InputData[InputStream] = new List <IInputData>(); daq.ProcessIteration += (c, args) => { Console.WriteLine("Blowing up the pipeline."); throw new Exception("bam!"); }; daq.ExceptionalStop += (c, args) => receivedExc = true; daq.Start(false); Assert.That(receivedExc, Is.True.After(1000, 10)); daq.CloseHardware(); //Should be ready to initialize again try { Assert.That(() => daq.InitHardware(), Throws.Nothing); } finally { if (daq.HardwareReady) { daq.CloseHardware(); } } } }
} //should be internal, but testing needs access public HekaDAQInputStream(string name, StreamType streamType, ushort channelNumber, HekaDAQController controller) : base(name, controller) { this.ChannelType = streamType; this.ChannelNumber = channelNumber; this.MeasurementConversionTarget = (ChannelType == StreamType.DIGITAL_IN || ChannelType == StreamType.AUX_IN) ? Measurement.UNITLESS : "V"; this.Controller = controller; this.Clock = controller; }
public void AvailableControllers() { Assert.GreaterOrEqual(HekaDAQController.AvailableControllers().Count(), 1); }
private void FixtureForController(HekaDAQController controller, double durationSeconds = 10) { controller.SampleRate = new Measurement(10000, "Hz"); controller.InitHardware(); OutStream = controller.OutputStreams .OfType<HekaDAQOutputStream>().First(str => str.ChannelNumber == 0); InputStream = controller.InputStreams .OfType<HekaDAQInputStream>().First(str => str.ChannelNumber == 0); InputStream.Configuration["SampleRate"] = InputStream.SampleRate; OutStream.Configuration["SampleRate"] = OutStream.SampleRate; IDAQOutputStream s = OutStream; var dataQueue = new Dictionary<IDAQOutputStream, Queue<IOutputData>>(); dataQueue[s] = new Queue<IOutputData>(); Data = new OutputData( Enumerable.Range(0, (int)(TimeSpan.FromSeconds(durationSeconds).Samples(controller.SampleRate))) .Select(i => new Measurement(i % 10, "V")).ToList(), s.SampleRate, false); TimeSpan d = new TimeSpan(controller.ProcessInterval.Ticks / 2); var outData = (IOutputData)Data.Clone(); while (outData.Duration > TimeSpan.Zero) { var split = outData.SplitData(d); dataQueue[s].Enqueue(new OutputData(split.Head, split.Rest.Duration == TimeSpan.Zero)); outData = split.Rest; } OutDevice = new TestDevice("Output", dataQueue); InputDevice = new TestDevice("Input", null); OutDevice.MeasurementConversionTarget = "V"; InputDevice.MeasurementConversionTarget = "V"; BindStreams(controller, OutDevice, InputDevice); }
public void ShouldBitShiftAndMaskPushedInputData() { var controller = new HekaDAQController(); var s = new HekaDigitalDAQInputStream("IN", 0, controller); controller.SampleRate = new Measurement(10000, 1, "Hz"); TimeSpan duration = TimeSpan.FromSeconds(0.5); var devices = new List<TestDevice>(); for (ushort bitPosition = 1; bitPosition < 16; bitPosition += 2) { TestDevice dev = new TestDevice(); dev.BindStream(s); s.BitPositions[dev] = bitPosition; devices.Add(dev); } var data = new InputData(Enumerable.Range(0, 10000).Select(i => new Measurement((short)(i % 2 * 0xaaaa), Measurement.UNITLESS)).ToList(), s.SampleRate, DateTime.Now); s.PushInputData(data); s.PushInputData(data); var expected = Enumerable.Range(0, 10000).Select(i => new Measurement(i % 2, Measurement.UNITLESS)).ToList(); foreach (var ed in devices) { Assert.AreEqual(expected, ed.InputData[s].ElementAt(0).Data); Assert.AreEqual(expected, ed.InputData[s].ElementAt(1).Data); } }
public void ShouldBitShiftAndMergeBackground() { var controller = new HekaDAQController(); var s = new HekaDigitalDAQOutputStream("OUT", 0, controller); controller.SampleRate = new Measurement(10000, 1, "Hz"); for (ushort bitPosition = 1; bitPosition < 16; bitPosition += 2) { TestDevice dev = new TestDevice {Background = new Measurement(1, Measurement.UNITLESS)}; dev.BindStream(s); s.BitPositions[dev] = bitPosition; } ulong q = 0xaaaa; var expected = new Measurement((long)q, Measurement.UNITLESS); Assert.AreEqual(expected, s.Background); }
public void ShouldBitShiftAndMergePulledOutputData() { var controller = new HekaDAQController(); var s = new HekaDigitalDAQOutputStream("OUT", 0, controller); controller.SampleRate = new Measurement(10000, 1, "Hz"); TimeSpan duration = TimeSpan.FromSeconds(0.5); for (ushort bitPosition = 1; bitPosition < 16; bitPosition += 2) { var dataQueue = new Dictionary<IDAQOutputStream, Queue<IOutputData>>(); dataQueue[s] = new Queue<IOutputData>(); var data = new OutputData(Enumerable.Range(0, 10000).Select(i => new Measurement(i % 2, Measurement.UNITLESS)).ToList(), s.SampleRate, false); dataQueue[s].Enqueue(data.SplitData(duration).Head); dataQueue[s].Enqueue(data.SplitData(duration).Head); TestDevice dev = new TestDevice("OUT-DEVICE" + bitPosition, dataQueue); dev.BindStream(s); s.BitPositions[dev] = bitPosition; } var expected = Enumerable.Range(0, 10000).Select(i => new Measurement((long)(i % 2 * 0xaaaa), Measurement.UNITLESS)).ToList(); var pull1 = s.PullOutputData(duration); Assert.AreEqual(expected, pull1.Data); var pull2 = s.PullOutputData(duration); Assert.AreEqual(expected, pull2.Data); }
public HekaDigitalDAQOutputStream(string name, ushort channelNumber, HekaDAQController controller) : base(name, StreamType.DO_PORT, channelNumber, controller) { BitPositions = new Dictionary<IExternalDevice, ushort>(); }