private void OpenSession()
        {
            if (CameraListBox.SelectedIndex >= 0)
            {
                MainCamera = CamList[CameraListBox.SelectedIndex];
                MainCamera.OpenSession();
                MainCamera.LiveViewUpdated += MainCamera_LiveViewUpdated;
                MainCamera.ProgressChanged += MainCamera_ProgressChanged;
                MainCamera.StateChanged    += MainCamera_StateChanged;
                MainCamera.DownloadReady   += MainCamera_DownloadReady;

                SessionButton.Content = "Close Session";
                SessionLabel.Content  = MainCamera.DeviceName;
                AvList  = MainCamera.GetSettingsList(PropertyID.Av);
                TvList  = MainCamera.GetSettingsList(PropertyID.Tv);
                ISOList = MainCamera.GetSettingsList(PropertyID.ISO);
                foreach (var Av in AvList)
                {
                    AvCoBox.Items.Add(Av.StringValue);
                }
                foreach (var Tv in TvList)
                {
                    TvCoBox.Items.Add(Tv.StringValue);
                }
                foreach (var ISO in ISOList)
                {
                    ISOCoBox.Items.Add(ISO.StringValue);
                }
                AvCoBox.SelectedIndex      = AvCoBox.Items.IndexOf(AvValues.GetValue(MainCamera.GetInt32Setting(PropertyID.Av)).StringValue);
                TvCoBox.SelectedIndex      = TvCoBox.Items.IndexOf(TvValues.GetValue(MainCamera.GetInt32Setting(PropertyID.Tv)).StringValue);
                ISOCoBox.SelectedIndex     = ISOCoBox.Items.IndexOf(ISOValues.GetValue(MainCamera.GetInt32Setting(PropertyID.ISO)).StringValue);
                SettingsGroupBox.IsEnabled = true;
                LiveViewGroupBox.IsEnabled = true;
            }
        }
Пример #2
0
        private async void Start_Click(object sender, RoutedEventArgs e)
        {
            int totalimg = q.Count;

            OverallProg.Maximum = totalimg;
            OverallProg.Minimum = 0;

            while (q.Count > 0)
            {
                try
                {
                    goset = (setting)q.Dequeue();                                                       //do not update goset with new value if an exposure was not taken due to failure
                    MainCamera.SetSetting(PropertyID.Tv, TvValues.GetValue(goset.getEXP()).IntValue);   // set exposure
                    MainCamera.SetSetting(PropertyID.Av, AvValues.GetValue(goset.getAP()).IntValue);    // set aperture
                    MainCamera.SetSetting(PropertyID.ISO, ISOValues.GetValue(goset.getISO()).IntValue); // set ISO sensitivity
                    MainCamera.TakePhotoAsync();                                                        // capture image
                    statustext.Text = "Capturing image " + (totalimg - q.Count) + " of " + totalimg;
                }
                catch (Exception ex)
                {
                    ReportError(ex.Message, false);
                    break; // stop while loop if error arises
                }
                finally
                {
                    OverallProg.Value = totalimg - q.Count;
                    await WaitAsynchronously();
                }
            }
            statustext.Text = "Complete";
        }
Пример #3
0
        public void StartExposure(double Duration, bool Light)
        {
            if (!IsLiveViewMode)
            {
                InitSettings();

                _duration  = Duration;
                _startTime = DateTime.Now;
                _canceledFlag.IsCanceled = false;

                if (Duration >= 1)
                {
                    MainCamera.SetSetting(PropertyID.Tv, TvValues.GetValue("Bulb").IntValue);
                    MainCamera.TakePhotoBulbAsync((int)(Duration * 1000), _canceledFlag);
                }
                else
                {
                    CameraValue tvCameraValue = GetSelectedTv(Duration);
                    MainCamera.SetSetting(PropertyID.Tv, tvCameraValue.IntValue);
                    MainCamera.TakePhoto();
                }
            }
            else
            {
                Thread.Sleep(100);
                _lvCapture = true;
            }
        }
Пример #4
0
 public void TvChanged(object sender, int value)
 {
     if (TvComboBox.SelectedIndex < 0 || !SessionOpen())
     {
         return;
     }
     Camera.SetSetting(PropertyID.Tv, TvValues.GetValue((string)TvComboBox.SelectedItem).IntValue);
     GUI.Camera_StatusUpdate("Tv set to: " + value);
 }
