libusbを使用しようとしていますが、次のエラーメッセージが表示されます。
usbfs:プロセス24665(myprogram)が使用前にインターフェース0を要求しませんでした
理由はよくわかりません。私が知る限り、図書館にある説明に従ってやっているからです。これが私のコードです:
#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;
}
ご覧のとおり、転送前にインターフェースを要求します。(私は他のUSBデバイスでも同じコードを試しましたが、それが何か関係がある場合に備えてです。)
私はlibusb-1.0.9を使用しています。これは私が見つけた最新のリリースです。私はUbuntu12.04_64(Precise Pangolin)でこれを実行してい ます。