Skip to content

Commit

Permalink
camera: test for enum entry availability before use
Browse files Browse the repository at this point in the history
The previous error code test was bogus, and polluted the debug output with a
useless warning.
  • Loading branch information
EmmanuelP committed Aug 17, 2021
1 parent f9d9d86 commit 03a232f
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 46 deletions.
104 changes: 65 additions & 39 deletions src/arvcamera.c
Original file line number Diff line number Diff line change
Expand Up @@ -990,11 +990,12 @@ arv_camera_set_frame_rate (ArvCamera *camera, double frame_rate, GError **error)
switch (priv->vendor) {
case ARV_CAMERA_VENDOR_BASLER:
/* Disabling AcquisitionStart is required on some Basler cameras. Just ignore a failure. */
arv_camera_set_string (camera, "TriggerSelector", "AcquisitionStart", &local_error);
if (local_error == NULL)
arv_camera_set_string (camera, "TriggerMode", "Off", &local_error);
else
g_clear_error (&local_error);
if (arv_camera_is_enumeration_entry_available (camera, "TriggerSelector", "AcquisitionStart",
&local_error)) {
arv_camera_set_string (camera, "TriggerSelector", "AcquisitionStart", &local_error);
if (local_error == NULL)
arv_camera_set_string (camera, "TriggerMode", "Off", &local_error);
}

if (local_error == NULL)
arv_camera_set_string (camera, "TriggerSelector", "FrameStart", &local_error);
Expand Down Expand Up @@ -1064,24 +1065,34 @@ arv_camera_set_frame_rate (ArvCamera *camera, double frame_rate, GError **error)
case ARV_CAMERA_VENDOR_XIMEA:
case ARV_CAMERA_VENDOR_MATRIX_VISION:
case ARV_CAMERA_VENDOR_UNKNOWN:
arv_camera_set_string (camera, "TriggerSelector", "FrameStart", &local_error);
if (local_error == NULL)
arv_camera_set_string (camera, "TriggerMode", "Off", &local_error);
else
g_clear_error (&local_error);
if (local_error == NULL)
arv_camera_set_float (camera,
priv->has_acquisition_frame_rate ?
"AcquisitionFrameRate":
"AcquisitionFrameRateAbs", frame_rate, &local_error);
if (local_error == NULL) {
if (arv_camera_is_feature_available (camera, "AcquisitionFrameRateEnable", &local_error)) {
if (local_error == NULL)
arv_camera_set_boolean (camera, "AcquisitionFrameRateEnable", TRUE, &local_error);
}
}
break;
}
if (local_error == NULL &&
arv_camera_is_enumeration_entry_available (camera, "TriggerSelector", "FrameStart",
&local_error)) {
arv_camera_set_string (camera, "TriggerSelector", "FrameStart", &local_error);
if (local_error == NULL)
arv_camera_set_string (camera, "TriggerMode", "Off", &local_error);
}
if (local_error == NULL &&
arv_camera_is_enumeration_entry_available (camera, "TriggerSelector", "AcquisitionStart",
&local_error)) {
arv_camera_set_string (camera, "TriggerSelector", "AcquisitionStart", &local_error);
if (local_error == NULL)
arv_camera_set_string (camera, "TriggerMode", "Off", &local_error);
}

if (local_error == NULL)
arv_camera_set_float (camera,
priv->has_acquisition_frame_rate ?
"AcquisitionFrameRate":
"AcquisitionFrameRateAbs", frame_rate, &local_error);
if (local_error == NULL) {
if (arv_camera_is_feature_available (camera, "AcquisitionFrameRateEnable", &local_error)) {
if (local_error == NULL)
arv_camera_set_boolean (camera, "AcquisitionFrameRateEnable", TRUE, &local_error);
}
}
break;
}

if (local_error != NULL)
g_propagate_error (error, local_error);
Expand Down Expand Up @@ -1246,33 +1257,26 @@ arv_camera_set_trigger (ArvCamera *camera, const char *source, GError **error)
if (priv->vendor == ARV_CAMERA_VENDOR_BASLER)
arv_camera_set_boolean (camera, "AcquisitionFrameRateEnable", FALSE, &local_error);

