-
-
Notifications
You must be signed in to change notification settings - Fork 340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Option to force device connection #885
Comments
@patrickwasp have you tried |
It seems the suggested functions are for the GigEVision cameras denoted by |
I've been playing around with this a little using libusb. The code below finds no kernel driver active on my camera's interface and is able to successfully claim said interface. I then call static libusb_device* getDevice(libusb_context* ctx, int guid, libusb_device_descriptor* desc) {
libusb_device** device_list;
libusb_device* device;
ssize_t device_count = libusb_get_device_list(ctx, &device_list);
if (device_count < 0) {
std::cerr << "Failed to get device list" << std::endl;
return nullptr;
}
for (ssize_t i = 0; i < device_count; ++i) {
device = device_list[i];
if (libusb_get_device_descriptor(device, desc) != 0) {
std::cerr << "Failed to get device descriptor" << std::endl;
continue;
}
if (desc->idVendor == guid) {
libusb_free_device_list(device_list, 1);
return device;
}
}
libusb_free_device_list(device_list, 1);
return nullptr;
}
static void resetDevice(int guid) {
// Initialize libusb
libusb_context* ctx = nullptr;
if (libusb_init(&ctx) != 0) {
std::cerr << "Failed to initialize libusb" << std::endl;
return;
}
// Get matching device
libusb_device_descriptor desc;
libusb_device* dev = getDevice(ctx, guid, &desc);
if (dev == nullptr) {
std::cerr << "Failed to find device" << std::endl;
libusb_exit(ctx);
return;
}
libusb_device_handle* dev_handle = nullptr;
if (libusb_open(dev, &dev_handle) != 0) {
std::cerr << "Failed to open USB device" << std::endl;
libusb_exit(ctx);
return;
}
for (int i = 0; i < desc.bNumConfigurations; ++i) {
if(libusb_kernel_driver_active(dev_handle, i) == 1) {
std::cout << "Kernel drive active" << std::endl;
if(libusb_detach_kernel_driver(dev_handle, i) == 0) {
std::cout << "Kernel drive Detached" << std::endl;
}
else {
std::cout << "Couldn't detach kernel driver" << std::endl;
}
}
if (libusb_claim_interface(dev_handle, i) != 0) {
std::cerr << "Failed to claim interface " << i << std::endl;
continue;
}
libusb_release_interface(dev_handle, i);
std::cout << "Interface " << i << " claimed successfully" << std::endl;
}
libusb_reset_device(dev_handle);
libusb_close(dev_handle);
libusb_exit(ctx);
return;
}
std::string deviceGuidString = std::string(arv_get_device_physical_id(0)).substr(0, 4);
int deviceGuid = std::stoi(deviceGuidString, 0, 16);
resetDevice(deviceGuid);
|
After enabling debug...
I have narrowed down the problem to when |
This is interesting, I also bumped into issue with Basler (USB) camera sometimes. Not sure if this is because of usb port or other matters. p/s: still a beginner, but I will try to setup for debugging as starting point |
When starting an aravis program I sometimes get:
Failed to bootstrap USB device '(null)-(null)-(null)-2978000AF0CC'
. I'm not sure exactly why this happens but unplugging the device and plugging it back it in fixes the issue, although it has to go through a(CID: DD4CCACF1905) device communication failure
error the first time it retries after being re-plugged in.If possible a
force
option when callingarv_camera_new()
to claim the device regardless of whatever else is using it would be helpful. If this is something deeper that cannot be done at the aravis level, are there any suggestions on a fix that doesn't involve physically unplugging?lsusb -t
has the following output for the camera, without a Driver, when it doesn't workWhen it works
lsusb -t
showsThe text was updated successfully, but these errors were encountered: