static void Main(string[] args)
        {
            EepromChecko();
            return;

            string camid = FindNikonCamera();
            if (camid == "")
            {
                Debug.WriteLine("** Failed to find Nikon Camera");
                Console.WriteLine("Failed to find Nikon Camera");
                return;
            }

            SN = camid.Split('#')[2];

            DeviceDescriptor descriptor = new DeviceDescriptor { WpdId = camid };
            cam = new BaseMTPCamera();
            bool i = cam.Init(descriptor);
            var rep = cam.ExecuteReadDataEx(MTP_OPERATION_GET_DEVICE_INFO);

            if (rep.ErrorCode == ErrorCodes.MTP_OK)
            {
                //DumpTests();

                Dump_Eeprom_LANG_Test1(SN);
              
            }
        }
        public bool Init(DeviceDescriptor deviceDescriptor,DeviceDescription description)
        {
            base.Init(deviceDescriptor);
            StillImageDevice imageDevice = StillImageDevice as StillImageDevice;
            if (imageDevice != null)
                imageDevice.DeviceEvent += StillImageDevice_DeviceEvent;
            foreach (var property in description.Properties)
            {
                if (!string.IsNullOrEmpty(property.Name))
                {
                    try
                    {
                        MTPDataResponse result = StillImageDevice.ExecuteReadData(CONST_CMD_GetDevicePropDesc, property.Code);

                        ErrorCodes.GetException(result.ErrorCode);
                        uint dataType = BitConverter.ToUInt16(result.Data, 2);
                        int dataLength = StaticHelper.GetDataLength(dataType);

                        var value = new PropertyValue<long> { Code = property.Code, Name = property.Name };
                        foreach (var propertyValue in property.Values)
                        {
                            value.AddValues(propertyValue.Name, propertyValue.Value);
                        }
                        value.ValueChanged += value_ValueChanged;
                        
                        AdvancedProperties.Add(value);
                    }
                    catch (Exception ex)
                    {
                        Log.Error("Error ger property ", ex);
                    }
                }
            }
            return true;
        }
        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);
            }
        }
        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);
                }
        }
