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 DoChecks(BaseMTPCamera cam) {
            var res = ReadBytes(cam, OC_Fx31_ptr, 0x4);

            uint OC_Fx31_base_check = (uint)((res[0] << 24) | (res[1] << 16) | (res[2] << 8) | res[3]);

            return OC_Fx31_base_check == OC_Fx31_base;
        }
        public bool DoChecks(BaseMTPCamera cam)
        {
            var res = cam.ExecuteReadDataEx(0xFE34, OC_Fx31_ptr, 0x4, 0, 0, 0);

            uint OC_Fx31_base_check = (uint)((res.Data[0] << 24) | (res.Data[1] << 16) | (res.Data[2] << 8) | res.Data[3]);

            return OC_Fx31_base_check == OC_Fx31_base;
        }
Exemple #4
0
        public void WriteBytes_FD31(BaseMTPCamera cam, uint OC_Fx31_base, uint addr, byte[] data)
        {
            uint datalen = (uint)data.Length;
            byte[] tmp_data = new byte[800];
            for (uint i = 0; i < datalen; i += 800)
            {
                uint tmp_len = Math.Min(0x800, datalen - i);
                Array.Copy(data, i, tmp_data, 0, tmp_len);

                cam.SetProperty(0xFD31, tmp_data, (addr + i) - OC_Fx31_base, tmp_len, 0);
            }
        }
Exemple #5
0
        public byte[] ReadBytes_FE31(BaseMTPCamera cam, uint OC_Fx31_base, uint addr, uint readlength)
        {
            uint step = 0x800;
            byte[] data = new byte[readlength];

            for (uint i = 0; i < readlength; i += step)
            {
                uint tmp_len = Math.Min(step, readlength - i);
                var res = cam.ExecuteReadDataEx(0xFE31, (addr + i) - OC_Fx31_base, tmp_len, 0, 0, 0);
                Array.Copy(res.Data, 0, data, i, tmp_len);
            }

            return data;
        }
        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();
            }

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

                    }

                }
            }
        }
 public void WriteBytes(BaseMTPCamera cam, uint addr, byte[] data)
 {
     WriteBytes_FD34(cam, addr, data);
 }
 public byte[] ReadBytes(BaseMTPCamera cam, uint addr, uint readlength)
 {
     return ReadBytes_FE34(cam, addr, readlength);
 }
 public bool DoChecks(BaseMTPCamera cam)
 {
     return true;
 }
 public void WriteBytes(BaseMTPCamera cam, uint addr, byte[] data)
 {
     WriteBytes_FD31(cam, OC_Fx31_base, addr, data);
 }
        static public byte[] ReadBytes(BaseMTPCamera cam, uint addr, uint readlength)
        {
            var res = cam.ExecuteReadDataEx(0xFE34, addr, readlength, 0, 0, 0);

            return res.Data;
        }
 public byte[] ReadBytes(BaseMTPCamera cam, uint addr, uint readlength)
 {
     return ReadBytes_FE31(cam, OC_Fx31_base, addr, readlength);
 }
 private void Button_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;
             }
         }
         XmlPropertyValue property = lst_values.SelectedItem as XmlPropertyValue;
         XmlPropertyDescriptor propertyDescriptor = lst_prop.SelectedItem as XmlPropertyDescriptor;
         if (property != null)
         {
             MTPCamera.SetProperty(BaseMTPCamera.CONST_CMD_SetDevicePropValue,
                                   BitConverter.GetBytes(property.Value), propertyDescriptor.Code);
         }
     }
     catch (Exception exception)
     {
         MessageBox.Show("Error set property " + exception.Message);
     }
 }
Exemple #16
0
 public void WriteBytes_FD34(BaseMTPCamera cam, uint addr, byte[] data)
 {
     cam.SetProperty(0xFD34, data, addr, (uint)data.Length, 0);
 }