Пример #5
0
        public bool TakePhoto(string[] camSettings)  //where cS[0] is ISO(sensitivity), cS[1] is Tv(exposition), cS[2] is Tv in bulb mode and cS[3] is Av(apperture)
        {
            try
            {
                APIHandler = new CanonAPI();
                if (OpenSession())
                {
                    if (!Error)
                    {
                        ImageSaveDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "RemotePhoto");
                        MainCamera.SetSetting(PropertyID.SaveTo, (int)SaveTo.Host);
                        MainCamera.SetSetting(PropertyID.ISO, ISOValues.GetValue(camSettings[0]).IntValue);
                        MainCamera.SetSetting(PropertyID.Av, AvValues.GetValue(camSettings[3]).IntValue);
                        MainCamera.SetCapacity(4096, int.MaxValue);
                        Console.WriteLine($"Set image output path to: {ImageSaveDirectory}");

                        Console.WriteLine("Taking photo with special settings...");
                        CameraValue tv = TvValues.GetValue(MainCamera.GetInt32Setting(PropertyID.Tv));
                        if (tv == TvValues.Bulb)
                        {
                            MainCamera.TakePhotoBulb(int.Parse(camSettings[2]));
                        }
                        else
                        {
                            MainCamera.SetSetting(PropertyID.Tv, TvValues.GetValue(camSettings[1]).IntValue);
                            MainCamera.TakePhoto();
                        }
                        WaitEvent.WaitOne();

                        if (!Error)
                        {
                            Console.WriteLine("Photo taken and saved"); return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); return(false); }
            finally
            {
                MainCamera?.Dispose();
                APIHandler.Dispose();
            }
        }
Пример #6
0
 private void TvCoBox_SelectedIndexChanged(object sender, EventArgs e)
 {
     try
     {
         if (IsUIInit)
         {
             MainCamera.Tv       = TvValues.GetValue((string)TvCoBox.SelectedItem);
             BulbTextBox.Enabled = (string)TvCoBox.SelectedItem == "Bulb";
         }
     }
     catch (Exception ex) { ShowError(ex); }
 }
Пример #7
0
        public void SetInitGUI()
        {
            if (IsGUIInit || !GUI.IsInitialized)
            {
                return;
            }
            if (CamList?.Count >= 1)
            {
                try {
                    GUI.Dispatcher.Invoke((Action) delegate {
                        AvComboBox  = GUI.GetComboBox(PropertyID.Av);
                        TvComboBox  = GUI.GetComboBox(PropertyID.Tv);
                        ISOComboBox = GUI.GetComboBox(PropertyID.ISO);
                        GUI.GetSavePathTextBox().Text = defSaveDir;

                        foreach (var Av in AvList)
                        {
                            AvComboBox.Items.Add(AvComboBox.Items.Add(Av.StringValue));
                        }
                        foreach (var Tv in TvList)
                        {
                            TvComboBox.Items.Add(TvComboBox.Items.Add(Tv.StringValue));
                        }
                        foreach (var ISO in ISOList)
                        {
                            ISOComboBox.Items.Add(ISOComboBox.Items.Add(ISO.StringValue));
                        }

                        AvComboBox.SelectedIndex =
                            AvComboBox.Items.IndexOf(AvValues.GetValue(Camera.GetInt32Setting(PropertyID.Av)).StringValue);
                        TvComboBox.SelectedIndex =
                            TvComboBox.Items.IndexOf(TvValues.GetValue(Camera.GetInt32Setting(PropertyID.Tv)).StringValue);
                        ISOComboBox.SelectedIndex =
                            ISOComboBox.Items.IndexOf(ISOValues.GetValue(Camera.GetInt32Setting(PropertyID.ISO)).StringValue);

                        GUI.Camera_StatusUpdate("Connected with:" + Camera.DeviceName);
                        GUI.Camera_OpenedSession(Camera);
                        GUI.LiveViewButton_Click(null, null);
                        IsConnected = true;
                        IsGUIInit   = true;
                    });
                }
                catch (Exception e) {
                    Console.WriteLine(e);
                    ReportError(e.Message, false);
                }
            }
            else
            {
                GUI.Dispatcher.Invoke((Action) delegate { GUI.Camera_StatusUpdate("No camera connected"); });
            }
        }
Пример #8
0
        private void TvCoBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                if (TvCoBox.SelectedIndex < 0)
                {
                    return;
                }

                MainCamera.SetSetting(PropertyID.Tv, TvValues.GetValue((string)TvCoBox.SelectedItem).IntValue);
            }
            catch (Exception ex) { ReportError(ex.Message, false); }
        }
