private void ConnectDevices() { if (_connectionInProgress) { return; } _connectionInProgress = true; if (PortableDeviceCollection.Instance == null) { PortableDeviceCollection.CreateInstance(AppName, AppMajorVersionNumber, AppMinorVersionNumber); PortableDeviceCollection.Instance.AutoConnectToPortableDevice = false; } _deviceEnumerator.RemoveDisconnected(); if (UseExperimentalDrivers) { InitCanon(); } 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)); cameraDevice.SerialNumber = StaticHelper.GetSerial(portableDevice.DeviceId); NewCameraConnected(cameraDevice); cameraDevice.Init(descriptor); descriptor.CameraDevice = cameraDevice; _deviceEnumerator.Add(descriptor); ConnectedDevices.Add(cameraDevice); } } _connectionInProgress = false; }
private void ConnectDevices() { if (_connectionInProgress) { return; } _connectionInProgress = true; if (PortableDeviceCollection.Instance == null) { PortableDeviceCollection.CreateInstance(AppName, AppMajorVersionNumber, AppMinorVersionNumber); PortableDeviceCollection.Instance.AutoConnectToPortableDevice = false; } _deviceEnumerator.RemoveDisconnected(); Log.Debug("Connection device start"); try { var devices = PortableDeviceCollection.Instance.Devices; foreach (PortableDevice portableDevice in 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); if (string.IsNullOrWhiteSpace(cameraDevice.SerialNumber)) { cameraDevice.SerialNumber = StaticHelper.GetSerial(portableDevice.DeviceId); } ConnectedDevices.Add(cameraDevice); NewCameraConnected(cameraDevice); descriptor.CameraDevice = cameraDevice; _deviceEnumerator.Add(descriptor); } } } catch (Exception exception) { Log.Error("Unable to connect to cameras ", exception); } _connectionInProgress = false; }