Exemple #5
0
 public override bool Init(DeviceDescriptor deviceDescriptor)
 {
     bool res = base.Init(deviceDescriptor);
     Capabilities.Clear();
     Capabilities.Add(CapabilityEnum.CaptureNoAf);
     HaveLiveView = false;
     CaptureInSdRam = false;
     return res;
 }
 public override bool Init(DeviceDescriptor deviceDescriptor)
 {
     bool res = base.Init(deviceDescriptor);
     Capabilities.Clear();
     Capabilities.Add(CapabilityEnum.LiveView);
     Capabilities.Add(CapabilityEnum.RecordMovie);
     CaptureInSdRam = false;
     PropertyChanged -= NikonBase_PropertyChanged;
     return res;
 }
 public override bool Init(DeviceDescriptor deviceDescriptor)
 {
     bool res = base.Init(deviceDescriptor);
     Capabilities.Clear();
     Capabilities.Add(CapabilityEnum.LiveView);
     Capabilities.Add(CapabilityEnum.RecordMovie);
     Capabilities.Add(CapabilityEnum.CaptureInRam);
     Capabilities.Add(CapabilityEnum.CaptureNoAf);
     return res;
 }
        private void MenuItem_Click(object sender, RoutedEventArgs e)
        {
            DeviceInfo = new XmlDeviceData();
            SelectDevice wnd = new SelectDevice();
            wnd.ShowDialog();
            if (wnd.DialogResult == true && wnd.SelectedDevice != null)
            {
                try
                {
                    SelectedDevice = wnd.SelectedDevice;
                    DeviceDescriptor descriptor = new DeviceDescriptor {WpdId = SelectedDevice.DeviceId};
                    MtpProtocol device = new MtpProtocol(descriptor.WpdId);
                    device.ConnectToDevice("MTPTester", 1, 0);
                    descriptor.StillImageDevice = device;
                    MTPCamera = new BaseMTPCamera();
                    MTPCamera.Init(descriptor);
                    LoadDeviceData(MTPCamera.ExecuteReadDataEx(0x1001));
                    //LoadDeviceData(MTPCamera.ExecuteReadDataEx(0x9108));
     
                    PopulateProperties();
                }
                catch (DeviceException exception)
                {
                    MessageBox.Show("Error getting device information" + exception.Message);
                }
                catch (Exception exception)
                {
                    MessageBox.Show("General error" + exception.Message);
                }
                if (DefaultDeviceInfo != null)
                {
                    foreach (XmlCommandDescriptor command in DeviceInfo.AvaiableCommands)
                    {
                        command.Name = DefaultDeviceInfo.GetCommandName(command.Code);
                    }
                    foreach (XmlEventDescriptor avaiableEvent in DeviceInfo.AvaiableEvents)
                    {
                        avaiableEvent.Name = DefaultDeviceInfo.GetEventName(avaiableEvent.Code);
                    }
                    foreach (XmlPropertyDescriptor property in DeviceInfo.AvaiableProperties)
                    {
                        property.Name = DefaultDeviceInfo.GetPropName(property.Code);
                    }
                }
                InitUi();
            }

        }
        public override bool Init(DeviceDescriptor deviceDescriptor)
        {
            base.Init(deviceDescriptor);
            Properties.Add(InitFocalLength());
            ExposureCompensation = new PropertyValue<int> {Available = false};
            ExposureMeteringMode = new PropertyValue<int> {Available = false};
            FNumber = new PropertyValue<int> {Available = false};
            IsoNumber = new PropertyValue<int> {Available = false};
            CompressionSetting = new PropertyValue<int> {Available = false};
            Mode = new PropertyValue<uint>() {Available = false};
            ShutterSpeed = new PropertyValue<long>() {Available = false};
            WhiteBalance = new PropertyValue<long>() {Available = false};
            FocusMode = new PropertyValue<long>() {Available = false};

            StillImageDevice imageDevice = StillImageDevice as StillImageDevice;
            if (imageDevice != null)
                imageDevice.DeviceEvent += StillImageDevice_DeviceEvent;
            return true;
        }
 private void btn_get_value_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         if (MTPCamera == null || MTPCamera.IsConnected == false)
         {
             DeviceInfo = new XmlDeviceData();
             SelectDevice wnd = new SelectDevice();
             wnd.ShowDialog();
             if (wnd.DialogResult == true && wnd.SelectedDevice != null)
             {
                 SelectedDevice = wnd.SelectedDevice;
                 DeviceDescriptor descriptor = new DeviceDescriptor {WpdId = SelectedDevice.DeviceId};
                 MTPCamera = new BaseMTPCamera();
                 MTPCamera.Init(descriptor);
             }
             else
             {
                 return;
             }
         }
         XmlPropertyDescriptor propertyDescriptor = lst_prop.SelectedItem as XmlPropertyDescriptor;
         MTPDataResponse resp = MTPCamera.ExecuteReadDataEx(BaseMTPCamera.CONST_CMD_GetDevicePropValue,
                                                             propertyDescriptor.Code);
         long val = GetValue(resp, 0, GetDataLength(propertyDescriptor.DataType));
         XmlPropertyValue selected = null;
         foreach (XmlPropertyValue xmlPropertyValue in propertyDescriptor.Values)
         {
             if (xmlPropertyValue.Value == val)
                 selected = xmlPropertyValue;
         }
         if(selected!=null)
         {
             lst_values.BeginInit();
             lst_values.SelectedItem = selected;
             lst_values.EndInit();
         }
     }
     catch (Exception exception)
     {
         MessageBox.Show("Error to get value " + exception.Message);
     }
 }
        public DeviceDescriptor Connect(string address)
        {
            int port = 7878;
            string ip = address;
            if (address.Contains(":"))
            {
                ip = address.Split(':')[0];
                int.TryParse(address.Split(':')[1], out port);
            }
            YiCameraProtocol protocol = new YiCameraProtocol();
            protocol.Connect(ip, port);

            DeviceDescriptor descriptor = new DeviceDescriptor { WpdId = "YiCamera" };
            var cameraDevice = new YiCamera();
            descriptor.StillImageDevice = protocol;
            descriptor.CameraDevice = cameraDevice;
            //cameraDevice.SerialNumber = StaticHelper.GetSerial(portableDevice.DeviceId);
            cameraDevice.Init(descriptor);
            return descriptor;
        }
        public DeviceDescriptor Connect(string address)
        {
            CameraDiscovery cameraDiscover = new CameraDiscovery();

            if (cameraDiscover.UDPSocketSetup())
            {
                if (cameraDiscover.MSearch())
                {

                    var cameraResp = cameraDiscover.DeviceDescription();
                    var info = cameraDiscover.AnalyzeDescription(cameraResp);
                    var camera = new SonyWifiCamera();
                    camera.Init(info.Endpoints["camera"]);
                    camera.DeviceName = info.FriendlyName;
                    camera.SerialNumber = info.UDN;
                    DeviceDescriptor descriptor = new DeviceDescriptor { WpdId = "SonyWifiCamera" };
                    descriptor.CameraDevice = camera;
                    //cameraDevice.SerialNumber = StaticHelper.GetSerial(portableDevice.DeviceId);
                    return descriptor;
                }
            }
            throw new Exception("No camera was found !");
        }
        public override bool Init(DeviceDescriptor deviceDescriptor)
        {
            CurrentValues = new Dictionary<string, string>();
            Capabilities.Add(CapabilityEnum.LiveView);
            Capabilities.Add(CapabilityEnum.LiveViewStream);
            Protocol = deviceDescriptor.StillImageDevice as YiCameraProtocol;
            Protocol.DataReceiverd += Protocol_DataReceiverd;

            DeviceName = Protocol.Model;
            Manufacturer = Protocol.Manufacturer;
            IsConnected = true;
            CompressionSetting = new PropertyValue<int> { Tag = "photo_quality" };
            
            Mode = new PropertyValue<uint> { Tag = "capture_mode" };
            Mode.AddValues("Single", 0);
            Mode.AddValues("Burst", 1);
            Mode.AddValues("Delayed", 2);
            //Mode.AddValues("TimeLapse", 3);
            Mode.ReloadValues();

            ExposureMeteringMode = new PropertyValue<int>() { Tag = "meter_mode" };
            
            LiveViewImageZoomRatio = new PropertyValue<int>();
            LiveViewImageZoomRatio.AddValues("All", 0);
            LiveViewImageZoomRatio.Value = "All";
            SendCommand(3);
            Thread.Sleep(500);

            SerialNumber = GetValue("serial_number");
            SetProperty(Mode.Tag, GetValue(Mode.Tag));


            var thread = new Thread(LoadProperties) { Priority = ThreadPriority.Lowest };
            thread.Start();
            return true;
        }
        private ICameraDevice GetWiaIDevice(IDeviceInfo devInfo)
        {
            // if camera already is connected do nothing
            if (_deviceEnumerator.GetByWiaId(devInfo.DeviceID) != null)
                return _deviceEnumerator.GetByWiaId(devInfo.DeviceID).CameraDevice;
            _deviceEnumerator.RemoveDisconnected();
            DeviceDescriptor descriptor = new DeviceDescriptor {WiaDeviceInfo = devInfo, WiaId = devInfo.DeviceID};

            ICameraDevice cameraDevice = new WiaCameraDevice();
            bool isConnected = cameraDevice.Init(descriptor);

            descriptor.CameraDevice = cameraDevice;
            _deviceEnumerator.Add(descriptor);
            ConnectedDevices.Add(cameraDevice);

            if (isConnected)
            {
                NewCameraConnected(cameraDevice);
            }
            //ServiceProvider.DeviceManager.SelectedCameraDevice.ReadDeviceProperties(0);

            return SelectedCameraDevice;
        }
 public override bool Init(DeviceDescriptor deviceDescriptor)
 {
     StillImageDevice = deviceDescriptor.StillImageDevice;
     StillImageDevice imageDevice = StillImageDevice as StillImageDevice;
     if (imageDevice != null)
         imageDevice.DeviceEvent += StillImageDevice_DeviceEvent;
     IsConnected = true;
     DeviceName = StillImageDevice.Model;
     Manufacturer = StillImageDevice.Manufacturer;
     var data = StillImageDevice.ExecuteReadData(CONST_CMD_GetDevicePropValue,
                                                                        CONST_PROP_BatteryLevel);
     if (data.Data != null && data.Data.Length > 0)
         Battery = data.Data[0];
     return true;
 }
        private void AddCanonCameras()
        {
            lock (_locker)
            {
                foreach (EosCamera eosCamera in GetEosCameras())
                {
                    bool shouldbeadded =
                        ConnectedDevices.OfType<CanonSDKBase>().All(camera => camera.PortName != eosCamera.PortName);

                    if (shouldbeadded)
                    {
                        Log.Debug("New canon camera found !");
                        CanonSDKBase camera = new CanonSDKBase();
                        Log.Debug("Pas 1");
                        DeviceDescriptor descriptor = new DeviceDescriptor {EosCamera = eosCamera};
                        descriptor.CameraDevice = camera;
                        Log.Debug("Pas 2");
                        camera.Init(eosCamera);
                        Log.Debug("Pas 3");
                        ConnectedDevices.Add(camera);
                        Log.Debug("Pas 4");
                        _deviceEnumerator.Add(descriptor);
                        Log.Debug("Pas 5");
                        NewCameraConnected(camera);
                        Log.Debug("New canon camera found done!");
                    }
                }
                //Thread.Sleep(2500);
            }
        }
        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;
        }
        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 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;
            }
        }
        public override bool Init(DeviceDescriptor deviceDescriptor)
        {
            //StillImageDevice = new StillImageDevice(deviceDescriptor.WpdId);
            //StillImageDevice.ConnectToDevice(AppName, AppMajorVersionNumber, AppMinorVersionNumber);
            //StillImageDevice.DeviceEvent += _stillImageDevice_DeviceEvent;
            Capabilities.Add(CapabilityEnum.Bulb);
            Capabilities.Add(CapabilityEnum.LiveView);

            IsConnected = true;
            return true;
        }
 public void Add(DeviceDescriptor descriptor)
 {
     Devices.Add(descriptor);
 }
 public override bool Init(DeviceDescriptor deviceDescriptor)
 {
     var res = base.Init(deviceDescriptor);
     Capabilities.Remove(CapabilityEnum.CaptureNoAf);
     return res;
 }
 public override bool Init(DeviceDescriptor deviceDescriptor)
 {
     StillImageDevice = new StillImageDevice(deviceDescriptor.WpdId);
     StillImageDevice.ConnectToDevice(AppName, AppMajorVersionNumber, AppMinorVersionNumber);
     StillImageDevice.DeviceEvent += _stillImageDevice_DeviceEvent;
     DeviceName = StillImageDevice.Model;
     Manufacturer = StillImageDevice.Manufacturer;
     Capabilities.Add(CapabilityEnum.Bulb);
     Capabilities.Add(CapabilityEnum.LiveView);
     InitShutterSpeed();
     IsConnected = true;
     ExecuteWithNoData(CONST_CMD_CANON_EOS_SetRemoteMode, 1);
     ExecuteWithNoData(CONST_CMD_CANON_EOS_SetEventMode, 1);
     _timer.Start();
     return true;
 }
        private void AddCanonCameras()
        {
            foreach (EosCamera eosCamera in GetEosCameras())
            {
                bool shouldbeadded = true;
                foreach (ICameraDevice device in ConnectedDevices)
                {
                    CanonSDKBase camera = device as CanonSDKBase;
                    if (camera != null)
                    {
                        if (camera.Camera == eosCamera)
                        {
                            shouldbeadded = false;
                            break;
                        }
                    }
                }

                if (shouldbeadded)
                {
                    Log.Debug("New canon camera found !");
                    CanonSDKBase camera = new CanonSDKBase();
                    DeviceDescriptor descriptor = new DeviceDescriptor {EosCamera = eosCamera};
                    descriptor.CameraDevice = camera;
                    NewCameraConnected(camera);
                    camera.Init(eosCamera);
                    ConnectedDevices.Add(camera);
                    _deviceEnumerator.Add(descriptor);
                }
            }
            Thread.Sleep(2500);
        }
 public void Remove(DeviceDescriptor descriptor)
 {
     Devices.Remove(descriptor);
 }
 public override bool Init(DeviceDescriptor deviceDescriptor)
 {
     StillImageDevice = deviceDescriptor.StillImageDevice;
     StillImageDevice imageDevice = StillImageDevice as StillImageDevice;
     if (imageDevice != null)
         imageDevice.DeviceEvent += StillImageDevice_DeviceEvent;
     IsConnected = true;
     return true;
 }
        public override bool Init(DeviceDescriptor deviceDescriptor)
        {
            IsBusy = false;
            //the device not connected
            try
            {
                ConnectToWiaDevice(deviceDescriptor);
            }
            catch (Exception exception)
            {
                Log.Error("Unable to connect camera using wia driver", exception);
                return false;
            }
            DeviceManager = new DeviceManager();
            DeviceManager.RegisterEvent(Conts.wiaEventItemCreated, deviceDescriptor.WiaId);
            DeviceManager.OnEvent += DeviceManager_OnEvent;

            try
            {
                Device = deviceDescriptor.WiaDevice;
                DeviceName = Device.Properties["Description"].get_Value();
                Manufacturer = Device.Properties["Manufacturer"].get_Value();
                SerialNumber = StaticHelper.GetSerial(Device.Properties["PnP ID String"].get_Value());
            }
            catch (Exception ex)
            {
                Log.Debug("Init error", ex);
            }
            IsConnected = true;
            try
            {
                try
                {
                    Property apertureProperty = Device.Properties[Conts.CONST_PROP_F_Number];
                    if (apertureProperty != null)
                    {
                        foreach (var subTypeValue in apertureProperty.SubTypeValues)
                        {
                            double d = (int) subTypeValue;
                            string s = "f/" + (d/100).ToString("0.0");
                            FNumber.AddValues(s, (int) d);
                            if ((int) subTypeValue == (int) apertureProperty.get_Value())
                                FNumber.SetValue((int) d);
                        }
                    }
                }
                catch (COMException)
                {
                    FNumber.IsEnabled = false;
                }

                try
                {
                    Property isoProperty = Device.Properties[Conts.CONST_PROP_ISO_Number];
                    if (isoProperty != null)
                    {
                        foreach (var subTypeValue in isoProperty.SubTypeValues)
                        {
                            IsoNumber.AddValues(subTypeValue.ToString(), (int) subTypeValue);
                            if ((int) subTypeValue == (int) isoProperty.get_Value())
                                IsoNumber.SetValue((int) subTypeValue);
                        }
                    }
                }
                catch (COMException)
                {
                    IsoNumber.IsEnabled = false;
                }

                try
                {
                    Property shutterProperty = Device.Properties[Conts.CONST_PROP_Exposure_Time];
                    if (shutterProperty != null)
                    {
                        foreach (int subTypeValue in shutterProperty.SubTypeValues)
                        {
                            if (ShutterTable.ContainsKey((int) subTypeValue))
                                ShutterSpeed.AddValues(ShutterTable[(int) subTypeValue], (int) subTypeValue);
                        }
                        ShutterSpeed.SetValue(shutterProperty.get_Value());
                    }
                }
                catch (COMException)
                {
                    ShutterSpeed.IsEnabled = false;
                }

                try
                {
                    Property wbProperty = Device.Properties[Conts.CONST_PROP_WhiteBalance];
                    if (wbProperty != null)
                    {
                        foreach (var subTypeValue in wbProperty.SubTypeValues)
                        {
                            if (WbTable.ContainsKey((int) subTypeValue))
                                WhiteBalance.AddValues(WbTable[(int) subTypeValue], (int) subTypeValue);
                        }
                        WhiteBalance.SetValue(wbProperty.get_Value());
                    }
                }
                catch (COMException)
                {
                    WhiteBalance.IsEnabled = false;
                }

                try
                {
                    Property modeProperty = Device.Properties[Conts.CONST_PROP_ExposureMode];
                    if (modeProperty != null)
                    {
                        foreach (var subTypeValue in modeProperty.SubTypeValues)
                        {
                            if (ExposureModeTable.ContainsKey((int) subTypeValue))
                                Mode.AddValues(ExposureModeTable[(int) subTypeValue], Convert.ToUInt32(subTypeValue));
                        }
                        Mode.SetValue(Convert.ToUInt32(modeProperty.get_Value()));
                    }
                    Mode.IsEnabled = false;
                }
                catch (COMException)
                {
                    Mode.IsEnabled = false;
                }

                try
                {
                    Property ecProperty = Device.Properties[Conts.CONST_PROP_ExposureCompensation];
                    if (ecProperty != null)
                    {
                        foreach (var subTypeValue in ecProperty.SubTypeValues)
                        {
                            decimal d = (int) subTypeValue;
                            string s = decimal.Round(d/1000, 1).ToString();
                            if (d > 0)
                                s = "+" + s;
                            ExposureCompensation.AddValues(s, (int) subTypeValue);
                        }
                        ExposureCompensation.SetValue(ecProperty.get_Value());
                    }
                }
                catch (COMException)
                {
                    ExposureCompensation.IsEnabled = false;
                }

                try
                {
                    Property csProperty = Device.Properties[Conts.CONST_PROP_CompressionSetting];
                    if (csProperty != null)
                    {
                        foreach (var subTypeValue in csProperty.SubTypeValues)
                        {
                            if (CSTable.ContainsKey((int) subTypeValue))
                                CompressionSetting.AddValues(CSTable[(int) subTypeValue], (int) subTypeValue);
                        }
                        CompressionSetting.SetValue(csProperty.get_Value());
                    }
                }
                catch (COMException)
                {
                    CompressionSetting.IsEnabled = false;
                }

                try
                {
                    Property emmProperty = Device.Properties[Conts.CONST_PROP_ExposureMeteringMode];
                    if (emmProperty != null)
                    {
                        foreach (var subTypeValue in emmProperty.SubTypeValues)
                        {
                            if (EMMTable.ContainsKey((int) subTypeValue))
                                ExposureMeteringMode.AddValues(EMMTable[(int) subTypeValue], (int) subTypeValue);
                        }
                        CompressionSetting.SetValue(emmProperty.get_Value());
                    }
                }
                catch (COMException)
                {
                    CompressionSetting.IsEnabled = false;
                }

                try
                {
                    Property fmProperty = Device.Properties[Conts.CONST_PROP_FocusMode];
                    if (fmProperty != null)
                    {
                        foreach (int subTypeValue in fmProperty.SubTypeValues)
                        {
                            uint subval = Convert.ToUInt16(subTypeValue);
                            if (FMTable.ContainsKey(subval))
                                FocusMode.AddValues(FMTable[subval], subval);
                        }
                        FocusMode.SetValue(Convert.ToUInt16((int) fmProperty.get_Value()));
                    }
                }
                catch (COMException)
                {
                    FocusMode.IsEnabled = false;
                }

                try
                {
                    Battery = Device.Properties[Conts.CONST_PROP_BatteryStatus].get_Value();
                }
                catch (COMException)
                {
                    Battery = 0;
                }
                IsConnected = true;
            }
            catch (Exception exception)
            {
                Log.Error(exception);
                IsConnected = false;
            }
            HaveLiveView = true;
            //Capabilities.Add(CapabilityEnum.LiveView);
            return true;
        }
        static void Main(string[] args)
        {
            LogIt("Nikon Flags v1.1");

            string camid = FindNikonCamera();

            if (camid == "")
            {
                LogIt("Failed to find Nikon Camera");
                return;
            }


            SN = camid.Split('#')[2];

            DeviceDescriptor descriptor = new DeviceDescriptor { WpdId = camid };
            cam = new BaseMTPCamera();
            bool i = cam.Init(descriptor);
            var rep = cam.ExecuteReadDataEx(MTP_OPERATION_GET_DEVICE_INFO);

            if (rep.ErrorCode != ErrorCodes.MTP_OK)
            {
                var s = "Failed to initialise";
                LogIt(s);
                return;
            }

            var version = Get_Version_FirmB();
            var model = Get_CameraModel();

            var cam_obj = CameraBase.GetCameraObject(model, version);

            LogIt(model);
            LogIt(version);

            if (cam_obj == null)
            {
                var s = "Camera model/version not recognised, please email: [email protected] with the details";

                LogIt(s);
                return;
            }

            if (cam_obj.DoChecks(cam) == false)
            {
                var s = "Camera model/version checks failed, please email: [email protected] with the details";

                LogIt(s);
                return;
            }

            var flagAddr = cam_obj.GetKnownAddresss(KnownAddressList.Set04Ram);
            var flagLen = cam_obj.GetKnownLenght(KnownAddressList.Set04Ram);

            //var flagAddr = cam_obj.GetKnownAddresss(KnownAddressList.Set26);
            //var flagLen = cam_obj.GetKnownLenght(KnownAddressList.Set26);

            LogIt("");
            LogIt("Flag Opp [Value]");

            LogIt("   Flag - byte between 0 - 0x{0:X} inclusive", flagLen - 1);
            LogIt("   Opp - A and, O or, C clear, D display, Q quit (no flag needed)");
            LogIt("   Value - hex value used in A, O, C operations");
            LogIt(" '0 A 0x01' will apply AND 0x01 with currnet set04ram[0x00]");
            LogIt(" '0x12 O 0x10' will apply OR 0x10 with current set04ram[0x12]");
            LogIt(" '0x11 C 0x01' will apply AND 0xFE (~0x01), aka clear current set04ram[0x11]");
            LogIt(" '15 D' will display current set04ram[0x15]");
           
            uint offset = 0;
            while (offset < flagLen)
            {
                var line = Console.ReadLine().ToLower().Trim();
                var parts = line.Split(' ');

                if (line == "q") break;

                if (parts.Length < 2) continue;
                var a = parts[0].ToLower().Trim();
                if (a.StartsWith("0x")) a = a.Substring(2);
                if (uint.TryParse(a, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out offset) &&
                    offset < flagLen)
                {
                    var b = parts[1].ToLower().Trim();
                    if (b.Length >= 1)
                    {
                        var opp = b[0];
                        if (opp != 'a' && opp != 'o' && opp != 'c' && opp != 'd')
                        {
                            LogIt("Bad operation character.");
                            break;
                        }

                        byte value = 0;
                        if (opp == 'a' || opp == 'o' || opp == 'c')
                        {
                            if (parts.Length != 3)
                            {
                                LogIt("Value missing");
                                continue;
                            }

                            var c = parts[2].ToLower().Trim();
                            if (c.StartsWith("0x")) c = c.Substring(2);

                            if (byte.TryParse(c, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out value) == false)
                            {
                                LogIt("Bad value input");
                                continue;
                            }
                        }

                        var data = cam_obj.ReadBytes(cam, flagAddr + offset, 1);

                        if (data.Length != 1)
                        {
                            LogIt("Bad data read.");
                            break;
                        }

                        if (opp == 'd')
                        {
                            LogIt("Set04ram[0x{0:X}] = 0x{1:X}", offset, data[0]);
                            continue;
                        }

                        if (opp == 'a')
                            data[0] &= value;

                        if (opp == 'o')
                            data[0] |= value;

                        if (opp == 'c')
                            data[0] &= (byte)(~value);

                        LogIt("write: Set04ram[0x{0:X}] = 0x{1:X}", offset, data[0]);
                        cam_obj.WriteBytes(cam, flagAddr + offset, data);

                    }

                }
            }
        }
 private void ConnectToWiaDevice(DeviceDescriptor deviceDescriptor, int retries_left = 6)
 {
     if (deviceDescriptor.WiaDevice == null)
     {
         Thread.Sleep(500);
         try
         {
             deviceDescriptor.WiaDevice = deviceDescriptor.WiaDeviceInfo.Connect();
             deviceDescriptor.CameraDevice = this;
             Thread.Sleep(250);
         }
         catch (COMException e)
         {
             if ((uint) e.ErrorCode == ErrorCodes.WIA_ERROR_BUSY && retries_left > 0)
             {
                 int retry_in_secs = 2*(7 - retries_left);
                 Thread.Sleep(1000*retry_in_secs);
                 Log.Debug("Connection to wia failed, Retrying to connect in " + retry_in_secs + " seconds");
                 ConnectToWiaDevice(deviceDescriptor, retries_left - 1);
             }
             else
             {
                 Log.Error("Could not connect to wia device.", e);
                 throw e;
             }
         }
     }
 }
