// needs a shot at processing the InputData on its way back from the board
        public override void PushInputData(IDAQInputStream stream, IInputData inData)
        {
            IInputData convertedData = new InputData(inData,
                                                     inData.DataWithUnits(MeasurementConversionTarget).Data); //TODO

            this.Controller.PushInputData(this, convertedData.DataWithExternalDeviceConfiguration(Configuration));
        }
예제 #2
0
        // needs a shot at processing the InputData on its way back from the board
        public override void PushInputData(IDAQInputStream stream, IInputData inData)
        {
            // Do these conversions need to be on a per-stream basis?
            // Or is per-device enough?

            // This is the easy part
            queues[stream].Add(inData);

            // Now figure out if we have all the data we need
            bool haveOneOfEverything = true;

            foreach (var dataList in queues.Values)
            {
                if (dataList.Count == 0)
                {
                    haveOneOfEverything = false;
                }
            }

            if (haveOneOfEverything)
            {
                IList <IInputData> data = new List <IInputData>();
                foreach (var dataList in queues.Values)
                {
                    data.Add(dataList[0]); data.RemoveAt(0);
                }

                Controller.PushInputData(this, Coalesce(data));
            }
        }
예제 #3
0
        public override void PushInputData(IDAQInputStream stream, IInputData inData)
        {
            if (!InputData.ContainsKey(stream))
            {
                InputData[stream] = new List <IInputData>();
            }

            InputData[stream].Add(inData);
        }
예제 #4
0
        /// <summary>
        /// Associate an IDAQInputStream with this ExternalDevice with the given name.
        /// Adds this device to the stream's
        /// Devices list.
        /// </summary>
        /// <param name="name">Associatino name</param>
        /// <param name="inputStream">Stream to bind</param>
        public ExternalDeviceBase BindStream(string name, IDAQInputStream inputStream)
        {
            Contract.Assert(inputStream != null, "inputStream is null");
            Contract.Assert(name != null && name.Length > 0, "name is null or empty");

            inputStream.Devices.Add(this);
            this.Streams[name] = inputStream;
            return(this);
        }
예제 #5
0
        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);
        }
예제 #6
0
        /// <summary>
        /// Pushes input data to this Device's controller.
        /// </summary>
        /// <param name="stream">Stream supplying the input data</param>
        /// <param name="inData">IInputData to push to the controller</param>
        public override void PushInputData(IDAQInputStream stream, IInputData inData)
        {
            try
            {
                IInputData convertedData = inData.DataWithUnits(MeasurementConversionTarget)
                                           .DataWithExternalDeviceConfiguration(this, Configuration);

                this.Controller.PushInputData(this, convertedData);
            }
            catch (Exception ex)
            {
                log.DebugFormat("Error pushing data to controller: {0}", ex);
                throw;
            }
        }
예제 #7
0
        /// <summary>
        /// Reads the given input stream, asynchronously (in the ITC sense, not the .Net sense). Should not be called while
        /// Running.
        /// </summary>
        /// <remarks>All output streams are automatically set to their associated ExternalDevice's Background value on stop</remarks>
        /// <param name="daqInputStream">IDAQInputStream to read</param>
        /// <returns>IInputData with a single read sample</returns>
        /// <exception cref="ArgumentException">If the given stream is not an input stream belonging to this HekaDAQController</exception>"
        public IInputData ReadStreamAsyncIO(IDAQInputStream daqInputStream)
        {
            if (!InputStreams.Contains(daqInputStream))
            {
                throw new ArgumentException("Input stream is not present on this device.", "daqInputStream");
            }

            var instream = daqInputStream as HekaDAQInputStream;

            if (instream != null)
            {
                return(Device.ReadStreamAsyncIO(instream));
            }

            return(null);
        }
예제 #8
0
        /// <summary>
        /// Pushes input data to this Device's controller.
        /// </summary>
        /// <param name="stream">Stream supplying the input data</param>
        /// <param name="inData">IInputData to push to the controller</param>
        public override void PushInputData(IDAQInputStream stream, IInputData inData)
        {
            try
            {
                var deviceParameters = DeviceParametersForInput(DateTimeOffset.Now.UtcDateTime).Data;

                IInputData convertedData = inData.DataWithConversion(
                    m => ConvertInput(m, deviceParameters)
                    );

                var config = MergeDeviceParametersIntoConfiguration(Configuration, deviceParameters);

                log.DebugFormat("Pushing InputData with parameters {0} (units {1})",
                                config,
                                UnitsForScaleFactorUnits(deviceParameters.ScaleFactorUnits));

                this.Controller.PushInputData(this, convertedData.DataWithExternalDeviceConfiguration(this, config));
            }
            catch (Exception ex)
            {
                log.DebugFormat("Error pushing data to controller: {0} ({1})", ex.Message, ex);
                throw;
            }
        }