if (local_error == NULL) {
arv_camera_set_string (camera, "TriggerSelector", "FrameStart", &local_error);
if (local_error == NULL &&
arv_camera_is_enumeration_entry_available (camera, "TriggerSelector", "FrameStart", &local_error)) {
arv_camera_set_string (camera, "TriggerSelector", "FrameStart", &local_error);
if (local_error == NULL)
arv_camera_set_string (camera, "TriggerMode", "On", &local_error);
else if (local_error->code == ARV_DEVICE_ERROR_FEATURE_NOT_FOUND ||
local_error->code == ARV_GC_ERROR_ENUM_ENTRY_NOT_FOUND) {
g_clear_error (&local_error);
has_frame_start = FALSE;
}
} else {
has_frame_start = FALSE;
}


if (local_error == NULL) {
if (local_error == NULL &&
arv_camera_is_enumeration_entry_available (camera, "TriggerSelector", "AcquisitionStart", &local_error)) {
arv_camera_set_string (camera, "TriggerSelector", "AcquisitionStart", &local_error);
if (local_error == NULL)
arv_camera_set_string (camera, "TriggerMode",
has_frame_start ? "Off" : "On", &local_error);
else if (local_error->code == ARV_DEVICE_ERROR_FEATURE_NOT_FOUND ||
local_error->code == ARV_GC_ERROR_ENUM_ENTRY_NOT_FOUND)
g_clear_error (&local_error);
}

if (local_error == NULL && arv_camera_is_feature_available (camera, "TriggerActivation", NULL)) {
if (local_error == NULL
&& arv_camera_is_enumeration_entry_available (camera, "TriggerActivation", "RisingEdge", &local_error)) {
arv_camera_set_string (camera, "TriggerActivation", "RisingEdge", &local_error);
if (local_error != NULL && (local_error->code == ARV_DEVICE_ERROR_FEATURE_NOT_FOUND ||
local_error->code == ARV_GC_ERROR_ENUM_ENTRY_NOT_FOUND))
g_clear_error (&local_error);
}

if (local_error == NULL)
Expand Down Expand Up @@ -2387,6 +2391,28 @@ arv_camera_dup_available_enumerations_as_display_names (ArvCamera *camera, const
return arv_device_dup_available_enumeration_feature_values_as_display_names (priv->device, feature, n_values, error);
}

/**
* arv_camera_is_enumeration_entry_available:
* @camera: a #ArvCamera
* @feature: enumeration feature name
* @entry: entry name
* @error: a #GError placeholder, %NULL to ignore
*
* Returns: %TRUE if the feature and the feature entry are available
*
* Since: 0.8.17
*/

gboolean
arv_camera_is_enumeration_entry_available (ArvCamera *camera, const char *feature, const char *entry, GError **error)
{
ArvCameraPrivate *priv = arv_camera_get_instance_private (camera);

g_return_val_if_fail (ARV_IS_CAMERA (camera), FALSE);

return arv_device_is_enumeration_entry_available (priv->device, feature, entry, error);
}

/**
* arv_camera_is_feature_available:
* @camera: a #ArvCamera
Expand Down
14 changes: 8 additions & 6 deletions src/arvcamera.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,14 @@ double arv_camera_get_float (ArvCamera *camera, const char *feature, GError *
void arv_camera_get_float_bounds (ArvCamera *camera, const char *feature, double *min, double *max, GError **error);
double arv_camera_get_float_increment (ArvCamera *camera, const char *feature, GError **error);

gint64 * arv_camera_dup_available_enumerations (ArvCamera *camera, const char *feature, guint *n_values,
GError **error);
const char ** arv_camera_dup_available_enumerations_as_strings (ArvCamera *camera, const char *feature, guint *n_values,
GError **error);
const char ** arv_camera_dup_available_enumerations_as_display_names (ArvCamera *camera, const char *feature, guint *n_values,
GError **error);
gint64 * arv_camera_dup_available_enumerations (ArvCamera *camera, const char *feature,
guint *n_values, GError **error);
const char ** arv_camera_dup_available_enumerations_as_strings (ArvCamera *camera, const char *feature,
guint *n_values, GError **error);
const char ** arv_camera_dup_available_enumerations_as_display_names (ArvCamera *camera, const char *feature,
guint *n_values, GError **error);
gboolean arv_camera_is_enumeration_entry_available (ArvCamera *camera, const char *feature,
const char *entry, GError **error);

gboolean arv_camera_is_feature_available (ArvCamera *camera, const char *feature, GError **error);

Expand Down
43 changes: 43 additions & 0 deletions src/arvdevice.c
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,49 @@ arv_device_dup_available_enumeration_feature_values_as_display_names (ArvDevice
return NULL;
}

/**
* arv_device_is_enumeration_entry_available:
* @device: an #ArvDevice instance
* @feature: enumeration feature name
* @entry: entry name
* @error: a #GError placeholder
*
* Returns: %TRUE if the feature and the feature entry are available
*
* Since: 0.8.17
*/

gboolean
arv_device_is_enumeration_entry_available (ArvDevice *device, const char *feature, const char *entry, GError **error)
{
GError *local_error = NULL;
const char **entries = NULL;
guint n_entries = 0;
gboolean is_available = FALSE;
unsigned int i;

if (!arv_device_is_feature_available (device, feature, &local_error)) {
g_propagate_error (error, local_error);
return FALSE;
}

entries = arv_device_dup_available_enumeration_feature_values_as_strings (device, feature, &n_entries,
&local_error);

if (local_error != NULL) {
g_propagate_error (error, local_error);
return FALSE;
}

for (i = 0; i < n_entries && !is_available; i++) {
if (g_strcmp0 (entry, entries[i]) == 0)
is_available = TRUE;
}
g_free (entries);

return is_available;
}

/**
* arv_device_set_features_from_string:
* @device: a #ArvDevice
Expand Down
5 changes: 4 additions & 1 deletion src/arvdevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,10 @@ const char ** arv_device_dup_available_enumeration_feature_values_as_strings (A
guint *n_values, GError **error);
const char ** arv_device_dup_available_enumeration_feature_values_as_display_names (ArvDevice *device, const char *feature,
guint *n_values, GError **error);

gboolean arv_device_is_enumeration_entry_available (ArvDevice *device,
const char *feature,
const char *entry,
GError **error);

gboolean arv_device_set_features_from_string (ArvDevice *device, const char *string, GError **error);

Expand Down

0 comments on commit 03a232f

Please sign in to comment.