public void ConnectDevicesPtpIp(string ip, int port)
        {
            if (_connectionInProgress)
            {
                return;
            }
            try
            {
                _connectionInProgress = true;
                _deviceEnumerator.RemoveDisconnected();

                PtpIpClient client = new PtpIpClient();
                if (!client.Open(ip, 15740))
                {
                    throw new Exception("No server was found!");
                }
                PtpIpProtocol protocol = new PtpIpProtocol(client);
                protocol.ExecuteWithNoData(0x1002, 1);

                if (GetNativeDriver(protocol.Model) != null)
                {
                    ICameraDevice    cameraDevice;
                    DeviceDescriptor descriptor = new DeviceDescriptor {
                        WpdId = "ptpip"
                    };
                    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;
            }
        }
Exemplo n.º 2
0
        public DeviceDescriptor Connect(string address)
        {
            string ip = address;

            if (address.Contains(":"))
            {
                ip = address.Split(':')[0];
                int port;
                int.TryParse(address.Split(':')[1], out port);
            }
            PtpIpClient client = new PtpIpClient();

            if (!client.Open(ip, 15740))
            {
                throw new Exception("No server was found!");
            }
            PtpIpProtocol protocol = new PtpIpProtocol(client);

            protocol.ExecuteWithNoData(0x1002, 1);

            if (CameraDeviceManager.GetNativeDriver(protocol.Model) != null)
            {
                DeviceDescriptor descriptor = new DeviceDescriptor {
                    WpdId = "ptpip"
                };
                var cameraDevice = (ICameraDevice)Activator.CreateInstance(CameraDeviceManager.GetNativeDriver(protocol.Model));
                descriptor.StillImageDevice = protocol;
                descriptor.CameraDevice     = cameraDevice;
                //cameraDevice.SerialNumber = StaticHelper.GetSerial(portableDevice.DeviceId);
                cameraDevice.Init(descriptor);
                return(descriptor);
            }
            else
            {
                throw new Exception("Not Supported device " + protocol.Model);
            }
        }