private void UpdateModeComboBox(TriggerModeInfo triggerInfo) { m_triggerModeComboBox.Items.Clear(); if (triggerInfo.present == true) { const int numTriggerModes = 16; for (int i = 0; i < numTriggerModes; i++) { int reverse = numTriggerModes - i - 1; bool modeAvailable = ((triggerInfo.modeMask >> reverse) & 0x1) == 1; if (modeAvailable == true) { m_triggerModeComboBox.Items.Add(i); } } m_triggerModeComboBox.Enabled = true; } else { m_triggerModeComboBox.Enabled = false; } }
static void Main(string[] args) { PrintBuildInfo(); const int NumImages = 10; bool useSoftwareTrigger = true; ManagedBusManager busMgr = new ManagedBusManager(); uint numCameras = busMgr.GetNumOfCameras(); Console.WriteLine("Number of cameras detected: {0}", numCameras); // Finish if there are no cameras if (numCameras == 0) { Console.WriteLine("Not enough cameras!"); Console.WriteLine("Press Enter to exit..."); Console.ReadLine(); return; } ManagedPGRGuid guid = busMgr.GetCameraFromIndex(0); ManagedCamera cam = new ManagedCamera(); cam.Connect(guid); // Power on the camera const uint CameraPower = 0x610; const uint CameraPowerValue = 0x80000000; cam.WriteRegister(CameraPower, CameraPowerValue); const Int32 MillisecondsToSleep = 100; uint cameraPowerValueRead = 0; // Wait for camera to complete power-up do { System.Threading.Thread.Sleep(MillisecondsToSleep); cameraPowerValueRead = cam.ReadRegister(CameraPower); }while ((cameraPowerValueRead & CameraPowerValue) == 0); // Get the camera information CameraInfo camInfo = cam.GetCameraInfo(); PrintCameraInfo(camInfo); if (!useSoftwareTrigger) { // Check for external trigger support TriggerModeInfo triggerModeInfo = cam.GetTriggerModeInfo(); if (triggerModeInfo.present != true) { Console.WriteLine("Camera does not support external trigger!"); Console.WriteLine("Press enter to exit..."); Console.ReadLine(); return; } } // Get current trigger settings TriggerMode triggerMode = cam.GetTriggerMode(); // Set camera to trigger mode 0 // A source of 7 means software trigger triggerMode.onOff = true; triggerMode.mode = 0; triggerMode.parameter = 0; if (useSoftwareTrigger) { // A source of 7 means software trigger triggerMode.source = 7; } else { // Triggering the camera externally using source 0. triggerMode.source = 0; } // Set the trigger mode cam.SetTriggerMode(triggerMode); // Poll to ensure camera is ready bool retVal = PollForTriggerReady(cam); if (retVal != true) { Console.WriteLine("Poll for trigger read failed!"); Console.WriteLine("Press enter to exit..."); Console.ReadLine(); return; } // Get the camera configuration FC2Config config = cam.GetConfiguration(); // Set the grab timeout to 5 seconds config.grabTimeout = 5000; // Set the camera configuration cam.SetConfiguration(config); // Camera is ready, start capturing images cam.StartCapture(); if (useSoftwareTrigger) { if (CheckSoftwareTriggerPresence(cam) == false) { Console.WriteLine("SOFT_ASYNC_TRIGGER not implemented on this camera! Stopping application\n"); Console.WriteLine("Press enter to exit..."); Console.ReadLine(); return; } } else { Console.WriteLine("Trigger the camera by sending a trigger pulse to GPIO%d.\n", triggerMode.source); } ManagedImage rawImage = new ManagedImage(); for (int iImageCount = 0; iImageCount < NumImages; iImageCount++) { if (useSoftwareTrigger) { // Check that the trigger is ready retVal = PollForTriggerReady(cam); Console.WriteLine("Press the Enter key to initiate a software trigger.\n"); Console.ReadLine(); // Fire software trigger retVal = FireSoftwareTrigger(cam); if (retVal != true) { Console.WriteLine("Error firing software trigger!"); Console.WriteLine("Press enter to exit..."); Console.ReadLine(); return; } } try { // Retrieve an image cam.RetrieveBuffer(rawImage); } catch (FC2Exception ex) { Console.WriteLine("Error retrieving buffer : {0}", ex.Message); continue; } Console.WriteLine(".\n"); } Console.WriteLine("Finished grabbing images"); // Stop capturing images cam.StopCapture(); // Turn off trigger mode triggerMode.onOff = false; cam.SetTriggerMode(triggerMode); // Disconnect the camera cam.Disconnect(); Console.WriteLine("Done! Press enter to exit..."); Console.ReadLine(); }
static void Main(string[] args) { PrintBuildInfo(); const int k_numImages = 10; bool useSoftwareTrigger = true; ManagedBusManager busMgr = new ManagedBusManager(); uint numCameras = busMgr.GetNumOfCameras(); Console.WriteLine("Number of cameras detected: {0}", numCameras); ManagedPGRGuid guid = busMgr.GetCameraFromIndex(0); ManagedCamera cam = new ManagedCamera(); cam.Connect(guid); // Get the camera information CameraInfo camInfo = cam.GetCameraInfo(); PrintCameraInfo(camInfo); if (!useSoftwareTrigger) { // Check for external trigger support TriggerModeInfo triggerModeInfo = cam.GetTriggerModeInfo(); if (triggerModeInfo.present != true) { Console.WriteLine("Camera does not support external trigger! Exiting...\n"); return; } } // Get current trigger settings TriggerMode triggerMode = cam.GetTriggerMode(); // Set camera to trigger mode 0 // A source of 7 means software trigger triggerMode.onOff = true; triggerMode.mode = 0; triggerMode.parameter = 0; if (useSoftwareTrigger) { // A source of 7 means software trigger triggerMode.source = 7; } else { // Triggering the camera externally using source 0. triggerMode.source = 0; } // Set the trigger mode cam.SetTriggerMode(triggerMode); // Poll to ensure camera is ready bool retVal = PollForTriggerReady(cam); if (retVal != true) { return; } // Get the camera configuration FC2Config config = cam.GetConfiguration(); // Set the grab timeout to 5 seconds config.grabTimeout = 5000; // Set the camera configuration cam.SetConfiguration(config); // Camera is ready, start capturing images cam.StartCapture(); if (useSoftwareTrigger) { if (CheckSoftwareTriggerPresence(cam) == false) { Console.WriteLine("SOFT_ASYNC_TRIGGER not implemented on this camera! Stopping application\n"); return; } } else { Console.WriteLine("Trigger the camera by sending a trigger pulse to GPIO%d.\n", triggerMode.source); } ManagedImage image = new ManagedImage(); for (int iImageCount = 0; iImageCount < k_numImages; iImageCount++) { if (useSoftwareTrigger) { // Check that the trigger is ready retVal = PollForTriggerReady(cam); Console.WriteLine("Press the Enter key to initiate a software trigger.\n"); Console.ReadLine(); // Fire software trigger retVal = FireSoftwareTrigger(cam); if (retVal != true) { Console.WriteLine("Error firing software trigger!"); return; } } // Grab image cam.RetrieveBuffer(image); Console.WriteLine(".\n"); } Console.WriteLine("Finished grabbing images"); // Stop capturing images cam.StopCapture(); // Turn off trigger mode triggerMode.onOff = false; cam.SetTriggerMode(triggerMode); // Disconnect the camera cam.Disconnect(); Console.WriteLine("Done! Press any key to exit..."); Console.ReadKey(); }