Пример #9
0
        static void Main(string[] args)
        {
            try
            {
                APIHandler = new CanonAPI();
                List <Camera> cameras = APIHandler.GetCameraList();
                if (!OpenSession())
                {
                    Console.WriteLine("No camera found. Please plug in camera");
                    APIHandler.CameraAdded += APIHandler_CameraAdded;
                    WaitEvent.WaitOne();
                    WaitEvent.Reset();
                }

                if (!Error)
                {
                    ImageSaveDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "RemotePhoto");
                    MainCamera.SetSetting(PropertyID.SaveTo, (int)SaveTo.Host);
                    MainCamera.SetCapacity(4096, int.MaxValue);
                    Console.WriteLine($"Set image output path to: {ImageSaveDirectory}");

                    Console.WriteLine("Taking photo with current settings...");
                    CameraValue tv = TvValues.GetValue(MainCamera.GetInt32Setting(PropertyID.Tv));
                    if (tv == TvValues.Bulb)
                    {
                        MainCamera.TakePhotoBulb(2);
                    }
                    else
                    {
                        MainCamera.TakePhoto();
                    }
                    WaitEvent.WaitOne();

                    if (!Error)
                    {
                        Console.WriteLine("Photo taken and saved");
                    }
                }
            }
            catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); }
            finally
            {
                MainCamera?.Dispose();
                APIHandler.Dispose();
                Console.WriteLine("Good bye! (press any key to close)");
                Console.ReadKey();
            }
        }
Пример #10
0
        private void OpenSession()
        {
            if (CameraListBox.SelectedIndex >= 0)
            {
                MainCamera = CamList[CameraListBox.SelectedIndex];
                MainCamera.OpenSession();
                MainCamera.LiveViewUpdated += MainCamera_LiveViewUpdated;
                MainCamera.ProgressChanged += MainCamera_ProgressChanged;
                MainCamera.StateChanged    += MainCamera_StateChanged;
                MainCamera.DownloadReady   += MainCamera_DownloadReady;

                if (IsInit)
                {
                    try
                    {
                        MainCamera.SetSetting(PropertyID.SaveTo, (int)SaveTo.Host); //new
                        MainCamera.SetCapacity();                                   //new
                        BrowseButton.IsEnabled = true;
                        button.IsEnabled       = true;                              //new
                    }
                    catch (Exception ex) { ReportError(ex.Message, false); }
                }

                SessionButton.Content = "Close Session";
                SessionLabel.Content  = MainCamera.DeviceName;
                AvList  = MainCamera.GetSettingsList(PropertyID.Av);
                TvList  = MainCamera.GetSettingsList(PropertyID.Tv);
                ISOList = MainCamera.GetSettingsList(PropertyID.ISO);
                foreach (var Av in AvList)
                {
                    AvCoBox.Items.Add(Av.StringValue);
                }
                foreach (var Tv in TvList)
                {
                    TvCoBox.Items.Add(Tv.StringValue);
                }
                foreach (var ISO in ISOList)
                {
                    ISOCoBox.Items.Add(ISO.StringValue);
                }
                AvCoBox.SelectedIndex      = AvCoBox.Items.IndexOf(AvValues.GetValue(MainCamera.GetInt32Setting(PropertyID.Av)).StringValue);
                TvCoBox.SelectedIndex      = TvCoBox.Items.IndexOf(TvValues.GetValue(MainCamera.GetInt32Setting(PropertyID.Tv)).StringValue);
                ISOCoBox.SelectedIndex     = ISOCoBox.Items.IndexOf(ISOValues.GetValue(MainCamera.GetInt32Setting(PropertyID.ISO)).StringValue);
                SettingsGroupBox.IsEnabled = true;
                LiveViewGroupBox.IsEnabled = true;
                //SaveFolderBrowser.SelectedPath = SavePathTextBox.Text; //new
            }
        }
