Beispiel #1
0
 /// <summary>
 /// Instantiates a new instance of the plugin
 /// </summary>
 /// <param name="config">configuration information</param>
 /// <param name="cameraControl">owner camera control</param>
 public Visca(CameraControlInfo config, ICameraControl cameraControl)
 {
     CameraControl = cameraControl;
     Debug.WriteLine("CameraControls.Visca");
     _serialPort = new SerialPort(config.Address, 9600, Parity.None, 8, StopBits.One);
     _serialPort.Open();
     _serialPort.DiscardNull = false;
     _serialPort.DtrEnable   = true;
     _serialPort.ReadTimeout = 10000;
     Debug.WriteLine("CameraControls.Visca.Open opened = " + _serialPort.PortName);
     try
     {
         DeviceTypeInquire();
         SetServo(false);
         SetBrake(true);
         SetSlowMode(false);
     }
     catch (Exception exc)
     {
         Debug.WriteLine("Is there a camera attached?");
         _serialPort.Close();
         _serialPort.Dispose();
         _serialPort = null;
         throw exc;
     }
 }
Beispiel #2
0
        /// <summary>
        /// Creates a new instance of the PelcoD control class
        /// </summary>
        /// <param name="config">configuration for the camera and the method of communication</param>
        /// <param name="cameraControl">parent camera control class that will own this plugin</param>
        public PelcoD(CameraControlInfo config, ICameraControl cameraControl)
        {
            Debug.WriteLine("CameraControls.PelcoD.Load");

            _cameraControl = cameraControl;

            try
            {
                _config = config;
                string portName = ParsePortAndAddress(_config.Address);
                _serialPort = new SerialPort(portName, _baudRate, Parity.None, 8, StopBits.One);
                _serialPort.Open();
                _serialPort.DiscardNull = false;
                _serialPort.DtrEnable   = true;
                _serialPort.ReadTimeout = 10000;

                Debug.WriteLine("CameraControls.PelcoD.Open opened = " + _serialPort.PortName + " @ " + _baudRate + " baud");
            }
            catch (Exception exc)
            {
                ErrorLogger.DumpToDebug(exc);
                throw new Exception("Unable to open serial port", exc);
            }

            _capabilities = _config.Capabilities;
        }
Beispiel #3
0
        /// <summary>
        /// Loads the plugin
        /// </summary>
        /// <param name="config">configuration to use</param>
        public void Open(CameraControlInfo config)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            Plugin       = PluginFactory.Create(config, this);
            CameraConfig = config;
        }
Beispiel #4
0
        /// <summary>
        /// Creates an instance of the plugin
        /// </summary>
        /// <param name="config">configuration information</param>
        /// <param name="cameraControl">owning camera control</param>
        public WonwooWCC261(CameraControlInfo config, ICameraControl cameraControl)
            : base(config, cameraControl)
        {
            _serialPort.Handshake = Handshake.None;
            _serialPort.DtrEnable = false;
            _serialPort.RtsEnable = true;

            _stopTimerDelegate = new TimerCallback(SendStopCommand);
            _stopTimer         = new Timer(_stopTimerDelegate, null, Timeout.Infinite, Timeout.Infinite);

            BuildIndexingArray();
        }
Beispiel #5
0
 /// <summary>
 /// Creates a new instance of the test plugin
 /// </summary>
 /// <param name="config">configuration</param>
 /// <param name="cameraControl">owning parent camera control</param>
 public Test1(CameraControlInfo config, ICameraControl cameraControl)
 {
     try
     {
         _cameraControl = cameraControl;
         Debug.WriteLine("CameraControls.Test1.Load");
         Thread.Sleep(1000); // some fake delay to emulate start/stop of SerialPort
     }
     catch (Exception exc)
     {
         ErrorLogger.DumpToDebug(exc);
     }
 }
