public async Task <object> StopVideo(dynamic input) { LogMessage("Stopping video capture"); bool shouldRestartLiveView = HasInputValue(input, "shouldRestartLiveView") ? (bool)input.shouldRestartLiveView : false; try { EnsureCameraSessionOpened(); DownloadReadyWaiter.Reset(); MainCamera.StopFilming(saveFilm: true, stopLiveView: false); DownloadReadyWaiter.WaitOne(); var result = new NodeResult(); result.message = "Stopped recording video."; result.success = true; return(result); } catch (Exception ex) { return(HandleException(ex)); } finally { if (!shouldRestartLiveView && IsCameraSessionOpened()) { MainCamera.StopLiveView(); } } }
/* * Stub example for reference: */ public async Task <object> StartVideo(dynamic input) { var result = new NodeResult(); //Method work goes here... try { Recording state = (Recording)MainCamera.GetInt32Setting(PropertyID.Record); if (state != Recording.On) { MainCamera.StartFilming(true); result.message = "Camera is in record mode"; result.success = true; } else { result.message = "Camera must be in record mode"; result.success = false; } } catch (Exception ex) { } finally { } return(result); }
public async Task <object> StartVideo(dynamic input) { LogMessage("Starting video capture"); try { EnsureCameraSessionOpened(); // TODO: Start live view if needed by camera MainCamera.StartFilming(true); LogMessage("Started video capture"); var result = new NodeResult(); result.message = "Started recording video"; result.success = true; return(result); } catch (Exception ex) { return(HandleException(ex)); } }
public async Task <object> StartLiveView(dynamic input) { LogMessage("Starting live view"); try { EnsureCameraSessionOpened(); LiveViewUpdates = 0; LiveViewWaiter.Reset(); MainCamera.StartLiveView(); LogMessage("Waiting for first live view"); LiveViewWaiter.WaitOne(); LogMessage("Live view started"); NodeResult result = new NodeResult(); result.message = "Live view started"; result.success = true; return(result); } catch (Exception ex) { return(HandleException(ex)); } }
/* * Stub example for reference: */ public async Task <object> EndSession(dynamic input) { var result = new NodeResult(); //Method work goes here... result.message = "Example message - did the method call succeed?"; result.success = false; return(result); }
private static NodeResult HandleException(Exception ex) { LogMessage("Error: " + ex.ToString()); var result = new NodeResult(); result.message = "Error: " + ex.Message; result.success = false; return(result); }
public async Task <object> EndSession(dynamic input) { LogMessage("Ending session"); MainCamera?.Dispose(); MainCamera = null; Api.Dispose(); Api = null; var result = new NodeResult(); result.message = "Camera session ended."; result.success = true; return(result); }
public async Task <object> SetOutputPath(dynamic input) { try { LogMessage($"Setting output path to \"{input.outputPath}\""); SaveDirectory = (string)input.outputPath; var result = new NodeResult(); result.message = "Set output path to " + (string)input.outputPath; result.success = true; return(result); } catch (Exception ex) { return(HandleException(ex)); } }
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 async Task <object> DownloadLastCapturedFile(dynamic input) { LogMessage($"Downloading last captured file"); bool deleteFile = HasInputValue(input, "deleteFile") ? (bool)input.deleteFile : true; if (LastCapturedFileInfo == null) { var result = new NodeResult(); result.message = "No file has been captured yet"; result.success = false; return(result); } try { EnsureCameraSessionOpened(); string downloadedFilePath = await DownloadFile(LastCapturedFileInfo); LogMessage("Last captured file downloaded"); if (deleteFile) { await DeleteLastCapturedFile(); } var result = new MediaResult(); result.message = "Downloaded file"; result.path = downloadedFilePath; result.success = true; return(result); } catch (Exception ex) { return(HandleException(ex)); } }
public async Task <object> CallCameraMethod(dynamic input) { LogMessage($"Calling camera method: {input.method}"); try { EnsureCameraSessionOpened(); typeof(Camera).GetMethod((string)input.method).Invoke(MainCamera, new object[] {}); var result = new NodeResult(); result.message = $"CallCameraMethod: "; result.success = true; return(result); } catch (Exception ex) { return(HandleException(ex)); } }
public async Task <object> SetOutputPath(dynamic input) { var result = new NodeResult(); try { Console.WriteLine("Attempting to set ImageSaveDirectory to " + (string)input.outputPath); ImageSaveDirectory = (string)input.outputPath; result.message = "Success."; result.success = true; } catch (Exception ex) { //Can't use requested path, resetting to default ImageSaveDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "RemotePhoto"); Console.WriteLine(ex.Message.ToString()); Console.WriteLine("Can't use requested path, resetting to default:" + ImageSaveDirectory.ToString()); result.message = ex.Message.ToString(); result.success = false; } return(result); }
/* * 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); }
public async Task <object> StopLiveView(dynamic input) { LogMessage("Stopping live view"); try { EnsureCameraSessionOpened(); MainCamera.StopLiveView(); LogMessage("Live view stopped"); NodeResult result = new NodeResult(); result.message = "Live view stopped"; result.success = true; return(result); } catch (Exception ex) { return(HandleException(ex)); } }
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); }