Пример #11
0
        private void OpenSession()
        {
            if (CameraListBox.SelectedIndex >= 0)
            {
                MainCamera = CamList[CameraListBox.SelectedIndex];
                MainCamera.OpenSession();
                MainCamera.LiveViewUpdated += MainCamera_LiveViewUpdated;
                MainCamera.ProgressChanged += MainCamera_ProgressChanged;
                MainCamera.StateChanged    += MainCamera_StateChanged;
                MainCamera.DownloadReady   += MainCamera_DownloadReady;


                SessionButton.Content = "Close Session";
                SessionLabel.Content  = MainCamera.DeviceName;
                AvList  = MainCamera.GetSettingsList(PropertyID.Av);
                TvList  = MainCamera.GetSettingsList(PropertyID.Tv);
                ISOList = MainCamera.GetSettingsList(PropertyID.ISO);
                foreach (var Av in AvList)
                {
                    AvCoBox.Items.Add(Av.StringValue);
                }
                foreach (var Tv in TvList)
                {
                    TvCoBox.Items.Add(Tv.StringValue);
                }
                foreach (var ISO in ISOList)
                {
                    ISOCoBox.Items.Add(ISO.StringValue);
                }
                AvCoBox.SelectedIndex      = AvCoBox.Items.IndexOf(AvValues.GetValue(MainCamera.GetInt32Setting(PropertyID.Av)).StringValue);
                TvCoBox.SelectedIndex      = TvCoBox.Items.IndexOf(TvValues.GetValue(MainCamera.GetInt32Setting(PropertyID.Tv)).StringValue);
                ISOCoBox.SelectedIndex     = ISOCoBox.Items.IndexOf(ISOValues.GetValue(MainCamera.GetInt32Setting(PropertyID.ISO)).StringValue);
                SettingsGroupBox.IsEnabled = true;
                LiveViewGroupBox.IsEnabled = true;

                if ((bool)STComputerRdButton.IsChecked)
                {
                    MainCamera.SetSetting(PropertyID.SaveTo, (int)SaveTo.Host);
                }
                else if ((bool)STBothRdButton.IsChecked)
                {
                    MainCamera.SetSetting(PropertyID.SaveTo, (int)SaveTo.Both);
                }
                MainCamera.SetCapacity(4096, int.MaxValue);
                // MessageBox.Show("dupa", "Error", MessageBoxButton.OK, MessageBoxImage.None);
            }
        }
Пример #12
0
        public void StartExposure(double Duration, bool Light)
        {
            OpenSession();
            InitSettings();

            _duration  = Duration;
            _startTime = DateTime.Now;
            _canceledFlag.IsCanceled = false;

            if (Duration >= 1)
            {
                MainCamera.SetSetting(PropertyID.Tv, TvValues.GetValue("Bulb").IntValue);
                MainCamera.TakePhotoBulbAsync((int)(Duration * 1000), _canceledFlag);
            }
            else
            {
                CameraValue tvCameraValue = GetSelectedTv(Duration);
                MainCamera.SetSetting(PropertyID.Tv, tvCameraValue.IntValue);
                MainCamera.TakePhoto();
            }
        }
        private void TvCoBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                if (TvCoBox.SelectedIndex < 0)
                {
                    return;
                }

                MainCamera.SetSetting(PropertyID.Tv, TvValues.GetValue((string)TvCoBox.SelectedItem).IntValue);
                if ((string)TvCoBox.SelectedItem == "Bulb")
                {
                    BulbBox.IsEnabled    = true;
                    BulbSlider.IsEnabled = true;
                }
                else
                {
                    BulbBox.IsEnabled    = false;
                    BulbSlider.IsEnabled = false;
                }
            }
            catch (Exception ex) { ReportError(ex.Message, false); }
        }
