public override Expression Build(IEnumerable <Expression> arguments)
        {
            var source = arguments.First();

            // Find upstream ONIControllers
            var visitor = new ControllerFinder();

            visitor.Visit(source);
            if (visitor.Controllers.Count == 0)
            {
                throw new Bonsai.WorkflowBuildException("Could not associate with upstream ONI hardware controller.");
            }

            Controller.Controllers = visitor.Controllers;

            if (Controller.SelectedController != null)
            {
                var devices = ONIHelpers.FindMachingDevices(Controller.SelectedController.AcqContext, ID);
                if (devices.Count == 0)
                {
                    throw new Bonsai.WorkflowBuildException("Device was not found in device table.");
                }
                DeviceIndex.Indices = devices.Keys.ToArray();
            }

            // Create Sink
            var thisType = GetType();
            var method   = thisType.GetMethod(nameof(Process));
            var instance = Expression.Constant(this);

            return(Expression.Call(instance, method, new[] { source }));
        }
Пример #2
0
        public override Expression Build(IEnumerable <Expression> arguments)
        {
            var source = arguments.First();

            // Find upstream ONIController
            var visitor = new ControllerFinder();

            visitor.Visit(source);
            if (visitor.Controllers.Count != 1)
            {
                // Never should contain more than 1 because must be attached to a frame source directly
                throw new Bonsai.WorkflowBuildException("ONI FrameReader Device is attached to multiple ONI controllers.");
            }

            Controller = visitor.Controllers[0];

            // Find valid device indices
            var devices = ONIHelpers.FindMachingDevices(Controller.AcqContext, ID);

            if (devices.Count == 0)
            {
                throw new Bonsai.WorkflowBuildException("Device was not found in device table.");
            }
            DeviceIndex.Indices = devices.Keys.ToArray();

            // Update device-specific clocks
            UpdateClocks();

            // Schedule clock update if device index changes
            DeviceIndex.IndexChanged += UpdateClocks;

            // Create combinator
            var thisType = GetType();
            var method   = thisType.GetMethod(nameof(Process));
            var instance = Expression.Constant(this);

            return(Expression.Call(instance, method, new[] { source }));
        }