Exemple #30
0
 public override bool Init(DeviceDescriptor deviceDescriptor)
 {
     try
     {
         IsBusy = true;
         Capabilities.Add(CapabilityEnum.CaptureInRam);
         Capabilities.Add(CapabilityEnum.CaptureNoAf);
         StillImageDevice = deviceDescriptor.StillImageDevice;
         // check if is mtp device
         StillImageDevice imageDevice = StillImageDevice as StillImageDevice;
         if (imageDevice != null)
             imageDevice.DeviceEvent += _stillImageDevice_DeviceEvent;
         HaveLiveView = true;
         DeviceReady();
         DeviceName = StillImageDevice.Model;
         Manufacturer = StillImageDevice.Manufacturer;
         IsConnected = true;
         CaptureInSdRam = true;
         PropertyChanged += NikonBase_PropertyChanged;
         var ser = StillImageDevice.SerialNumber;
         Log.Debug("Serial number" + ser ?? "");
         if (ser != null && ser.Length >= 7)
         {
             SerialNumber = ser.Substring(0, 7);
             // there in some cases the leading zero order differs
             if (SerialNumber == "0000000")
             {
                 SerialNumber =  ser.Substring(ser.Length-7,7);
             }
         }
         // load advanced properties in a separated thread to speed up camera connection
         var thread = new Thread(LoadProperties) {Priority = ThreadPriority.Lowest};
         thread.Start();
     }
     catch (Exception exception)
     {
         Log.Error("Error initialize device", exception);
     }
     return true;
 }
 public override bool Init(DeviceDescriptor deviceDescriptor)
 {
     return true;
 }
        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;
            }
        }