Пример #14
0
        public void StartExposure(double Duration, bool Light)
        {
            if (!IsLiveViewMode)
            {
                InitSettings();

                _duration  = Duration;
                _startTime = DateTime.Now;
                _canceledFlag.IsCanceled = false;

                MainCamera.IsOldCanon();

                if (MainCamera.IsManualMode())
                {
                    if (Duration > 30)
                    {
                        Logger.WriteTraceMessage("ManualMode and > 30.0");
                        MainCamera.SetSetting(PropertyID.Tv, TvValues.GetValue("Bulb").IntValue);
                        MainCamera.TakePhotoBulbAsync((int)(Duration * 1000), _canceledFlag);
                    }
                    else
                    {
                        Logger.WriteTraceMessage("ManualMode and < 30.0");
                        CameraValue tvCameraValue = GetSelectedTv(Duration);
                        MainCamera.SetSetting(PropertyID.Tv, tvCameraValue.IntValue);
                        MainCamera.TakePhoto();
                    }
                }
                else
                {
                    if (MainCamera.IsBulbMode())
                    {
                        if (Duration >= 1)
                        {
                            Logger.WriteTraceMessage("BulbMode and > 1.0");
                            MainCamera.TakePhotoBulbAsync((int)(Duration * 1000), _canceledFlag);
                        }
                        else
                        {
                            Logger.WriteTraceMessage("BulbMode and < 1.0");
                            MainCamera.TakePhotoBulbAsync((int)(Duration * 1000), _canceledFlag);
                        }
                    }
                    else
                    {
                        Logger.WriteTraceMessage("For old cameras the wheel needs to be (M) position and for newer cameras the wheel needs to be (B) position");
                        throw new InvalidOperationException("For old cameras the wheel needs to be (M) position and for newer cameras the wheel needs to be (B) position");
                    }
                }

                /* Old Code when I was trobleshooting
                 * if (Duration >= 1 )
                 * {
                 *      if (MainCamera.IsManualMode() || MainCamera.IsOldCanon()) {
                 *      Logger.WriteTraceMessage(">= 1 ManualMode or Oldcanon");
                 *      MainCamera.SetSetting(PropertyID.Tv, TvValues.GetValue("Bulb").IntValue);
                 *      }
                 *      MainCamera.TakePhotoBulbAsync((int)(Duration * 1000), _canceledFlag);
                 *
                 * }
                 * else
                 * {
                 *  Logger.WriteTraceMessage("< 1");
                 *
                 *  if (MainCamera.IsOldCanon() || MainCamera.IsManualMode())
                 *  {
                 *      CameraValue tvCameraValue = GetSelectedTv(Duration);
                 *      Logger.WriteTraceMessage("< 1 ManualMode or Oldcanon");
                 *      MainCamera.SetSetting(PropertyID.Tv, tvCameraValue.IntValue);
                 *      MainCamera.TakePhoto();
                 *  }
                 *  else
                 *  {
                 *      Logger.WriteTraceMessage("Not Old or Manual");
                 *      if (MainCamera.IsBulbMode())
                 *      {
                 *          Logger.WriteTraceMessage("New Canon BulbMode");
                 *          MainCamera.TakePhotoBulbAsync((int)(Duration * 1000), _canceledFlag);
                 *      }
                 *
                 *  }
                 *
                 * }*/
            }
            else
            {
                Thread.Sleep(100);
                _lvCapture = true;
            }
        }
