Skip to content

Commit c654c02

Browse files
updated error handling
1 parent 3d16edf commit c654c02

File tree

1 file changed

+91
-37
lines changed

1 file changed

+91
-37
lines changed

src/bb/image-io/rt_u3v.h

Lines changed: 91 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ class U3V {
336336
devices_(num_sensor), buffers_(num_sensor), operation_mode_(OperationMode::Came1USB1), frame_cnt_(0), device_idx_(-1), disposed_(false), sim_mode_(sim_mode), order_filp_(false)
337337
{
338338
init_symbols();
339-
log::debug("U3V:: 24-08-30 : Tested on device 1.2");
339+
log::debug("U3V:: 24-09-03 : Tested on device 1.2");
340340
log::info("Using aravis-{}.{}.{}", arv_get_major_version(), arv_get_minor_version(), arv_get_micro_version());
341341
}
342342

@@ -500,7 +500,7 @@ class U3V {
500500
log::info("Acquisition option::{} is {}", "realtime_display_mode_", realtime_display_mode_);
501501
}
502502

503-
GError* command_acquisition_mode_contd_and_start(){
503+
void command_acquisition_mode_contd_and_start(){
504504
for (auto i=0; i<devices_.size(); ++i) {
505505
arv_device_set_string_feature_value(devices_[i].device_, "AcquisitionMode", arv_acquisition_mode_to_string(ARV_ACQUISITION_MODE_CONTINUOUS), &err_);
506506
if (err_) {
@@ -514,10 +514,9 @@ class U3V {
514514
}
515515
log::info("\tDevice/USB {}::{} : {}", i, "Command", "AcquisitionStart");
516516
}
517-
return err_;
518517
}
519518

520-
GError* open_fake_devices(int32_t width, int32_t height , float_t fps, const std::string & pixel_format){
519+
void open_fake_devices(int32_t width, int32_t height , float_t fps, const std::string & pixel_format){
521520
auto path = std::getenv("GENICAM_FILENAME");
522521
if (path == nullptr){
523522
throw std::runtime_error("Please define GENICAM_FILENAME by `set GENICAM_FILENAME=` or `export GENICAM_FILENAME=`");
@@ -529,13 +528,19 @@ class U3V {
529528
log::info("Creating U3V instance with {} fake sensors...", num_sensor_);
530529

531530
auto fake_camera0 = arv_camera_new ("Fake_1", &err_);
531+
if (err_) {
532+
throw std::runtime_error(err_->message);
533+
}
532534
auto fake_device0 = arv_camera_get_device(fake_camera0);
533535
devices_[0].device_ = fake_device0;
534536
devices_[0].dev_id_= "fake_0";
535537
devices_[0].camera_ = fake_camera0;
536538
if (num_sensor_==2){
537539
// aravis only provide on ARV_FAKE_DEVICE_ID https://github.com/Sensing-Dev/aravis/blob/main/src/arvfakeinterface.c
538540
auto fake_camera1 = arv_camera_new ("Fake_1", &err_);
541+
if (err_) {
542+
throw std::runtime_error(err_->message);
543+
}
539544
auto fake_device1 = arv_camera_get_device(fake_camera1);
540545
devices_[1].device_ = fake_device1;
541546
devices_[1].dev_id_= "fake_1";
@@ -546,13 +551,35 @@ class U3V {
546551
// setting the params if it is not zero
547552
log::info("Width {}, Height {} PixelFormat {}...", width, height, pixel_format_);
548553
arv_device_set_integer_feature_value (devices_[i].device_, "Width", width, &err_);
554+
if (err_) {
555+
throw std::runtime_error(err_->message);
556+
}
549557
arv_device_set_integer_feature_value (devices_[i].device_, "Height", height, &err_);
558+
if (err_) {
559+
throw std::runtime_error(err_->message);
560+
}
550561
arv_device_set_float_feature_value (devices_[i].device_, "AcquisitionFrameRate",fps, &err_);
551-
if (pixel_format_ != "Mono8")
562+
if (err_) {
563+
throw std::runtime_error(err_->message);
564+
}
565+
if (pixel_format_ != "Mono8"){
552566
arv_device_set_string_feature_value(devices_[i].device_, "PixelFormat", pixel_format.c_str(), &err_);
567+
if (err_) {
568+
throw std::runtime_error(err_->message);
569+
}
570+
}
553571
devices_[i].u3v_payload_size_ = arv_device_get_integer_feature_value (devices_[i].device_, "PayloadSize", &err_);
572+
if (err_) {
573+
throw std::runtime_error(err_->message);
574+
}
554575
auto px =arv_device_get_integer_feature_value(devices_[i].device_, "PixelFormat", &err_);
576+
if (err_) {
577+
throw std::runtime_error(err_->message);
578+
}
555579
auto fps = arv_device_get_float_feature_value(devices_[i].device_, "AcquisitionFrameRate", &err_);
580+
if (err_) {
581+
throw std::runtime_error(err_->message);
582+
}
556583
struct rawHeader header= { 1, width, height,
557584
1, 1, 1, 1, 1, 1, 0, 0, 0, 0,
558585
width, height, width, height, static_cast<float>(fps), px, 0};
@@ -561,10 +588,9 @@ class U3V {
561588
devices_[i].frame_count_ = 0;
562589

563590
}
564-
return err_;
565591
}
566592

567-
GError* open_real_devices(int32_t num_detected_device, int32_t num_usb_to_open, char* dev_id){
593+
void open_real_devices(int32_t num_detected_device, int32_t num_usb_to_open, char* dev_id){
568594

569595
int index_on_detected_device = 0;
570596
int index_on_opened_device = 0;
@@ -598,16 +624,18 @@ class U3V {
598624

599625
pixel_format_ = arv_device_get_string_feature_value(devices_[index_on_opened_device].device_, "PixelFormat", &err_);
600626
if (err_ ) {
601-
throw std::runtime_error(err_->message);
627+
log::error(err_->message);
628+
err_ = nullptr;
629+
}else{
630+
log::info("\tDevice/USB {}::{} : {}", index_on_opened_device, "PixelFormat", pixel_format_);
602631
}
603-
log::info("\tDevice/USB {}::{} : {}", index_on_opened_device, "PixelFormat", pixel_format_);
604-
632+
605633
// Here PayloadSize is the one for U3V data
606634
devices_[index_on_opened_device].u3v_payload_size_ = arv_device_get_integer_feature_value(devices_[index_on_opened_device].device_, "PayloadSize", &err_);
607-
log::info("\tDevice/USB {}::{} : {}", index_on_opened_device, "PayloadSize", devices_[index_on_opened_device].u3v_payload_size_);
608635
if (err_ ) {
609636
throw std::runtime_error(err_->message);
610637
}
638+
log::info("\tDevice/USB {}::{} : {}", index_on_opened_device, "PayloadSize", devices_[index_on_opened_device].u3v_payload_size_);
611639

612640
// check it the device has gendc mode ==============================
613641
is_gendc_ = arv_device_is_feature_available(devices_[index_on_opened_device].device_, "GenDCDescriptor", &err_);
@@ -632,19 +660,30 @@ class U3V {
632660
// Some type of U3V Camera supports Frame count generated by its device
633661
const char* device_vender_name;
634662
device_vender_name = arv_device_get_string_feature_value(devices_[index_on_opened_device].device_, "DeviceVendorName", &err_);
635-
if (strcmp(device_vender_name, "Sony Semiconductor Solutions Corporation")==0){
636-
const char* device_model_name;
637-
device_model_name = arv_device_get_string_feature_value(devices_[index_on_opened_device].device_, "DeviceModelName", &err_);
638-
if (strcmp(device_model_name, " ")==0){
639-
is_param_integer_ = true;
640-
frame_count_method_ = FrameCountMethod::TIMESTAMP;
641-
arv_uv_device_set_usb_mode(devices_[index_on_opened_device].device_, ARV_UV_USB_MODE_SYNC); //hotfix for v1.0
642-
}
643-
if (is_gendc_){
644-
frame_count_method_ = FrameCountMethod::TYPESPECIFIC3;
645-
order_filp_ = true;
663+
if (err_) {
664+
log::error(err_->message);
665+
err_ = nullptr;
666+
}else{
667+
if (strcmp(device_vender_name, "Sony Semiconductor Solutions Corporation")==0){
668+
const char* device_model_name;
669+
device_model_name = arv_device_get_string_feature_value(devices_[index_on_opened_device].device_, "DeviceModelName", &err_);
670+
if (err_) {
671+
log::error(err_->message);
672+
err_ = nullptr;
673+
}else{
674+
if (strcmp(device_model_name, " ")==0){
675+
is_param_integer_ = true;
676+
frame_count_method_ = FrameCountMethod::TIMESTAMP;
677+
arv_uv_device_set_usb_mode(devices_[index_on_opened_device].device_, ARV_UV_USB_MODE_SYNC); //hotfix for v1.0
678+
}
679+
}
680+
if (is_gendc_){
681+
frame_count_method_ = FrameCountMethod::TYPESPECIFIC3;
682+
order_filp_ = true;
683+
}
646684
}
647685
}
686+
648687
log::info("\tDevice/USB {}::{} : {}", index_on_opened_device, "frame_count method is ",
649688
frame_count_method_ == FrameCountMethod::TIMESTAMP ? "Timestamp":
650689
frame_count_method_ == FrameCountMethod::TYPESPECIFIC3 ? "TypeSpecific" : "Unavailabe");
@@ -694,17 +733,28 @@ class U3V {
694733
// Set Device Info =================================================
695734
{
696735
int32_t wi = arv_device_get_integer_feature_value(devices_[index_on_opened_device].device_, "Width", &err_);
736+
if (err_) {
737+
throw std::runtime_error(err_->message);
738+
}
697739
int32_t hi = arv_device_get_integer_feature_value(devices_[index_on_opened_device].device_, "Height", &err_);
740+
if (err_) {
741+
throw std::runtime_error(err_->message);
742+
}
698743
double fps = 0.0;
699744
if (arv_device_is_feature_available(devices_[index_on_opened_device].device_, "AcquisitionFrameRate", &err_)){
700745
fps = arv_device_get_float_feature_value(devices_[index_on_opened_device].device_, "AcquisitionFrameRate", &err_);
701746
}
747+
if (err_) {
748+
throw std::runtime_error(err_->message);
749+
}
702750
log::info("\tDevice/USB {}::{} : {}", index_on_opened_device, "Width", wi);
703751
log::info("\tDevice/USB {}::{} : {}", index_on_opened_device, "Height", hi);
704752

705753
int32_t px = arv_device_get_integer_feature_value (devices_[index_on_opened_device].device_, "PixelFormat", &err_);
706-
if (px == 0){
754+
if (err_ || px == 0){
707755
log::info("The pixel format is not supported for header info");
756+
err_ = nullptr;
757+
px = 0;
708758
}
709759

710760
devices_[index_on_opened_device].header_info_ = { 1, wi, hi,
@@ -714,8 +764,14 @@ class U3V {
714764
}
715765

716766
if (index_on_opened_device == 0 && arv_device_is_feature_available(devices_[index_on_opened_device].device_, "OperationMode", &err_)){
767+
if (err_) {
768+
throw std::runtime_error(err_->message);
769+
}
717770
const char* operation_mode_in_string;
718771
operation_mode_in_string = arv_device_get_string_feature_value(devices_[index_on_opened_device].device_, "OperationMode", &err_);
772+
if (err_) {
773+
throw std::runtime_error(err_->message);
774+
}
719775
if (strcmp(operation_mode_in_string, "Came2USB1")==0){
720776
operation_mode_ = OperationMode::Came2USB1;
721777
}else if (strcmp(operation_mode_in_string, "Came1USB1")==0){
@@ -737,10 +793,9 @@ class U3V {
737793

738794
index_on_detected_device += 1;
739795
}
740-
return err_;
741796
}
742797

743-
GError* create_stream_and_start_acquisition(bool specific_device_to_flip_order){
798+
void create_stream_and_start_acquisition(bool specific_device_to_flip_order){
744799
/*
745800
* ion-kit starts the acquisition before stream creation This is a tentative fix only in ion-kit due to hardware issue
746801
* In aravis, the acquisition should be done afterward. Since this maps better with GenAPI, where buffers
@@ -749,7 +804,7 @@ class U3V {
749804
*/
750805
if (specific_device_to_flip_order){
751806
log::info("Execute AcquisitionStart before create stream on this device.");
752-
err_ = command_acquisition_mode_contd_and_start();
807+
command_acquisition_mode_contd_and_start();
753808
}
754809
//start streaming after AcquisitionStart
755810
for (auto i=0; i<devices_.size(); ++i) {
@@ -763,9 +818,8 @@ class U3V {
763818
}
764819

765820
if (! specific_device_to_flip_order){
766-
err_ = command_acquisition_mode_contd_and_start();
821+
command_acquisition_mode_contd_and_start();
767822
}
768-
return err_;
769823
}
770824

771825
void allocate_buffers(){
@@ -989,7 +1043,7 @@ class U3VFakeCam : public U3V{
9891043
private:
9901044
U3VFakeCam(int32_t num_sensor, int32_t width, int32_t height , float_t fps, const std::string & pixel_format, char* dev_id = nullptr)
9911045
: U3V(num_sensor, false, false, true, width, height , fps, pixel_format, nullptr){
992-
err_ = open_fake_devices(width, height, fps, pixel_format);
1046+
open_fake_devices(width, height, fps, pixel_format);
9931047

9941048
// Start streaming and start acquisition
9951049
for (auto i=0; i<devices_.size(); ++i) {
@@ -1154,15 +1208,15 @@ class U3VRealCam: public U3V{
11541208
sim_mode_ = true;
11551209
}
11561210
if (sim_mode_){
1157-
err_ = open_fake_devices(width, height, fps, pixel_format);
1211+
open_fake_devices(width, height, fps, pixel_format);
11581212

11591213
// Start streaming and start acquisition
1160-
err_ = create_stream_and_start_acquisition(order_filp_);
1214+
create_stream_and_start_acquisition(order_filp_);
11611215
}else{
11621216
// Real Camera
11631217
validate_user_input(num_device, dev_id);
1164-
err_ = open_real_devices(num_device, num_sensor_, dev_id);
1165-
err_ = create_stream_and_start_acquisition(order_filp_);
1218+
open_real_devices(num_device, num_sensor_, dev_id);
1219+
create_stream_and_start_acquisition(order_filp_);
11661220
allocate_buffers();
11671221
}
11681222
};
@@ -1314,15 +1368,15 @@ class U3VGenDC: public U3V{
13141368
sim_mode_ = true;
13151369
}
13161370
if (sim_mode_){
1317-
err_ = open_fake_devices(width, height, fps, pixel_format);
1371+
open_fake_devices(width, height, fps, pixel_format);
13181372

13191373
// Start streaming and start acquisition
1320-
err_ = create_stream_and_start_acquisition(order_filp_);
1374+
create_stream_and_start_acquisition(order_filp_);
13211375
}else{
13221376
// Real Camera
13231377
validate_user_input(num_device, dev_id);
1324-
err_ = open_real_devices(num_device, num_sensor_, dev_id);
1325-
err_ = create_stream_and_start_acquisition(order_filp_);
1378+
open_real_devices(num_device, num_sensor_, dev_id);
1379+
create_stream_and_start_acquisition(order_filp_);
13261380
allocate_buffers();
13271381
}
13281382
};

0 commit comments

Comments
 (0)