Beispiel #1
0
        void UpdateDeviceInternal(UpdateDevice update)
        {
            CameraInstance selected = update.Body.Selected;
            bool           updated  = false;

            if (_state.Selected != null &&
                _state.Selected.FrameGrabber != null)
            {
                _state.Selected.FrameGrabber.StopCapture();
                _state.Selected.FrameGrabber.Dispose();

                _state.Selected = null;
            }

            foreach (object obj in new vision.CameraCollection())
            {
                using (vision.Camera camera = obj as vision.Camera)
                {
                    if ((!string.IsNullOrEmpty(selected.FriendlyName) && camera.Name == selected.FriendlyName) ||
                        (!string.IsNullOrEmpty(selected.DevicePath) && camera.Path == selected.DevicePath))
                    {
                        selected.FriendlyName               = camera.Name;
                        selected.DevicePath                 = selected.DevicePath;
                        selected.FrameGrabber               = vision.FrameGrabber.FromCamera(camera);
                        selected.SupportedFormats           = ConvertFormats(selected.FrameGrabber.Formats);
                        selected.FrameGrabber.CaptureFrame += OnCaptureFrame;
                        selected.FrameGrabber.StartCapture();
                        selected.Format = new Format(selected.FrameGrabber.Format);

                        updated = true;
                        break;
                    }
                }
            }
            if (updated)
            {
                _state.Selected = selected;

                update.ResponsePort.Post(DefaultUpdateResponseType.Instance);

                SendNotification(_submgrPort, update);
            }
            else
            {
                update.ResponsePort.Post(
                    Fault.FromCodeSubcodeReason(FaultCodes.Receiver,
                                                DsspFaultCodes.UnknownEntry,
                                                "Camera not found"
                                                )
                    );
            }
        }
Beispiel #2
0
        IEnumerator <ITask> GetInitialState(Srv1CameraState initialState)
        {
            Srv1CameraState state = new Srv1CameraState();

            state.CaptureFile = initialState.CaptureFile;
            state.Quality     = initialState.Quality;

            yield return(InitializeInternalService());

            foreach (object obj in new vision.CameraCollection())
            {
                using (vision.Camera camera = obj as vision.Camera)
                {
                    CameraInstance instance = new CameraInstance();
                    instance.FriendlyName     = camera.Name;
                    instance.DevicePath       = camera.Path;
                    instance.SupportedFormats = ConvertFormats(camera.Formats);

                    state.Cameras.Add(instance);
                }
            }

            state.Image = null;

            Replace replace = new Replace();

            replace.Body = state;
            _fwdPort.Post(replace);

            yield return(Arbiter.Choice(
                             replace.ResponsePort,
                             delegate(DefaultReplaceResponseType success) { },
                             delegate(Fault fault)
            {
                LogError(null, "Unable to set camera list", fault);
            }
                             ));

            UpdateDeviceRequest request = new UpdateDeviceRequest();

            if (initialState.Selected != null)
            {
                request.Selected = initialState.Selected;
            }
            else if (state.Cameras.Count > 0)
            {
                request.Selected = state.Cameras[0];
            }
            else
            {
                yield break;
            }
            UpdateDevice update = new UpdateDevice();

            update.Body = request;
            _fwdPort.Post(update);

            yield return(Arbiter.Choice(
                             update.ResponsePort,
                             delegate(DefaultUpdateResponseType success) { },
                             delegate(Fault fault)
            {
                LogError(null, "Unable to select camera", fault);
            }
                             ));

            if (initialState.Selected == null ||
                initialState.Selected.Format == null)
            {
                yield break;
            }

            UpdateFormat updateFormat = new UpdateFormat();

            updateFormat.Body = initialState.Selected.Format;

            _fwdPort.Post(updateFormat);

            yield return(Arbiter.Choice(
                             updateFormat.ResponsePort,
                             delegate(DefaultUpdateResponseType success) { },
                             delegate(Fault fault)
            {
                LogError(null, "Unable to select format", fault);
            }
                             ));
        }