Пример #15
0
        static void Main(string[] args)
        {
            try
            {
                APIHandler = new CanonAPI();
                List <Camera> cameras = APIHandler.GetCameraList();
                if (!OpenSession())
                {
                    Console.WriteLine("No camera found. Please plug in camera");
                    APIHandler.CameraAdded += APIHandler_CameraAdded;
                    WaitEvent.WaitOne();
                    WaitEvent.Reset();
                }

                if (!Error)
                {
                    //ImageSaveDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "RemotePhoto");
                    ImageSaveDirectory = "G:\\CSE260\\dataset\\3";
                    MainCamera.SetSetting(PropertyID.SaveTo, (int)SaveTo.Host);
                    MainCamera.SetCapacity(4096, int.MaxValue);
                    Console.WriteLine($"Set image output path to: {ImageSaveDirectory}");

                    int SHUTTER_ID = 30;

                    // Get aperture and shutter speed tables
                    CameraValue[] AvList = MainCamera.GetSettingsList(PropertyID.Av);
                    CameraValue[] TvList = MainCamera.GetSettingsList(PropertyID.Tv);


                    // Loop over all aperture
                    for (int i_av = 0; i_av < AvList.Length; ++i_av)
                    {
                        // Validate shutter speed
                        if (SHUTTER_ID - i_av >= TvList.Length)
                        {
                            Console.WriteLine("shutter speed out of bounds");
                            break;
                        }


                        // Set Aperture and Shutter Speed
                        MainCamera.SetSetting(PropertyID.Av, AvValues.GetValue((string)AvList[i_av]).IntValue);
                        MainCamera.SetSetting(PropertyID.Tv, TvValues.GetValue((string)TvList[SHUTTER_ID - i_av]).IntValue);

                        Console.WriteLine("set av to " + (string)AvList[i_av]);
                        Console.WriteLine("set tv to " + (string)TvList[SHUTTER_ID - i_av]);

                        System.Threading.Thread.Sleep(500);

                        int now_av = MainCamera.GetInt32Setting(PropertyID.Av);
                        int now_tv = MainCamera.GetInt32Setting(PropertyID.Tv);

                        if ((int)AvList[i_av] != now_av)
                        {
                            Console.WriteLine("av comfirmation failed");
                        }
                        if ((int)TvList[SHUTTER_ID - i_av] != now_tv)
                        {
                            Console.WriteLine("tv comfirmation failed");
                        }


                        double shutterTime = TvList[SHUTTER_ID - i_av].DoubleValue;
                        int    waitTime    = (int)(shutterTime * 1000 + 2000);
                        Console.WriteLine("Wait Time is " + waitTime);

                        // 22 +3 Steps
                        for (int f = 0; f < 22; ++f)
                        {
                            int actualf = f;
                            if (!atFar)
                            {
                                actualf = 21 - f;
                            }

                            ImageFileName = now_av + "_" + actualf + ".CR3";

                            MainCamera.TakePhoto();

                            System.Threading.Thread.Sleep(waitTime);

                            // Flip the step direction each time to save time
                            if (atFar)
                            {
                                MainCamera.SendCommand(CameraCommand.DriveLensEvf, (int)DriveLens.Near3);
                            }
                            else
                            {
                                MainCamera.SendCommand(CameraCommand.DriveLensEvf, (int)DriveLens.Far3);
                            }

                            System.Threading.Thread.Sleep(500);
                        }

                        // Flip far->near and far<-near
                        atFar = !atFar;
                    }

                    /*
                     * try { MainCamera.SendCommand(CameraCommand.DriveLensEvf, (int)DriveLens.Far3); }
                     * catch (Exception ex)
                     * { Console.WriteLine(ex); }*/

                    /*
                     * Console.WriteLine("Taking photo with current settings...");
                     * CameraValue tv = TvValues.GetValue(MainCamera.GetInt32Setting(PropertyID.Tv));
                     * if (tv == TvValues.Bulb) MainCamera.TakePhotoBulb(2);
                     * else MainCamera.TakePhoto();
                     * WaitEvent.WaitOne();
                     */

                    if (!Error)
                    {
                        Console.WriteLine("Photo taken and saved");
                    }
                }
            }
            catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); }
            finally
            {
                Console.WriteLine("finally");
                MainCamera?.Dispose();
                APIHandler.Dispose();
                Console.WriteLine("Good bye! (press any key to close)");
                Console.ReadKey();
            }
        }
Пример #16
0
        public async Task <object> TakePhoto(dynamic input)
        {
            NodeResult result = new NodeResult();

            try
            {
                Console.WriteLine("Called C# method from node.");
                APIHandler = new CanonAPI();

                Console.WriteLine("APIHandler initialised");
                List <Camera> cameras = APIHandler.GetCameraList();
                foreach (var camera in cameras)
                {
                    Console.WriteLine("APIHandler GetCameraList:" + camera);
                }

                if (cameras.Count > 0)
                {
                    MainCamera = cameras[0];
                    MainCamera.DownloadReady += MainCamera_DownloadReady;
                    MainCamera.OpenSession();
                    Console.WriteLine($"Opened session with camera: {MainCamera.DeviceName}");
                }
                else
                {
                    Console.WriteLine("No camera found. Please plug in camera");
                    APIHandler.CameraAdded += APIHandler_CameraAdded;
                    WaitEvent.WaitOne();
                    WaitEvent.Reset();
                }
                Console.WriteLine("OpenSession");
                if (!Error)
                {
                    if (ImageSaveDirectory == null)
                    {
                        ImageSaveDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "RemotePhoto");
                    }
                    MainCamera.SetSetting(PropertyID.SaveTo, (int)SaveTo.Host);
                    MainCamera.SetCapacity(4096, int.MaxValue);
                    Console.WriteLine($"Set image output path to: {ImageSaveDirectory}");

                    Console.WriteLine("Taking photo with current settings...");
                    CameraValue tv = TvValues.GetValue(MainCamera.GetInt32Setting(PropertyID.Tv));
                    if (tv == TvValues.Bulb)
                    {
                        MainCamera.TakePhotoBulb(2);
                    }
                    else
                    {
                        MainCamera.TakePhoto();
                    }
                    WaitEvent.WaitOne();

                    if (!Error)
                    {
                        Console.WriteLine("Photo taken and saved");
                    }
                    result.message = "Photo taken and saved";
                    result.success = true;
                }
            }
            catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); }
            finally
            {
                MainCamera?.Dispose();
                APIHandler.Dispose();
                Console.WriteLine("Program exited.");
            }

            return(result);
        }