Tôi đang cố gắng sử dụng libusb, nhưng tôi nhận được thông báo lỗi sau:Thông báo lỗi 'Giao diện không tuyên bố' từ libusb
usbfs: quá trình 24.665 (myprogram) không tuyên bố giao diện 0 trước khi sử dụng
Tôi thực sự không hiểu tại sao, bởi vì theo như tôi có thể nói, tôi đang làm theo mô tả được tìm thấy trong thư viện. Đây là mã của tôi:
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <libusb.h>
int main(void)
{
int result;
struct libusb_device_descriptor desc;
libusb_device **list;
libusb_device *my_device = NULL;
result = libusb_init(NULL);
libusb_set_debug(NULL, 3);
ssize_t count = libusb_get_device_list(NULL, &list);
for (int i = 0; i < count; i++) {
libusb_device *device = list[i];
result = libusb_get_device_descriptor(device, &desc);
if((desc.idVendor == 0x03f0) && (desc.idProduct == 0x241d)) {
my_device = device;
break;
}
}
if(my_device != NULL) {
libusb_device_handle *handle;
result = libusb_open(my_device, &handle);
int kernelActive = libusb_kernel_driver_active(handle, 0);
if(kernelActive == 1) {
result = libusb_detach_kernel_driver(handle, 0);
}
result = libusb_claim_interface (handle, 0);
result = libusb_control_transfer(handle,0x21,34,0x0003,0,NULL,0,0);
result = libusb_release_interface (handle, 0);
if(kernelActive == 1) {
result = libusb_attach_kernel_driver(handle, 0);
}
libusb_close(handle);
}
libusb_free_device_list(list, 1);
libusb_exit(NULL);
return EXIT_SUCCESS;
}
Như bạn thấy, tôi yêu cầu giao diện trước khi chuyển. (Tôi cũng đã thử cùng một mã với các thiết bị USB khác, chỉ trong trường hợp có liên quan đến nó.)
Tôi đang sử dụng libusb-1.0.9, đây là bản phát hành mới nhất mà tôi có thể tìm thấy. Tôi đang chạy điều này trên Ubuntu12.04_64 (Chính xác tê tê).
Có thể là sự cố về quyền không? Bạn đã thử chạy chương trình của bạn với 'sudo' chưa? – gfour
Vâng, tôi đã thử sudo. Khi nó quay ra, tất cả mọi thứ dường như làm việc ok, vì vậy tôi giả định rằng tin nhắn chỉ là thông tin trình bày xấu, chứ không phải là một lỗi hoặc một cảnh báo. Tôi vẫn rất muốn hiểu tại sao tôi nhận được tin nhắn, mặc dù. – Robert
[Xem giải pháp này] (http://stackoverflow.com/questions/22011760/libusb-claim-interface-access-denied-java/39269489#39269489). Nó có thể giúp. –