コード例 #1
0
        static string FindNikonCamera()
        {
            if (PortableDeviceCollection.Instance == null)
            {
                const string AppName = "CameraControl";
                const int    AppMajorVersionNumber = 1;
                const int    AppMinorVersionNumber = 0;

                PortableDeviceCollection.CreateInstance(AppName, AppMajorVersionNumber, AppMinorVersionNumber);
                PortableDeviceCollection.Instance.AutoConnectToPortableDevice = false;
            }
            //_deviceEnumerator.RemoveDisconnected();

            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;
                }

                // find Nikon cameras
                if (portableDevice.DeviceId.Contains("vid_04b0"))
                {
                    return(portableDevice.DeviceId);
                }
            }

            return("");
        }
コード例 #2
0
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     if (PortableDeviceCollection.Instance == null)
     {
         PortableDeviceCollection.CreateInstance(AppName, AppMajorVersionNumber, AppMinorVersionNumber);
         PortableDeviceCollection.Instance.AutoConnectToPortableDevice = false;
     }
     foreach (PortableDevice portableDevice in PortableDeviceCollection.Instance.Devices)
     {
         portableDevice.ConnectToDevice(AppName, AppMajorVersionNumber, AppMinorVersionNumber);
         Devices.Add(portableDevice);
     }
     cmb_devices.ItemsSource = Devices;
 }
コード例 #3
0
        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;
        }
コード例 #4
0
ファイル: Base.cs プロジェクト: hibive/nikon-firmware-tools
        public bool FindNikonCamera()
        {
            if (PortableDeviceCollection.Instance == null)
            {
                const string AppName = "CameraControl";
                const int    AppMajorVersionNumber = 1;
                const int    AppMinorVersionNumber = 0;

                try {
                    PortableDeviceCollection.CreateInstance(AppName, AppMajorVersionNumber, AppMinorVersionNumber);
                    PortableDeviceCollection.Instance.AutoConnectToPortableDevice = false;
                }catch (Exception)
                {
                    StatusMessage = "Failed to load depentant .dll's";
                    return(false);
                }
            }

            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;
                }

                // find Nikon cameras
                if (portableDevice.DeviceId.Contains("vid_04b0"))
                {
                    deviceId = portableDevice.DeviceId;
                    try
                    {
                        SerialNumber = deviceId.Split('#')[2];
                    }
                    catch (Exception)
                    {
                        StatusMessage = "Failed to find Serial Number";
                        return(false);
                    }

                    return(true);
                }
            }

            StatusMessage = "Failed to Find Nikon Camera";
            deviceId      = "";
            return(false);
        }
コード例 #5
0
        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;
        }
