/// <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; }
private void SetPTZControlFromCapabilities(CameraCapabilitiesAndLimits caps) { ChangingSelfValues = true; ptzControl.PanEnabled = caps.HasPan; ptzControl.TiltEnabled = caps.HasTilt; ptzControl.TiltAngleMaximum = caps.TiltMaxAngle; ptzControl.TiltAngleMinimum = caps.TiltMinAngle; ptzControl.TiltAngleCustomTicks = new double[] { caps.TiltMinAngle, 0, caps.TiltMaxAngle }; ptzControl.ZoomEnabled = caps.HasZoom; ptzControl.ZoomLevelMaximum = caps.ZoomMaxLevel; ptzControl.ZoomLevelMinimum = caps.ZoomMinLevel; ptzControl.ZoomLevelCustomTicks = new double[] { caps.ZoomMinLevel, 0, caps.ZoomMaxLevel }; ChangingSelfValues = false; }
/// <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); }
/// <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); }
public static ICameraControlClient Create(String serverAddress, StreamSourceInfo info) { ICameraControlClient result = null; if (info.CameraControl.PTZType == PTZType.Stacked) { StackedCameraControlClient client = new StackedCameraControlClient(); CameraControlClients.Protocol.IProtocol protocol; CameraControlClients.Transport.ITransport transport; if (info.CameraControl.Address != null) { UriBuilder uriBuilder = new UriBuilder(info.CameraControl.Address); if (uriBuilder.Scheme == "test1") { transport = new CameraControlClients.Transport.DebugTest1(info.CameraControl.Address); } else if (uriBuilder.Scheme == "vivotektunnel") { transport = new CameraControlClients.Transport.VivotekTunnel(info.CameraControl.Address); } else { throw new Exception("unknown camera control transport type"); } if (uriBuilder.Path.Contains("wca261")) { protocol = new CameraControlClients.Protocol.WonwooWCA261(client, transport); } else if (uriBuilder.Path.Contains("wcc261")) { protocol = new CameraControlClients.Protocol.WonwooWCC261(client, transport); } else { throw new Exception("unknown camera control protocol type"); } client.Protocol = protocol; CameraCapabilitiesAndLimits caps = new CameraCapabilitiesAndLimits(); caps.HasAbsoluteControls = protocol.HasAbsoluteControls; caps.HasPan = protocol.HasPan; caps.HasTilt = protocol.HasTilt; caps.HasZoom = protocol.HasZoom; caps.HasDigitalZoom = protocol.HasDigitalZoom; caps.HasEmitter = protocol.HasEmitter; caps.HasStabilizer = protocol.HasStabilizer; caps.HasInfrared = protocol.HasInfrared; caps.HasInverter = protocol.HasInverter; caps.HasWiper = protocol.HasWiper; caps.HasFocus = protocol.HasFocus; caps.PanLimitStart = protocol.PanLimitStart; caps.PanLimitAngle = protocol.PanLimitAngle; caps.PanOffset = protocol.PanOffset; caps.TiltMaxAngle = protocol.TiltMaxAngle; caps.TiltMinAngle = protocol.TiltMinAngle; caps.ZoomMaxLevel = protocol.ZoomMaxLevel; caps.ZoomMinLevel = protocol.ZoomMinLevel; caps.FieldOfView = protocol.FieldOfView; info.CameraControl.Capabilities = caps; result = client; } } else { result = new LegacyCameraControlClient(serverAddress); } return(result); }