public void TestCameraFunctionality() { try { var camStatus = api.GetCamStatus(); Console.WriteLine($"Camera state {camStatus["state"]}, level {camStatus["level"]}, flags {camStatus["flags"]}"); Console.WriteLine($"\nCamera extended status - state {camStatus["state"]}, level {camStatus["level"]}, flags {camStatus["flags"]}, IS temp (C) {camStatus["is_temp"]}, FPGA temp (C) {camStatus["fpga_temp"]}"); Console.WriteLine($"\nStatus string: {api.GetStatusString()}"); Console.WriteLine($"\nDirectory path to active storage device: {api.GetStorageDir()}"); var storageInfo = api.GetStorageInfo(); Console.WriteLine($"\nStorage information: {storageInfo["available_space"]} / " + $"{storageInfo["storage_size"]} bytes, mount point: {storageInfo["mount_point"]}"); Console.WriteLine("\nCamera information:"); Console.Write(api.GetInfoString(" ")); var settings = api.GetSavedSettings(); Console.WriteLine("\nSaved camera settings:"); api.PrintSettings(settings, "requested_", " "); settings = api.GetCurrentSettings(); Console.WriteLine("\nCurrent requested camera settings:"); api.PrintSettings(settings, "requested_", " "); Console.WriteLine("\nCurrent allowed camera settings:"); api.PrintSettings(settings, "", " "); var requestedSettings = new CamDictionary() { { "requested_iso", null }, { "requested_exposure", 1 / 500.0 }, { "requested_frame_rate", 60 }, { "requested_horizontal", 640 }, { "requested_vertical", 480 }, { "requested_subsample", 1 }, { "requested_duration", 10 }, { "requested_pretrigger", 50 }, { "requested_multishot_count", 1 } }; settings = api.ConfigureCamera(requestedSettings); Console.WriteLine("\nRequested camera settings:"); api.PrintSettings(settings, "requested_", " "); Console.WriteLine("\nAllowed camera settings:"); api.PrintSettings(settings, "", " "); if (DoFavoritesTest) { var favoritesTests = new FavoritesTests(api); favoritesTests.Run(); } if (DoCaptureTest) { var captureTests = new CaptureTests(api); captureTests.RunCaptureCancelPostFill(settings); captureTests.RunCaptureSaveStop(settings); captureTests.RunCaptureVideo(settings, "Last saved file: {0}"); requestedSettings["duration"] = 1; settings = api.ConfigureCamera(requestedSettings); captureTests.RunCaptureVideo(settings, "Last saved file - should be '/tmp/hcamapi_tmp_test': {0}", "/tmp/hcamapi_tmp_test"); captureTests.RunCaptureVideo(settings, "Last saved file - should be 'hcamapi_test': {0}", "hcamapi_test"); } if (DoMultiCaptureTest) { var multishotCaptureTests = new MultiCaptureTests(api); multishotCaptureTests.Run(); multishotCaptureTests.Run(true); multishotCaptureTests.Run(TestCancellingPostTriggerFill: true); } if (DoCaptureTest || DoMultiCaptureTest) { Console.WriteLine("\nListing files in active storage video directory"); var fileList = api.FetchRemoteDirectoryListing(); foreach (var file in fileList) { Console.WriteLine($" {file}"); } string lastVideoFilename = api.GetLastSavedFilename(); api.DisplayRemoteFile($"{lastVideoFilename.Substring(1, lastVideoFilename.Length - 6)}.txt"); } } catch (Exception ex) { Console.WriteLine($"Error: {ex.Message}"); } }
private void MultiShotSaveVideos(long expectedVideoCount, int discardAfterVideo, int saveWait) { // param discard_after_video: set to zero to save all captured multishot videos or to the number of videos to save if (discardAfterVideo > 0) { Console.WriteLine($" Saving filled multishot buffers, discarding videos after video {discardAfterVideo} is saved"); } else { Console.WriteLine(" Saving filled multishot buffers"); } api.ExpectState(CAMERA_STATE.RUNNING); Save(); Thread.Sleep(1000); for (var x = 0; x < expectedVideoCount; x++) { var expectedBuffer = x + 1; var maxWait = saveWait; api.ExpectState(CAMERA_STATE.SAVING); var camStatus = api.GetCamStatus(); var capturedBuffers = (long)camStatus["captured_buffers"]; Console.WriteLine($" Captured buffers: {capturedBuffers}"); if (capturedBuffers != expectedVideoCount) { Console.WriteLine($" Error: captured buffer count doesn't match expected count: {capturedBuffers} != {expectedVideoCount}"); Environment.Exit(1); } while (expectedBuffer <= expectedVideoCount && maxWait > 0) { // camera stays in the save state the entire time the set of captured videos are saved // monitor progress by using the active buffer and save complete level camStatus = api.GetCamStatus(); var state = (CAMERA_STATE)camStatus["state"]; if (state != CAMERA_STATE.SAVING) { Console.WriteLine($" Current state: {api.GetTextState(state)}"); break; } var activeBuffer = (long)camStatus["active_buffer"]; Console.WriteLine($" Saving buffer {activeBuffer}/{expectedVideoCount} progress {camStatus["level"]} ({maxWait})"); if (expectedBuffer + 1 == activeBuffer) { break; } if (discardAfterVideo > 0 && discardAfterVideo + 1 == activeBuffer) { Console.WriteLine(" Discarding filled multishot buffers"); Thread.Sleep(2000); api.SaveStop(true); api.WaitForTransition("Waiting for truncation to finish", CAMERA_STATE.SAVE_TRUNCATING, 5); api.ExpectRunningState(); return; } Thread.Sleep(1000); maxWait--; } } api.ExpectRunningState(); }