コード例 #6
0
ファイル: Service1.cs プロジェクト: wyfbit/MtpBasedWCFService
        ///循环监测是否有Pad插入
        private void LoopDetection()
        {
            //LogHelper.LogWrite("MTP服务开启!");
            //创建同步历史记录XML


            while (true)
            {
                ///获取接入的Pad信息
                portableDevices = new ObservableCollection <PortableDevice>();

                if (PortableDeviceCollection.Instance == null)
                {
                    try
                    {
                        PortableDeviceCollection.CreateInstance(AppName, AppMajorVersionNumber, AppMinorVersionNumber);
                        PortableDeviceCollection.Instance.AutoConnectToPortableDevice = false;
                    }
                    catch (Exception ex)
                    {
                        LogHelper.LogWrite(ex.Message);
                    }
                }
                ///添加Pad设备,一次只能接入一个Pad设备
                foreach (var device in PortableDeviceCollection.Instance.Devices)
                {
                    if (device.DeviceId == padOne || device.DeviceId == padTwo)
                    {
                        portableDevices.Add(device);
                    }
                }
                if (portableDevices.Count >= 1)//需增加判断,是否远程WCF服务已开启??
                {
                    if ((portableDevices[0].DeviceId == padOne || portableDevices[0].DeviceId == padTwo) && isUpdateComplete == false)
                    {
                        foreach (var portableDevice in portableDevices)
                        {
                            string[] paths = padSourcePath.Split('\\');
                            try
                            {
                                portableDevice.ConnectToDevice(AppName, AppMajorVersionNumber, AppMinorVersionNumber);
                            }
                            catch//(Exception ex)
                            {
                                //LogHelper.LogWrite(ex.Message);
                                continue;
                            }
                            portableDevice.ScanContent(paths);


                            PortableDeviceContainerObject lastObj = portableDevice.GetLast(portableDevice.Content);

                            if (lastObj.Name == "uploadRefresh")
                            {
                                portableDevice.ScanFolderEnumerate(lastObj.ID, lastObj);

                                //从Pad向PC复制文件
                                try
                                {
                                    portableDevice.CopyFolderToPC(lastObj, pcTargetFolder);
                                }
                                catch (Exception ex)
                                {
                                    LogHelper.LogWrite(ex);
                                }


                                ///查找Pad端指定位置
                                string[] paths1 = padTargetFolder.Split('\\');

                                portableDevice.ScanContent(paths1);

                                lastObjDown = portableDevice.GetLast(portableDevice.Content);

                                //find the all files in the last folder
                                portableDevice.ScanFolderEnumerate(lastObjDown.ID, lastObjDown);

                                //copy folder from pc to pad
                                //portableDevice.CopyFolderToPad(lastObjDown, pcSourceFolder);
                                if (Directory.Exists(pcTargetFolder + "\\uploadRefresh"))
                                {
                                    ///执行数据更新工作
                                    StartUpdateDate();
                                }


                                bool complete = true;
                                ///判断是否更新成功
                                do
                                {
                                    if (n == 6)
                                    {
                                        ///上传同步记录
                                        if (portableDevices[0].DeviceId == padOne)
                                        {
                                            portableDevices[0].CopyFolderToPad(lastObjDown, historyRecordXmlOne);
                                        }
                                        if (portableDevices[0].DeviceId == padTwo)
                                        {
                                            portableDevices[0].CopyFolderToPad(lastObjDown, historyRecordXmlTwo);
                                        }

                                        ///上传结束标志文件
                                        using (FileStream wcfFile = new FileStream(wcfdownloadpath + "time.xml", FileMode.Create))
                                        {
                                            byte[] bytes = new byte[0];
                                            wcfFile.Write(bytes, 0, bytes.Length);
                                            wcfFile.Flush();
                                        }
                                        try
                                        {
                                            portableDevices[0].CopyFolderToPad(lastObjDown, wcfdownloadpath + "time.xml");
                                        }
                                        catch (Exception ex)
                                        {
                                            LogHelper.LogWrite(ex.Message);
                                        }
                                        complete = false;
                                        n        = 0;
                                        if (wcfclient != null)
                                        {
                                            try
                                            {
                                                wcfclient.Close();
                                            }
                                            catch (Exception ex)
                                            {
                                                wcfclient.Abort();
                                                LogHelper.LogWrite(ex);
                                            }
                                        }
                                    }
                                    Thread.Sleep(100);
                                }while (complete);

                                isUpdateComplete = true;
                            }
                        }
                    }
                }
                if (portableDevices.Count == 0)
                {
                    isUpdateComplete = false;
                }
                if (portableDevices != null)
                {
                    portableDevices = null;
                }

                GC.Collect();
                Thread.Sleep(100);
            }
        }
コード例 #7
0
 private static PortableDeviceCollection CreatePortableDeviceCollectionFromApplicationInformation(ApplicationInformation applicationInformation)
 {
     PortableDeviceCollection.CreateInstance(applicationInformation.Name, applicationInformation.MajorVersionNumber, applicationInformation.MinorVersionNumber);
     PortableDeviceCollection.Instance.AutoConnectToPortableDevice = false;
     return(PortableDeviceCollection.Instance);
 }