Beispiel #6
0
        /// <summary>
        /// Creates a camera control plugin based on the given <see cref="T:CameraControlInfo"/>
        /// </summary>
        /// <param name="config">Camera control configuration. The type of plugin generated is determined by the <see cref="F:CameraControlInfo.PTZType"/> field.</param>
        /// <param name="cameraControl">owning camera control service</param>
        /// <returns>A plugin for the specified configuration. Note: some configurations could return null.</returns>
        /// <exception cref="T:SourceConfigException">Thrown if an unrecognized or unsupported <see cref="T:PTZType"/> is contained by the configuration.</exception>
        public static ICameraControlPlugin Create(CameraControlInfo config, ICameraControl cameraControl)
        {
            ICameraControlPlugin plugin;

            switch (config.PTZType)
            {
            case PTZType.Visca:
                plugin = new CameraControls.Visca(config, cameraControl);
                break;

            case PTZType.ViscaTest1:
                plugin = new CameraControls.ViscaTest1(config, cameraControl);
                break;

            case PTZType.Null:
                plugin = null;
                Debug.WriteLine("using Null camera control plugin");
                break;

            case PTZType.PelcoD:
                plugin = new CameraControls.PelcoD(config, cameraControl);
                break;

            case PTZType.WWCC:
                plugin = new CameraControls.WonwooWCC261(config, cameraControl);
                break;

            case PTZType.WWCA:
                plugin = new CameraControls.WonwooWCA261(config, cameraControl);
                break;

            case PTZType.Test1:
                plugin = new CameraControls.Test1(config, cameraControl);
                break;

            default:
                throw new SourceConfigException("Unsupported PTZ type (" + config.PTZType.ToString() + ")");
            }
            if (plugin != null)
            {
                Debug.WriteLine("CameraControls.PluginFactory.Create created " + plugin.ToString());
            }
            return(plugin);
        }
Beispiel #7
0
        public void Open(ClientConnectRequest request)
        {
            try
            {
                clientRequest = request;
                AppLogger.Message(request.UserName + " CameraControlService.Open " + request.SourceName);

                StreamSourceInfo sourceConfig = StreamSources.LoadFromFile().FindSource(request.SourceName);
                if (sourceConfig.CameraControl == null)
                {
                    throw new SourceConfigException("Source does not have CameraControl defined!");
                }

                //lock against the camera control address -- this allows multiple sources to share the same camera.
                //    if the particular camera control does not require an address, then lock against the source name
                this.ResourceID = string.IsNullOrEmpty(sourceConfig.CameraControl.Address) ?
                                  request.SourceName :
                                  sourceConfig.CameraControl.Address;

                if (!ResourceManager.Acquire <ResourceManager.MutexRule>(this.ResourceID,
                                                                         typeof(CameraControlService),
                                                                         request.UserName))
                {
                    string owner = ResourceManager.GetOwner(this.ResourceID, typeof(CameraControlService));
                    throw new SourceHasMaxClientsException("The camera control is in use by " +
                                                           (string.IsNullOrEmpty(owner) ? "<unknown>" : owner) + ".");
                }
                resourceAcquired = true;

                CameraControl = sourceConfig.CameraControl;
                Plugin        = CameraControls.PluginFactory.Create(CameraControl, this);
                LoadSavedPositions();
            }
            catch (Exception exc)
            {
                AppLogger.Dump(exc);
                //throw new Exception("Unable to open camera control for " + sourceName, exc);
                throw;
            }
        }
Beispiel #8
0
 /// <summary>
 /// Creates an instance of this plugin
 /// </summary>
 /// <param name="config">configuration information</param>
 /// <param name="cameraControl">owning camera control</param>
 public WonwooWCA261(CameraControlInfo config, ICameraControl cameraControl) : base(config, cameraControl)
 {
 }
Beispiel #9
0
        /// <summary>
        /// Connects to given address and parses xml to extract all IP addresses
        /// of all nodes advertising given service type
        /// </summary>
        /// <param name="type">Type of service to retrieve.</param>
        /// <param name="address">IP address to get xml from - Note that the file /xml/services is added onto this IP.</param>
        /// <param name="exc">If an exception was thrown while retrieving services, it is returned here.</param>
        /// <returns>list of Advertised Service Objects</returns>
        public static List <SourceDiscoveryGroup> Query(String url, String username, String password)
        {
            List <SourceDiscoveryGroup> result = new List <SourceDiscoveryGroup>();
            XDocument doc = XDocument.Load(url);
            IEnumerable <XElement> groups = doc.Element("SourceGroups").Elements("SourceGroup");

            foreach (XElement group in groups)
            {
                SourceDiscoveryGroup sourceGroup = new SourceDiscoveryGroup();
                sourceGroup.Version = Int32.Parse(group.Attribute("Version").Value);
                sourceGroup.Name    = group.Attribute("Name").Value;
                IEnumerable <XElement> sources = group.Elements("StreamSourceInfo");
                foreach (XElement xmlSource in sources)
                {
                    try
                    {
                        StreamSourceInfo source = new StreamSourceInfo();
                        source.SourceName  = xmlSource.Attribute("SourceName").Value;
                        source.Description = xmlSource.Attribute("Description").Value;
                        if (xmlSource.Attribute("ClientURL") != null)
                        {
                            source.SinkAddress = xmlSource.Attribute("ClientURL").Value;
                        }
                        else if (xmlSource.Attribute("SinkAddress") != null)
                        {
                            source.SinkAddress = xmlSource.Attribute("SinkAddress").Value;
                        }
                        if (xmlSource.Attribute("HasAudio") != null)
                        {
                            if (xmlSource.Attribute("HasAudio").Value == "1")
                            {
                                source.HasAudio = true;
                            }
                        }
                        XElement xmlCameraControl = xmlSource.Element("CameraControl");
                        if (xmlCameraControl != null)
                        {
                            CameraControlInfo info = new CameraControlInfo();
                            info.PTZType = (PTZType)Enum.Parse(typeof(PTZType), xmlCameraControl.Attribute("PTZType").Value);
                            XElement xmlCaps = xmlCameraControl.Element("Capabilities");
                            if (xmlCaps != null)
                            {
                                info.Capabilities = CameraCapabilitiesAndLimits.CreateFromXml(xmlCaps);
                            }
                            XElement xmlAddress = xmlCameraControl.Element("Address");
                            if (xmlAddress != null)
                            {
                                info.Address = xmlAddress.Value;
                            }
                            source.CameraControl = info;
                        }
                        sourceGroup.Sources.Add(source);
                    }
                    catch (Exception e)
                    {
                        ErrorLogger.DumpToDebug(e);
                    }
                }
                result.Add(sourceGroup);
            }
            return(result);
        }
