static void Api_CameraAdded(CanonAPI sender) { var camList = sender.GetCameraList(); MainCamera = camList[0]; Waiter.Set(); }
private void RefreshCameras() { Cameras = Api.GetCameraList(); CameraListBox.Items.Clear(); foreach (var cam in Cameras) { CameraListBox.Items.Add(cam.DeviceName); } if (Cameras.Count == 0) { SessionButton.Enabled = false; } else { int idx = Cameras.FindIndex(t => t.SessionOpen); if (idx != -1) { CameraListBox.SelectedIndex = idx; } else { CameraListBox.SelectedIndex = 0; } } }
public bool Initialize() { 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(); return(false); } else { MainCamera.CloseSession(); Console.WriteLine("Session closed"); return(true); } } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); return(false); } finally { MainCamera?.Dispose(); APIHandler.Dispose(); } }
private void ScanForCameras() { CamList = APIHandler.GetCameraList(); if (!CamList.Any()) { throw new NotConnectedException(ErrorMessages.NotConnected); } }
private void btnRefreshCameras_Click(object sender, EventArgs e) { List <Camera> cameraList = api.GetCameraList(); foreach (Camera c in cameraList) { cbCameras.Items.Add(new CameraListItem(c)); } }
public async Task <object> BeginSession(dynamic input) { LogMessage("Beginning session"); try { CameraAddedWaiter = new AutoResetEvent(false); if (Api == null) { Api = new CanonAPI(); Api.CameraAdded += APIHandler_CameraAdded; } LogMessage("APIHandler initialised"); List <Camera> cameras = Api.GetCameraList(); foreach (var camera in cameras) { LogMessage("APIHandler GetCameraList:" + camera); } if (cameras.Count > 0) { OpenSession(cameras[0]); } else { LogMessage("No camera found. Please plug in camera"); CameraAddedWaiter.WaitOne(); CameraAddedWaiter.Reset(); } var result = new NodeResult(); result.message = $"Opened session with camera: {MainCamera.DeviceName}"; result.success = true; return(result); } catch (Exception ex) { return(HandleException(ex)); } }
public override CameraModel ScanCameras() { CamList = APIHandler.GetCameraList(); if (!CamList.Any()) { throw new NotConnectedException(ErrorMessages.NotConnected); } _mainCamera = CamList.First(); var cameraModel = GetCameraModel(_mainCamera.DeviceName); return(cameraModel); }
public List <Camera> GetCameraList() { CamList.Clear(); //try //{ // CamList = APIHandler.GetCameraList(); //} //catch (Exception ex) //{ // ReportError(ex.Message, false); //} CamList = APIHandler.GetCameraList(); return(CamList); }
private void RefreshCamera() { CamList.Clear(); CamList = APIHandler.GetCameraList(); if (CamList.Count > 0) { OpenSession(); MainCamera.SetSetting(PropertyID.SaveTo, (int)SaveTo.Both); MainCamera.SetCapacity(4096, int.MaxValue); } else { //refresh } }
private void GetCamera() { if (MainCamera == null) { var camList = Api.GetCameraList(); if (camList.Count > 0) { MainCamera = camList[0]; MainCamera.OpenSession(); MainCamera.DownloadReady += MainCamera_DownloadReady; CameraLabel.Text = MainCamera.DeviceName; SetUI(true); } } }
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(); } }
private void RefreshCamera() { CameraListBox.Items.Clear(); CamList = APIHandler.GetCameraList(); foreach (Camera cam in CamList) { CameraListBox.Items.Add(cam.DeviceName); } if (MainCamera?.SessionOpen == true) { CameraListBox.SelectedIndex = CamList.FindIndex(t => t.ID == MainCamera.ID); } else if (CamList.Count > 0) { CameraListBox.SelectedIndex = 0; } }
private static bool OpenSession() { List <Camera> cameras = APIHandler.GetCameraList(); if (cameras.Count > 0) { MainCamera = cameras[0]; MainCamera.DownloadReady += MainCamera_DownloadReady; MainCamera.OpenSession(); Console.WriteLine($"Opened session with camera: {MainCamera.DeviceName}"); return(true); } else { return(false); } }
void GetAvailableCameras() { InitCanonApi(); lvCamera.Items.Clear(); _listOfCameras = _canonApi.GetCameraList(); foreach (var cam in _listOfCameras) { lvCamera.Items.Add(cam.DeviceName); } if (lvCamera.Items.Count != 0) { var cameraName = Properties.Settings.Default.CameraName; var itemIndex = lvCamera.FindString(cameraName); if (itemIndex != -1) { lvCamera.SelectedIndex = itemIndex; } } }
private void RefreshCamera() { CameraListBox.Items.Clear(); CamList = APIHandler.GetCameraList(); foreach (Camera cam in CamList) { CameraListBox.Items.Add(cam.DeviceName); } if (MainCamera?.SessionOpen == true) { CameraListBox.SelectedIndex = CamList.FindIndex(t => t.ID == MainCamera.ID); } else if (CamList.Count > 0) { CameraListBox.SelectedIndex = 0; } var ports = SerialPort.GetPortNames(); cBoxCOMPORT.DataSource = ports; }
/* * Stub example for reference: */ public async Task <object> BeginSession(dynamic input) { var 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(); } result.message = $"Opened session with camera: {MainCamera.DeviceName}"; result.success = true; }catch (Exception ex) { result.message = ex.Message; result.success = false; } return(result); }
private void OpenSession() { CamList = APIHandler.GetCameraList(); if (MainCamera?.SessionOpen == true) { CamList.FindIndex(t => t.ID == MainCamera.ID); //TODO } else if (CamList.Count > 0) { MainCamera = CamList[0]; MainCamera.OpenSession(); MainCamera.LiveViewUpdated += MainCamera_LiveViewUpdated; MainCamera.ProgressChanged += MainCamera_ProgressChanged; MainCamera.StateChanged += MainCamera_StateChanged; MainCamera.DownloadReady += MainCamera_DownloadReady; this.Text = MainCamera.DeviceName; MainCamera.SetSetting(PropertyID.SaveTo, (int)SaveTo.Both); MainCamera.SetCapacity(4096, int.MaxValue); pictureBox.Click += TakePhotoButton_Click; MainCamera.StartLiveView(); } }
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); }
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(); } }
private void RefreshCamera() { CamList = APIHandler.GetCameraList(); }
static void Main(string[] args) { try { Console.WriteLine("Starting up..."); Waiter = new AutoResetEvent(false); Api = new CanonAPI(); var camList = Api.GetCameraList(); if (camList.Count == 0) { Api.CameraAdded += Api_CameraAdded; Console.WriteLine("Please connect a camera..."); Waiter.WaitOne(); } else { MainCamera = camList[0]; } Console.WriteLine("Open session with " + MainCamera.DeviceName + "..."); MainCamera.OpenSession(); MainCamera.DownloadReady += MainCamera_DownloadReady; MainCamera.FileDownloaded += MainCamera_FileDownloaded; MainCamera.SaveTo = SaveTo.Host; MainCamera.SetCapacity(4096, 999999999); Console.WriteLine("Press any key to take a photo..."); Console.ReadKey(); if (MainCamera.IsShutterButtonAvailable) { MainCamera.SC_PressShutterButton(ShutterButton.Completely); MainCamera.SC_PressShutterButton(ShutterButton.OFF); } else { MainCamera.SC_TakePicture(); } Console.WriteLine("Waiting for download..."); Waiter.WaitOne(); Console.WriteLine("Closing session..."); MainCamera.DownloadReady -= MainCamera_DownloadReady; MainCamera.FileDownloaded -= MainCamera_FileDownloaded; MainCamera.CloseSession(); } catch (DllNotFoundException) { Console.WriteLine("Canon DLLs not found. They should lie beside the executable."); } catch (SDKException SDKex) { if (SDKex.Error == ErrorCode.TAKE_PICTURE_AF_NG) { Console.WriteLine("Couldn't focus"); } else { throw; } } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); } finally { Console.WriteLine("Disposing resources..."); if (MainCamera != null) { MainCamera.Dispose(); } if (Api != null) { Api.Dispose(); } Console.WriteLine("Press any key to close..."); Console.ReadKey(); } }