예제 #9
0
 /// <summary>
 /// Pushes input data to this Device's controller.
 /// </summary>
 /// <param name="stream">Stream supplying the input data</param>
 /// <param name="inData">IInputData to push to the controller</param>
 public abstract void PushInputData(IDAQInputStream stream, IInputData inData);
예제 #10
0
        /// <summary>
        /// Associate an IDAQInputStream with this ExternalDevice with the given name.
        /// Adds this device to the stream's
        /// Devices list.
        /// </summary>
        /// <param name="name">Associatino name</param>
        /// <param name="inputStream">Stream to bind</param>
        public ExternalDeviceBase BindStream(string name, IDAQInputStream inputStream)
        {
            Contract.Assert(inputStream != null, "inputStream is null");
            Contract.Assert(name != null && name.Length > 0, "name is null or empty");

            inputStream.Devices.Add(this);
            this.Streams[name] = inputStream;
            return this;
        }
예제 #11
0
 /// <summary>
 /// Binds an IDAQInputStream to this device. Adds this device to the stream's
 /// Devices list.
 /// </summary>
 /// <param name="inputStream">Stream to bind</param>
 public ExternalDeviceBase BindStream(IDAQInputStream inputStream)
 {
     Contract.Assert(inputStream != null, "inputStream is null");
     return BindStream(inputStream.Name, inputStream);
 }
예제 #12
0
        // needs a shot at processing the InputData on its way back from the board
        public override void PushInputData(IDAQInputStream stream, IInputData inData)
        {
            // Do these conversions need to be on a per-stream basis?
            // Or is per-device enough?

            // This is the easy part
            queues[stream].Add(inData);

            // Now figure out if we have all the data we need
            bool haveOneOfEverything = true;
            foreach (var dataList in queues.Values)
            {
                if (dataList.Count == 0)
                {
                    haveOneOfEverything = false;
                }
            }

            if (haveOneOfEverything)
            {
                IList<IInputData> data = new List<IInputData>();
                foreach (var dataList in queues.Values)
                {
                    data.Add(dataList[0]); data.RemoveAt(0);
                }

                Controller.PushInputData(this, Coalesce(data));
            }
        }
예제 #13
0
 public override ExternalDeviceBase BindStream(string name, IDAQInputStream inputStream)
 {
     _queues.Add(inputStream, new List<IInputData>());
     return base.BindStream(name, inputStream);
 }
예제 #14
0
        public override void PushInputData(IDAQInputStream stream, IInputData inData)
        {
            if (!InputData.ContainsKey(stream))
            {
                InputData[stream] = new List<IInputData>();
            }

            InputData[stream].Add(inData);
        }
예제 #15
0
 public ExternalDeviceBase BindStream(string name, IDAQInputStream inputStream)
 {
     throw new NotImplementedException();
 }
예제 #16
0
        /// <summary>
        /// Reads the given input stream, asynchronously (in the ITC sense, not the .Net sense). Should not be called while
        /// Running.
        /// </summary>
        /// <remarks>All output streams are automatically set to their associated ExternalDevice's Background value on stop</remarks>
        /// <param name="daqInputStream">IDAQInputStream to read</param>
        /// <returns>IInputData with a single read sample</returns>
        /// <exception cref="ArgumentException">If the given stream is not an input stream belonging to this HekaDAQController</exception>"
        public IInputData ReadStreamAsyncIO(IDAQInputStream daqInputStream)
        {
            if (!InputStreams.Contains(daqInputStream))
                throw new ArgumentException("Input stream is not present on this device.", "daqInputStream");

            var instream = daqInputStream as HekaDAQInputStream;
            if (instream != null)
            {
                return Device.ReadStreamAsyncIO(instream);
            }

            return null;
        }
예제 #17
0
 /// <summary>
 /// Pushes input data to this Device's controller.
 /// </summary>
 /// <param name="stream">Stream supplying the input data</param>
 /// <param name="inData">IInputData to push to the controller</param>
 public abstract void PushInputData(IDAQInputStream stream, IInputData inData);
