- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正尝试在我的 USB 上执行写/读 libusb_bulk_transfer()大容量存储器。但是在第一次成功写入 libusb_bulk_transfer() 之后,我的程序只是挂起并且不执行 libusb_bulk_transfer() 读取。我发现我的 USB 设备分离了。为什么我无法执行读取?
以下是我的代码片段:
e = libusb_get_configuration(handle, &config2);
if (e!=0)
{
printf("\n***Error in libusb_get_configuration\n");
libusb_free_device_list(devs, 1);
libusb_close(handle);
return -1;
}
printf("\nConfigured value : %d", config2);
if (config2 != 1)
{
libusb_set_configuration(handle, 1);
if (e!=0)
{
printf("Error in libusb_set_configuration\n");
libusb_free_device_list(devs, 1);
libusb_close(handle);
return -1;
}
else
printf("\nDevice is in configured state!");
}
if (libusb_kernel_driver_active(handle, 0) == 1)
{
printf("\nKernel Driver Active");
if (libusb_detach_kernel_driver(handle, 0) == 0)
printf("\nKernel Driver Detached!");
else
{
printf("\nCouldn't detach kernel driver!\n");
libusb_free_device_list(devs, 1);
libusb_close(handle);
return -1;
}
}
e = libusb_claim_interface(handle, 0);
if (e < 0)
{
printf("\nCannot Claim Interface");
libusb_free_device_list(devs, 1);
libusb_close(handle);
return -1;
}
else
printf("\nClaimed Interface\n");
char *Report_to_write, *Report_to_read;
int transferred = 0;
int received = 0;
int nbytes = 8; // As protocol suggested it should be 8 bytes
Report_to_write = (char *)malloc(nbytes);
Report_to_read = (char *)malloc(nbytes);
Report_to_write[0] = 0x01; // cmd
Report_to_write[1] = Report_to_write[2] = Report_to_write[3] = 15; // HOUR
Report_to_write[4] = Report_to_write[5] = Report_to_write[6] = 30; // MIN
Report_to_write[7] = 255; // some checksum
memset(Report_to_read, '\0', 8);
e = libusb_bulk_transfer(handle, BULK_EP_OUT, Report_to_write, 8, &transferred, 0);
if (e == 0 && transferred == 8)
{
printf("\nWrite successful!");
printf("\nSent %d bytes with string: %s\n", transferred, Report_to_write);
}
else
printf("\nError in write! e = %d and transferred = %d\n", e, transferred);
e = libusb_bulk_transfer(handle, BULK_EP_IN, Report_to_read, 8, &received, 0); //64: Max Packet Length
if (e == 0)
{
printf("\nReceived: ");
printf("%c", Report_to_read[1]); //Will read a string
//sleep(1);
}
else
{
printf("\nError in read! e = %d and received = %d\n", e, received);
return -1;
}
e = libusb_release_interface(handle, 0);
libusb_free_device_list(devs, 1);
libusb_close(handle);
libusb_exit(NULL);
最佳答案
命名和字符串看起来与 Stack Overflow 问题中的代码非常相似 Read/write on a pen drive using libusb: libusb_bulk_transfer() (我写的)。
观察您的代码,我只能预测您没有使用正确的端点地址。
关于linux - libusb_bulk_transfer() 在 USB 大容量存储设备上首次成功写入后 libusb_bulk_transfer() 读取挂起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19727933/
我正尝试在我的 USB 上执行写/读 libusb_bulk_transfer()大容量存储器。但是在第一次成功写入 libusb_bulk_transfer() 之后,我的程序只是挂起并且不执行 l
libusb_open(device, &deviceHandle); returns 0 但是 libusb_bulk_transfer(deviceHandle, 0x81, data1, 512
我有一个 USB 打印机设备。我想从 Linux 发送文件数据到 USB 打印机。我的代码使用 libUsb。我在发送时总是超时(libusb 返回值 -7)。但我可以在 Windows 中为同一台打
我正在尝试对 pen drive 执行读写操作. 详细信息:供应商 ID:8564 和产品 ID:1000。它是 Transcend JetFlash 大容量存储设备。 我很想知道是否可以在笔式驱动器
我正在创建一个程序,使用 libusb 从 MIDI Controller 读取输入。如何正确调用libusb_bulk_transfer?目前我每次都会收到错误“LIBUSB_ERROR_NOT_F
我是一名优秀的程序员,十分优秀!