Beispiel #10
0
        /// <summary>
        /// Connects to given address and parses xml to extract all IP addresses
        /// of all nodes advertising given service type
        /// </summary>
        /// <param name="type">Type of service to retrieve.</param>
        /// <param name="address">IP address to get xml from - Note that the file /xml/services is added onto this IP.</param>
        /// <param name="exc">If an exception was thrown while retrieving services, it is returned here.</param>
        /// <returns>list of Advertised Service Objects</returns>
        public static List <SourceDiscoveryGroup> ReadFile(String path)
        {
            List <SourceDiscoveryGroup> result = new List <SourceDiscoveryGroup>();
            XDocument doc = XDocument.Load(path);
            IEnumerable <XElement> groups = doc.Element("SourceGroups").Elements("SourceGroup");

            foreach (XElement group in groups)
            {
                SourceDiscoveryGroup sourceGroup = new SourceDiscoveryGroup();
                ServerInfo           serverInfo  = new ServerInfo();
                serverInfo.ServerName    = "Local";
                serverInfo.ServerAddress = "127.0.0.1";
                sourceGroup.ServerInfo   = serverInfo;
                sourceGroup.Version      = Int32.Parse(group.Attribute("Version").Value);
                sourceGroup.Name         = group.Attribute("Name").Value;
                IEnumerable <XElement> sources = group.Elements("StreamSourceInfo");
                foreach (XElement xmlSource in sources)
                {
                    StreamSourceInfo source = new StreamSourceInfo();
                    source.SourceName = xmlSource.Attribute("Name").Value;
                    XAttribute sourceTypeAttribute = xmlSource.Attribute("SourceType");
                    if (sourceTypeAttribute != null)
                    {
                        source.SourceType = (SourceType)Enum.Parse(typeof(SourceType), sourceTypeAttribute.Value);
                    }
                    else
                    {
                        source.SourceType = SourceType.RTSP;
                    }
                    source.Description = xmlSource.Attribute("Description").Value;
                    if (xmlSource.Attribute("SinkAddress") != null)
                    {
                        source.SinkAddress = xmlSource.Attribute("SinkAddress").Value;
                    }
                    else if (xmlSource.Attribute("ClientURL") != null)
                    {
                        source.SinkAddress = xmlSource.Attribute("ClientURL").Value;
                    }
                    if (source.SinkAddress.StartsWith(@"rtsp://"))
                    {
                        if ((xmlSource.Attribute("SourceType") != null) && xmlSource.Attribute("SourceType").Value == "RTSP_Elecard")
                        {
                            source.SourceType = SourceType.RTSP_Elecard;
                        }
                        else
                        {
                            source.SourceType = SourceType.RTSP;
                        }
                    }
                    if (xmlSource.Element("CameraControl") != null)
                    {
                        XElement          xmlCameraControl = xmlSource.Element("CameraControl");
                        CameraControlInfo info             = new CameraControlInfo();
                        info.PTZType = (PTZType)Enum.Parse(typeof(PTZType), xmlCameraControl.Attribute("PTZType").Value);
                        XElement xmlCaps = xmlCameraControl.Element("Capabilities");
                        if (xmlCaps != null)
                        {
                            info.Capabilities = CameraCapabilitiesAndLimits.CreateFromXml(xmlCaps);
                        }
                        XElement xmlAddress = xmlCameraControl.Element("Address");
                        if (xmlAddress != null)
                        {
                            info.Address = xmlAddress.Value;
                        }
                        source.CameraControl = info;
                    }
                    sourceGroup.Sources.Add(source);
                }
                result.Add(sourceGroup);
            }
            return(result);
        }
