/// <summary>
        /// Remove the Stream associated with this ExternalDevice
        /// </summary>
        /// <param name="name"></param>
        public void UnbindStream(string name)
        {
            if (Streams.ContainsKey(name))
            {
                IDAQStream stream = Streams[name];
                Streams.Remove(name);

                stream.RemoveDevice(this);
            }
        }
 public void AddStream(IDAQStream stream)
 {
     DAQStreams.Add(stream);
 }
Example #3
0
 public IInputData DataWithStreamConfiguration(IDAQStream stream, IDictionary <string, object> config)
 {
     return(DataWithNodeConfiguration(stream.Name, config));
 }
Example #4
0
        public SimpleDAQController(IDAQStream[] streams)
        {
            foreach (IDAQStream i in streams)
            {
                DAQStreams.Add(i);
            }

            BackgroundSet = false;
        }
 public void AddStream(IDAQStream stream)
 {
     DAQStreams.Add(stream);
 }
        public SimpleDAQController(IDAQStream[] streams)
        {
            foreach (IDAQStream i in streams)
            {
                DAQStreams.Add(i);
            }

            BackgroundSet = false;
            WaitedForTrigger = false;
            ProcessInterval = TimeSpan.FromSeconds(0.25);
        }
Example #7
0
        public Controller ParseConfiguration(string input, Dictionary <string, IClock> additionalClockProviders)
        {
            Controller controller     = new Controller();
            var        devices        = new List <ExternalDeviceBase>();
            var        streams        = new List <IDAQStream>();
            var        clockProviders = new Dictionary <string, IClock>(additionalClockProviders);

            var controllerConfig = ControllerParser.Parse(input);

            controller.Configuration[ClockKey] = controllerConfig.Clock;
            if (!string.IsNullOrEmpty(controllerConfig.ProvidesClock))
            {
                clockProviders[controllerConfig.ProvidesClock] = controller as IClock;
            }

            var            daqControllerConfig = controllerConfig.DAQController;
            IDAQController daqController       = (IDAQController)Construct(daqControllerConfig.Type);

            foreach (var nvp in daqControllerConfig.Config.ConfigValues)
            {
                var  key   = nvp.Name;
                var  value = nvp.Value;
                uint uintValue;
                if (UInt32.TryParse(value, out uintValue))
                {
                    daqController.Configuration[key] = uintValue;
                }
                else
                {
                    daqController.Configuration[key] = value;
                }
            }

            daqController.Configuration.Add(new KeyValuePair <string, object>(ClockKey, daqControllerConfig.Clock));

            if (!string.IsNullOrEmpty(daqControllerConfig.ProvidesClock))
            {
                clockProviders[daqControllerConfig.ProvidesClock] = daqController as IClock;
            }

            daqController.BeginSetup();

            foreach (var s in daqControllerConfig.Streams)
            {
                IDAQStream stream;

                if (daqController.GetStreams(s.Name).Count() > 1)
                {
                    throw new ParserException("More than one stream with name" + s.Name);
                }

                //If we can find the named stream, use the one created by DAQController, otherwise we'll add it.
                if (daqController.GetStreams(s.Name).Count() == 0)
                {
                    stream = (IDAQStream)Construct(s.Type, s.Name);
                }
                else
                {
                    stream = daqController.GetStreams(s.Name).First();
                }

                foreach (var nvp in s.Config.ConfigValues)
                {
                    var key   = nvp.Name;
                    var value = nvp.Value;
                    stream.Configuration.Add(new KeyValuePair <string, object>(key, value));
                }

                stream.Configuration.Add(new KeyValuePair <string, object>(ClockKey, s.Clock));
                try
                {
                    stream.SampleRate = s.SampleRate;
                }
                catch (NotSupportedException)
                {
                    //Heka streams don't support setting sample rate
                }

                streams.Add(stream);
            }

            foreach (var d in daqControllerConfig.Devices)
            {
                ExternalDeviceBase ed = (ExternalDeviceBase)(Construct(d.Type, d.Name, d.Manufacturer, controller, d.Background));

                foreach (var nvp in d.Config.ConfigValues)
                {
                    var key   = nvp.Name;
                    var value = nvp.Value;
                    ed.Configuration.Add(new KeyValuePair <string, object>(key, value));
                }

                ed.Configuration.Add(new KeyValuePair <string, object>(ClockKey, d.Clock));

                foreach (var bindCfg in d.Binds)
                {
                    IDAQStream st = streams.Find((s) => s.Name == bindCfg.Name);
                    if (st == null)
                    {
                        throw new Exception(String.Format("Attempting to bind {0} which does not exist in configuration", bindCfg.Name));
                    }
                    else
                    {
                        if (st is IDAQInputStream)
                        {
                            ed.BindStream((IDAQInputStream)st);
                        }
                        else if (st is IDAQOutputStream)
                        {
                            ed.BindStream((IDAQOutputStream)st);
                        }
                        else
                        {
                            throw new Exception(String.Format("Attempting to bind {0} which is neither an Input or Output stream", bindCfg.Name));
                        }
                    }
                }

                foreach (var connectCfg in d.Connects)
                {
                    if (ed is CoalescingDevice)
                    {
                        ((CoalescingDevice)ed).Connect(connectCfg.Values.ToArray());
                    }
                    else
                    {
                        throw new Exception(
                                  String.Format("Attempting to connect {0} to a non-CoalescingDevice {1}", connectCfg.Values.ToString(), ed));
                    }
                }

                devices.Add(ed);
            }


            foreach (IDAQStream s in streams)
            {
                //if the stream came from DAQController.GetStreams, we don't need to add it
                if (!daqController.Streams.Contains(s) && (daqController as IMutableDAQController != null))
                {
                    (daqController as IMutableDAQController).AddStream(s);
                }
            }


            daqController.Clock = clockProviders[daqControllerConfig.Clock] as IClock;
            InjectClock(controller, clockProviders);

            controller.DAQController = daqController;


            return(controller);
        }