예제 #18
0
        public override void PushInputData(IDAQInputStream stream, IInputData inData)
        {
            if (inData.Data.Count == 0)
                return;

            _queues[stream].Add(inData);
            if (_queues.Values.Any(dataList => dataList.Count == 0))
                return;

            try
            {
                IDictionary<string, IInputData> data = new Dictionary<string, IInputData>();
                foreach (var dataList in _queues)
                {
                    string streamName = Streams.FirstOrDefault(x => x.Value == dataList.Key).Key;
                    data.Add(streamName, dataList.Value[0]);
                    dataList.Value.RemoveAt(0);
                }

                var deviceParameters = Axopatch.ReadTelegraphData(data);
                DeviceParameters = deviceParameters;

                IInputData scaledData = data[SCALED_OUTPUT_STREAM_NAME];
                IInputData convertedData = scaledData.DataWithConversion(m => ConvertInput(m, deviceParameters));

                var config = MergeDeviceParametersIntoConfiguration(Configuration, deviceParameters);

                this.Controller.PushInputData(this, convertedData.DataWithExternalDeviceConfiguration(this, config));
            }
            catch (Exception ex)
            {
                log.DebugFormat("Error pushing data to controller: {0} ({1})", ex.Message, ex);
                throw;
            }
        }
예제 #19
0
 /// <summary>
 /// Binds an IDAQInputStream to this device. Adds this device to the stream's
 /// Devices list.
 /// </summary>
 /// <param name="inputStream">Stream to bind</param>
 public ExternalDeviceBase BindStream(IDAQInputStream inputStream)
 {
     Contract.Assert(inputStream != null, "inputStream is null");
     return(BindStream(inputStream.Name, inputStream));
 }
예제 #20
0
        /// <summary>
        /// Pushes input data to this Device's controller.
        /// </summary>
        /// <param name="stream">Stream supplying the input data</param>
        /// <param name="inData">IInputData to push to the controller</param>
        public override void PushInputData(IDAQInputStream stream, IInputData inData)
        {
            try
            {

                IInputData convertedData = inData.DataWithUnits(MeasurementConversionTarget)
                    .DataWithExternalDeviceConfiguration(this, Configuration);

                this.Controller.PushInputData(this, convertedData);
            }
            catch (Exception ex)
            {
                log.DebugFormat("Error pushing data to controller: {0}", ex);
                throw;
            }
        }
 public override void PushInputData(IDAQInputStream stream, IInputData inData)
 {
 }
예제 #22
0
 public void AddStreamMapping(IDAQOutputStream outStream, IDAQInputStream inStream)
 {
     StreamMapping[outStream] = inStream;
 }
예제 #23
0
 public void PushInputData(IDAQInputStream stream, IInputData inData)
 {
     throw new NotImplementedException();
 }
예제 #24
0
 public ExternalDeviceBase BindStream(string name, IDAQInputStream inputStream)
 {
     throw new NotImplementedException();
 }
예제 #25
0
        /// <summary>
        /// Pushes input data to this Device's controller.
        /// </summary>
        /// <param name="stream">Stream supplying the input data</param>
        /// <param name="inData">IInputData to push to the controller</param>
        public override void PushInputData(IDAQInputStream stream, IInputData inData)
        {
            try
            {
                var deviceParameters = DeviceParametersForInput(DateTimeOffset.Now.UtcDateTime).Data;

                IInputData convertedData = inData.DataWithConversion(
                    m => ConvertInput(m, deviceParameters)
                    );

                var config = MergeDeviceParametersIntoConfiguration(Configuration, deviceParameters);

                log.DebugFormat("Pushing InputData with parameters {0} (units {1})",
                                config,
                                UnitsForScaleFactorUnits(deviceParameters.ScaleFactorUnits));

                this.Controller.PushInputData(this, convertedData.DataWithExternalDeviceConfiguration(this, config));
            }
            catch (Exception ex)
            {
                log.DebugFormat("Error pushing data to controller: {0} ({1})", ex.Message, ex);
                throw;
            }
        }
예제 #26
0
 public void PushInputData(IDAQInputStream stream, IInputData inData)
 {
     throw new NotImplementedException();
 }
예제 #27
0
 public void AddStreamMapping(IDAQOutputStream outStream, IDAQInputStream inStream)
 {
     StreamMapping[outStream] = inStream;
 }
예제 #28
0
        // needs a shot at processing the InputData on its way back from the board
        public override void PushInputData(IDAQInputStream stream, IInputData inData)
        {
            IInputData convertedData = new InputData(inData,
                inData.DataWithUnits(MeasurementConversionTarget).Data); //TODO

            this.Controller.PushInputData(this, convertedData.DataWithExternalDeviceConfiguration(Configuration));
        }
 public override IInputData ReadStreamAsync(IDAQInputStream s)
 {
     throw new NotImplementedException();
 }
예제 #30
0
 public override ExternalDeviceBase BindStream(string name, IDAQInputStream inputStream)
 {
     lock(_bindLock) base.BindStream(name, inputStream);
     Commander.RequestTelegraphValue();
     return this;
 }