public DeviceDescriptor Connect(string address) { int port = 4757; string ip = address; if (address.Contains(":")) { ip = address.Split(':')[0]; int.TryParse(address.Split(':')[1], out port); } DdClient client = new DdClient(); if (!client.Open(ip, port)) throw new Exception("No server was found!"); var devices = client.GetDevices(); if (devices.Count == 0) throw new Exception("No connected device was found!"); client.Connect(devices[0]); DdServerProtocol protocol = new DdServerProtocol(client); if (CameraDeviceManager.GetNativeDriver(protocol.Model) != null) { DeviceDescriptor descriptor = new DeviceDescriptor { WpdId = "ddserver" }; var cameraDevice = (ICameraDevice)Activator.CreateInstance(CameraDeviceManager.GetNativeDriver(protocol.Model)); descriptor.StillImageDevice = protocol; //cameraDevice.SerialNumber = StaticHelper.GetSerial(portableDevice.DeviceId); cameraDevice.Init(descriptor); descriptor.CameraDevice = cameraDevice; return descriptor; } else { throw new Exception("Not Supported device " + protocol.Model); } }
public void ConnectDevicesDDServer(string ip, int port) { if (_connectionInProgress) return; try { _connectionInProgress = true; _deviceEnumerator.RemoveDisconnected(); DdClient client = new DdClient(); if (!client.Open(ip, port)) throw new Exception("No server was found!"); var devices = client.GetDevices(); if (devices.Count == 0) throw new Exception("No connected device was found!"); client.Connect(devices[0]); DdServerProtocol protocol = new DdServerProtocol(client); if (GetNativeDriver(protocol.Model) != null) { ICameraDevice cameraDevice; DeviceDescriptor descriptor = new DeviceDescriptor {WpdId = "ddserver"}; cameraDevice = (ICameraDevice) Activator.CreateInstance(GetNativeDriver(protocol.Model)); descriptor.StillImageDevice = protocol; //cameraDevice.SerialNumber = StaticHelper.GetSerial(portableDevice.DeviceId); cameraDevice.Init(descriptor); ConnectedDevices.Add(cameraDevice); NewCameraConnected(cameraDevice); descriptor.CameraDevice = cameraDevice; _deviceEnumerator.Add(descriptor); } else { throw new Exception("Not Supported device " + protocol.Model); } } finally { _connectionInProgress = false; } }
public void ConnectDevicesDDServer(string ip, int port) { if (_connectionInProgress) return; try { _connectionInProgress = true; _deviceEnumerator.RemoveDisconnected(); DdClient client = new DdClient(); if (!client.Open(ip, port)) throw new Exception("No server was found!"); var devices = client.GetDevices(); if (devices.Count == 0) throw new Exception("No connected device was found!"); client.Connect(devices[0]); DdServerProtocol protocol = new DdServerProtocol(client); if (GetNativeDriver(protocol.Model) != null) { ICameraDevice cameraDevice; DeviceDescriptor descriptor = new DeviceDescriptor {WpdId = "ddserver"}; cameraDevice = (ICameraDevice) Activator.CreateInstance(GetNativeDriver(protocol.Model)); descriptor.StillImageDevice = protocol; //cameraDevice.SerialNumber = StaticHelper.GetSerial(portableDevice.DeviceId); cameraDevice.Init(descriptor); ConnectedDevices.Add(cameraDevice); NewCameraConnected(cameraDevice); descriptor.CameraDevice = cameraDevice; _deviceEnumerator.Add(descriptor); } foreach (PortableDevice portableDevice in PortableDeviceCollection.Instance.Devices) { Log.Debug("Connection device " + portableDevice.DeviceId); //TODO: avoid to load some mass storage in my computer need to find a general solution if (!portableDevice.DeviceId.StartsWith("\\\\?\\usb") && !portableDevice.DeviceId.StartsWith("\\\\?\\comp")) continue; // ignore some Canon cameras if (!SupportedCanonCamera(portableDevice.DeviceId)) continue; portableDevice.ConnectToDevice(AppName, AppMajorVersionNumber, AppMinorVersionNumber); if (_deviceEnumerator.GetByWpdId(portableDevice.DeviceId) == null && GetNativeDriver(portableDevice.Model) != null) { ICameraDevice cameraDevice; DeviceDescriptor descriptor = new DeviceDescriptor {WpdId = portableDevice.DeviceId}; cameraDevice = (ICameraDevice) Activator.CreateInstance(GetNativeDriver(portableDevice.Model)); MtpProtocol device = new MtpProtocol(descriptor.WpdId); device.ConnectToDevice(AppName, AppMajorVersionNumber, AppMinorVersionNumber); descriptor.StillImageDevice = device; cameraDevice.SerialNumber = StaticHelper.GetSerial(portableDevice.DeviceId); cameraDevice.Init(descriptor); ConnectedDevices.Add(cameraDevice); NewCameraConnected(cameraDevice); descriptor.CameraDevice = cameraDevice; _deviceEnumerator.Add(descriptor); } } } finally { _connectionInProgress = false; } }