Ejemplo n.º 1
0
        public static ONIDisposable ReserveDAQ(uint context_index = 0)
        {
            Tuple <ONIController, RefCountDisposable> oni_context;

            lock (openContextsLock)
            {
                if (!openContexts.TryGetValue(context_index, out oni_context)) // Context has not been opened yet
                {
                    ONIController oni;                                         // Does not call constructor
                    var           configuration = LoadConfiguration();
                    if (configuration.Contains(context_index))                 // There is a configuration file specifying non-default channel paths
                    {
                        var config = configuration[context_index];             // Nothing used yet
                        oni = new ONIController(config.ConfigurationPath, config.DataInputPath, config.SignalPath);
                    }
                    else
                    {
                        oni = new ONIController(); // Default params
                    }

                    var dispose = Disposable.Create(() =>
                    {
                        //oni.DAQ.Dispose(false);
                        openContexts.Remove(context_index);
                    });

                    var ref_count = new RefCountDisposable(dispose);
                    oni_context = Tuple.Create(oni, ref_count);
                    openContexts.Add(context_index, oni_context);
                    return(new ONIDisposable(oni, ref_count));
                }
            }

            return(new ONIDisposable(oni_context.Item1, oni_context.Item2.GetDisposable())); // New reference
        }
Ejemplo n.º 2
0
        public ONIDisposable(ONIController oni, IDisposable disposable)
        {
            if (oni == null)
            {
                throw new ArgumentNullException("oni");
            }

            if (disposable == null)
            {
                throw new ArgumentNullException("disposable");
            }

            Environment = oni;
            DAQ         = Environment.DAQ;
            resource    = disposable;
        }