Exemplo n.º 1
0
        public void Setup()
        {
            visca = new ViscaProtocolProcessor(
                new Action <byte[]>(b =>
            {
                sendQueue.Add(b);
            }),
                new Action <byte, string, object[]>((l, f, o) =>
            {
                Console.WriteLine("CAMERA LOG:[{0}]", String.Format(f, o));
            })
                );

            camera = new ViscaCamera(ViscaCameraId.Camera1, null, visca);
        }
Exemplo n.º 2
0
        /// <summary>
        /// CameraVisca Plugin device constructor using IBasicCommunication
        /// </summary>
        /// <param name="key"></param>
        /// <param name="name"></param>
        /// <param name="config"></param>
        /// <param name="comms"></param>
        public CameraVisca(string key, string name, CameraViscaConfig config, IBasicCommunication comm)
            : base(key, name)
        {
            Debug.Console(0, this, "Constructing new {0} instance", name);

            _config = config;
            Enabled = _config.Enabled;

            _visca = new ViscaProtocolProcessor(comm.SendBytes, new Action <byte, string, object[]>((l, f, o) =>
            {
                Debug.Console(l, this, f, o);
            }));

            _camera             = new ViscaCamera((ViscaCameraId)_config.Id, null, _visca);
            _camera.PollEnabled = Enabled;

            Capabilities = eCameraCapabilities.Pan | eCameraCapabilities.Tilt | eCameraCapabilities.Zoom | eCameraCapabilities.Focus;
            ControlMode  = eCameraControlMode.Auto;

            ConnectFeedback       = new BoolFeedback(() => Connect);
            OnlineFeedback        = new BoolFeedback(() => _commsMonitor.IsOnline);
            StatusFeedback        = new IntFeedback(() => (int)_commsMonitor.Status);
            PowerIsOnFeedback     = new BoolFeedback(() => _camera.Power);
            CameraIsOffFeedback   = new BoolFeedback(() => !_camera.Power);
            CameraIsMutedFeedback = new BoolFeedback(() => _camera.Mute);

            _camera.PowerChanged += (o, e) => { PowerIsOnFeedback.FireUpdate(); CameraIsOffFeedback.FireUpdate(); };
            _camera.MuteChanged  += (o, e) => { CameraIsMutedFeedback.FireUpdate(); };

            _cameraPollCommands = new Dictionary <string, Action>()
            {
                { "AE", _camera.AEPoll },
                { "Aperture", _camera.AperturePoll },
                { "BackLight", _camera.BackLightPoll },
                { "BGain", _camera.BGainPoll },
                { "ExpComp", _camera.ExpCompPoll },
                { "FocusAuto", _camera.FocusAutoPoll },
                { "FocusPosition", _camera.FocusPositionPoll },
                { "Gain", _camera.GainPoll },
                { "Iris", _camera.IrisPoll },
                { "Mute", _camera.MutePoll },
                { "PTZPosition", _camera.PanTiltPositionPoll },
                { "Power", _camera.PowerPoll },
                { "RGain", _camera.RGainPoll },
                { "Shutter", _camera.ShutterPoll },
                { "Title", _camera.TitlePoll },
                { "WB", _camera.WBModePoll },
                { "WD", _camera.WideDynamicModePoll },
                { "ZoomPosition", _camera.ZoomPositionPoll },
            };

            _comms = comm;

            // TODO: For VISCA camera current library implementation only
            // serial is supported, so socket code is not needed
            var socket = _comms as ISocketStatus;

            if (socket != null)
            {
                socket.ConnectionChange += socket_ConnectionChange;
                if (Enabled)
                {
                    Connect = true;
                }
            }

            if (_config.CommunicationMonitorProperties != null)
            {
                if (!String.IsNullOrEmpty(_config.CommunicationMonitorProperties.PollString))
                {
                    foreach (var poll in _config.CommunicationMonitorProperties.PollString.Split(','))
                    {
                        if (_cameraPollCommands.ContainsKey(poll.Trim()))
                        {
                            _poll.Add(_cameraPollCommands[poll.Trim()]);
                        }
                    }
                }

                _commsMonitor = new GenericCommunicationMonitor(this, _comms,
                                                                _config.CommunicationMonitorProperties.PollInterval,
                                                                _config.CommunicationMonitorProperties.TimeToWarning,
                                                                _config.CommunicationMonitorProperties.TimeToError,
                                                                () => _poll.ForEach((pollAction) => pollAction())
                                                                );
            }
            else
            {
                // We do not have CommunicationMonitorProperties and therefore
                // no Poll string defined, using ALL poll functions
                _poll.AddRange(_cameraPollCommands.Values);
                _commsMonitor = new GenericCommunicationMonitor(this, _comms, 10000, 20000, 30000, () => _poll.ForEach((pollAction) => pollAction()));
            }

            _commsMonitor.Client.BytesReceived += (s, e) => _visca.ProcessIncomingData(e.Bytes);
            DeviceManager.AddDevice(CommunicationMonitor);

            // Handle Increase PTZ move speed
            #region PTZ Speed Increase

            // if FastSpeedHoldTimeMs defined in config, enable SpeedIncrease behaivor
            if (_config.FastSpeedHoldTimeMs > 0)
            {
                _ptzSpeedIncreaseBehaivor = true;

                if (_config.PanSpeedSlow > 0)
                {
                    _camera.PanSpeed = _config.PanSpeedSlow;
                }

                if (_config.TiltSpeedSlow > 0)
                {
                    _camera.TiltSpeed = _config.TiltSpeedSlow;
                }

                _ptzPanNormalSpeed  = _camera.PanSpeed;
                _ptzTiltNormalSpeed = _camera.TiltSpeed;

                _ptzSpeedIncreaseAction = ptzCommand =>
                {
                    // Kill Speed Increase Timer as we already in fast pace
                    ptzSpeedChangeTimerDispose();
                    // if Fast speeds not defined, use Max values
                    _camera.PanSpeed  = (_config.PanSpeedFast > 0) ? _config.PanSpeedFast : Visca.ViscaDefaults.PanSpeedLimits.High;
                    _camera.TiltSpeed = (_config.TiltSpeedFast > 0) ? _config.PanSpeedFast : Visca.ViscaDefaults.TiltSpeedLimits.High;
                    // we passed current ptz command to action, so we repeat it with increased speed
                    (ptzCommand as Action).Invoke();
                };
            }

            #endregion PTZ Speed Increase
        }