PVCAM  3.9.x
Programmable Virtual Camera Access Method library
Live Image Software Trigger

This example application demonstrates how to setup and run the camera in a 'fast' software trigger mode using the pl_exp_trigger API call.

This mode is supported only on newer camera models. With other cameras, applications may still use so called 'emulated' software trigger that uses a repeated sequence of single frame (pl_exp_start_seq).

The 'fast' software trigger may provide better latency, measured at about 100-500us depending on the camera interface. The 'emulated' software trigger usually yields latencies starting from 500us and up, depending on the camera interface, firmware and PVCAM version.

This sample code triggers the camera every one second and collects 50 frames. It is similar to the Live Image Callbacks example and therefore only the code parts that are different are shown below.

The code reads all available values from PARAM_EXPOSURE_MODE and checks the EXT_TRIG_SOFTWARE_EDGE mode is on the list. If that mode is missing, the camera does not support 'fast' software trigger feature and the application exits.

This code example uses the recommended callbacks acquisition (see Polling versus Callbacks). A part of the code omitted here defines a static callback function and registers the function with PVCAM. This approach is used in other code samples as well. The relevant code part is described in Frame Callback Handler section.

Once the acquisition is configured (pl_exp_setup_cont), the circular buffer is allocated and acquisition is started (pl_exp_start_cont), a helper function PeriodicTimerStart is called. That function creates a new timer thread that 'sends' a software trigger to PVCAM and sleeps for one second in an infinite loop.

auto nextTrigTime = std::chrono::steady_clock::now();
while (g_periodicTimerActive)
{
nextTrigTime += std::chrono::milliseconds(intervalMs);
// Trigger the camera
uns32 flags = 0;
if (PV_OK != pl_exp_trigger(ctx->hcam, &flags, 0))
{
PrintErrorMessage(pl_error_code(), "SW Trigger failed, pl_exp_trigger() error");
break;
}
...
std::this_thread::sleep_until(nextTrigTime);
}

Then, in a simple loop on main thread, 50 frames are acquired. Afterwards, the timer thread is stopped via PeriodicTimerStop helper function, continuous acquisition is stopped (pl_exp_abort), and all other resources are released before the application exits.