Beispiel #11
0
        private void btnStartStop_MouseClick(object sender, MouseEventArgs e)
        {
            if (btnStartStop.Text.Contains("Start"))
            {
                ClearInterface();
                InitInterface();
                this.Cursor = Cursors.WaitCursor;

                btnStartStop.BackColor = Color.Red;
                btnStartStop.Text      = "Stop";

                if (serverClient != null)
                {
                    btnStartStop.BackColor = Color.Orange;
                    btnStartStop.Text      = "Connecting... (Stop)";
                    SetEnabled(false);

                    try
                    {
                        serverClient.Opened += new EventHandler(cameraControlClient_Opened);
                        serverClient.Open(new ClientConnectRequest(config.SourceName));
                        serverClient.PropertyChanged += new PropertyChangedEventHandler(currentClient_PropertyChanged);
                    }
                    catch (Exception ex)
                    {
                        ErrorLogger.DumpToDebug(ex);
                        MessageBox.Show(ex.ToString(), "Error opening camera control client!");
                        btnStartStop_MouseClick();
                    }
                }
                else if (pluginClient != null)
                {
                    btnStartStop.BackColor = Color.Red;
                    btnStartStop.Text      = "Stop";

                    try
                    {
                        CameraControlInfo cameraConfig = new CameraControlInfo();
                        cameraConfig.Address = config.Address;
                        cameraConfig.PTZType = config.PTZType;

                        cameraConfig.Capabilities = new CameraCapabilitiesAndLimits();
                        cameraConfig.Capabilities.HasDigitalZoom = true;
                        cameraConfig.Capabilities.HasFocus       = true;
                        cameraConfig.Capabilities.HasPan         = true;
                        cameraConfig.Capabilities.HasTilt        = true;
                        cameraConfig.Capabilities.HasZoom        = true;

                        switch (config.PTZType)
                        {
                        case PTZType.Visca:
                            cameraConfig.Capabilities.HasEmitter    = true;
                            cameraConfig.Capabilities.HasInfrared   = true;
                            cameraConfig.Capabilities.HasInverter   = true;
                            cameraConfig.Capabilities.HasStabilizer = true;
                            cameraConfig.Capabilities.HasWiper      = true;
                            cameraConfig.Capabilities.TiltMaxAngle  = 90;
                            cameraConfig.Capabilities.TiltMinAngle  = -37;
                            cameraConfig.Capabilities.ZoomMinLevel  = 1;
                            cameraConfig.Capabilities.ZoomMaxLevel  = 37;
                            break;

                        case PTZType.PelcoD:
                            cameraConfig.Capabilities.HasEmitter    = false;
                            cameraConfig.Capabilities.HasInfrared   = false;
                            cameraConfig.Capabilities.HasInverter   = false;
                            cameraConfig.Capabilities.HasStabilizer = false;
                            cameraConfig.Capabilities.HasWiper      = false;
                            cameraConfig.Capabilities.TiltMaxAngle  = 90;
                            cameraConfig.Capabilities.TiltMinAngle  = -45;
                            cameraConfig.Capabilities.ZoomMinLevel  = 1;
                            cameraConfig.Capabilities.ZoomMaxLevel  = 26;
                            break;

                        case PTZType.WWCC:
                        case PTZType.WWCA:
                            cameraConfig.Capabilities.HasEmitter    = false;
                            cameraConfig.Capabilities.HasInfrared   = false;
                            cameraConfig.Capabilities.HasInverter   = false;
                            cameraConfig.Capabilities.HasStabilizer = false;
                            cameraConfig.Capabilities.HasWiper      = false;
                            cameraConfig.Capabilities.TiltMaxAngle  = 45;
                            cameraConfig.Capabilities.TiltMinAngle  = -45;
                            cameraConfig.Capabilities.ZoomMinLevel  = -20;
                            cameraConfig.Capabilities.ZoomMaxLevel  = 20;
                            break;
                        }

                        SetPTZControlFromCapabilities(cameraConfig.Capabilities);

                        DialogResult r;
                        if (promptForInitialize == DialogResult.Cancel)
                        {
                            r = MessageBox.Show("Would you like to call Initialize() on the plugin?", "Call Initialize()?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                        }
                        else
                        {
                            r = promptForInitialize;
                        }

                        pluginClient.PropertyChanged += new PropertyChangedEventHandler(currentClient_PropertyChanged);
                        pluginClient.Open(cameraConfig);

                        if (r == DialogResult.Yes)
                        {
                            pluginClient.Initialize();
                        }

                        SetEnabled(true);
                        this.Cursor = Cursors.Default;
                    }
                    catch (Exception ex)
                    {
                        ErrorLogger.DumpToDebug(ex);
                        MessageBox.Show(ex.ToString(), "Error loading or initializing Plugin!");
                        btnStartStop_MouseClick();
                        this.Cursor = Cursors.Default;
                    }
                }
            }
            else if (btnStartStop.Text.Contains("Stop"))
            {
                ClearInterface();

                SetEnabled(false);
                btnStartStop.BackColor = Color.Green;
                btnStartStop.Text      = "Start";
            }
        }
Beispiel #12
0
        private void InitControls(CameraControlInfo cc)
        {
            if (cc == null)
            {
                throw new ArgumentNullException("CameraCapabilitiesAndLimits may not be null!");
            }

            B_Emitter.Visible    = cc.Capabilities.HasEmitter;
            B_Infrared.Visible   = cc.Capabilities.HasInfrared;
            B_Invert.Visible     = cc.Capabilities.HasInverter;
            B_Stabilizer.Visible = cc.Capabilities.HasStabilizer;
            B_Wiper.Visible      = cc.Capabilities.HasWiper;

            ptzControl.PanEnabled  = cc.Capabilities.HasPan;
            ptzControl.TiltEnabled = cc.Capabilities.HasTilt;
            ptzControl.ZoomEnabled = cc.Capabilities.HasZoom;

            ptzFavoritesControl.Visible = cc.Capabilities.HasAbsoluteControls;

            if (cc.Capabilities.HasEmitter)
            {
                client.EmitterEnabled = false;
                B_Emitter.ImageIndex  = 0;
            }
            if (cc.Capabilities.HasInfrared)
            {
                client.InfraredEnabled = false;
                B_Infrared.ImageIndex  = 0;
            }
            if (cc.Capabilities.HasInverter)
            {
                client.InvertedEnabled = false;
                B_Invert.ImageIndex    = 0;
            }
            if (cc.Capabilities.HasStabilizer)
            {
                client.StabilizerEnabled = true;
                B_Stabilizer.ImageIndex  = 1;
            }
            if (cc.Capabilities.HasWiper)
            {
                client.WiperEnabled = false;
                B_Wiper.ImageIndex  = 0;
            }

            ArrangePTZOptions();

            ChangingSelfValues = true;

            //set pan angle
            ptzControl.PanAngle       = client.CurrentPanAngle;
            ptzControl.PanAngleOffset = cc.Capabilities.PanOffset;

            //set the tilt level
            ptzControl.TiltAngle = client.CurrentTiltAngle;

            ptzControl.TiltAngleMinimum     = cc.Capabilities.TiltMinAngle;
            ptzControl.TiltAngleMaximum     = cc.Capabilities.TiltMaxAngle;
            ptzControl.TiltAngleCustomTicks = new double[] { ptzControl.TiltAngleMinimum, 0, ptzControl.TiltAngleMaximum };

            //set field of view
            ptzControl.CameraFieldOfView = cc.Capabilities.FieldOfView;

            //set zoom level
            ptzControl.ZoomLevel = client.CurrentZoomPosition;

            ptzControl.ZoomLevelMinimum       = cc.Capabilities.ZoomMinLevel;
            ptzControl.ZoomLevelMaximum       = cc.Capabilities.ZoomMaxLevel;
            ptzControl.ZoomLevelTickFrequency = 10;

            ChangingSelfValues = false;

            if (ptzControl.GetCurrentFieldOfView() != 0)
            {
                this.StreamViewerControl.PTZOverlayControl                = new ClickToCenter();
                this.StreamViewerControl.PTZOverlayControl.FieldOfView    = ptzControl.GetCurrentFieldOfView();
                this.StreamViewerControl.PTZOverlayControl.MoveRequested += new EventHandler <PTZMoveRequestEventArgs>(PTZOverlayControl_MoveRequested);
                this.StreamViewerControl.PTZOverlayControl.Enabled        = true;
            }
        }
Beispiel #13
0
 /// <summary>
 /// Instantiates a new instance of this plugin
 /// </summary>
 /// <param name="config">configuration information</param>
 /// <param name="cameraControl">owning camera control</param>
 public ViscaTest1(CameraControlInfo config, ICameraControl cameraControl)
 {
     CameraControl = cameraControl;
     Debug.WriteLine("CameraControls.ViscaTest1.Initialize");
 }