Printing 写入时libusb\u批量\u传输超时
我有一个USB打印机设备。我想从Linux向USB打印机发送文件数据。我正在使用libUsb作为我的代码。发送时,我总是收到超时(libusb返回值-7)。但我可以在Windows中为同一台打印机发送数据。出了什么问题?看来ehci或uhci没有向打印机发送数据。请帮忙 操作系统:Ubuntu 12.04(32位) 下面是我的代码片段Printing 写入时libusb\u批量\u传输超时,printing,timeout,libusb-1.0,Printing,Timeout,Libusb 1.0,我有一个USB打印机设备。我想从Linux向USB打印机发送文件数据。我正在使用libUsb作为我的代码。发送时,我总是收到超时(libusb返回值-7)。但我可以在Windows中为同一台打印机发送数据。出了什么问题?看来ehci或uhci没有向打印机发送数据。请帮忙 操作系统:Ubuntu 12.04(32位) 下面是我的代码片段 dev_handle = libusb_open_device_with_vid_pid(ctx, PRINTER_VID, PRINTER_PID);
dev_handle = libusb_open_device_with_vid_pid(ctx, PRINTER_VID, PRINTER_PID);
if (dev_handle == NULL)
{
cout << "Cannot open device" << endl;
libusb_free_device_list(devs, 1); //free the list, unref the devices in it
return;
}
else
{
cout << "Device Opened" << endl;
}
if (libusb_kernel_driver_active(dev_handle, 0) == 1) //find out if kernel driver is attached
{
cout << "Kernel Driver Active" << endl;
if (libusb_detach_kernel_driver(dev_handle, 0) == 0) //detach it
cout << "Kernel Driver Detached!" << endl;
}
r = libusb_claim_interface(dev_handle, 0);
if (r < 0)
{
cout << "Cannot Claim Interface" << endl;
return 1;
}
cout << "Claimed Interface" << endl;
cout << "Writing Data..." << endl;
memset(data_buffer,0,64);
while(fgets((char *)data_buffer,64,fp))
{
errno = 0;
r = libusb_bulk_transfer(dev_handle,0x081 | LIBUSB_ENDPOINT_OUT, data_buffer, 64,&actual, 10);
cout<<"The return value of r is "<<r<< "::::" << actual << endl ;
memset(data_buffer,0,64);
}
尝试从超级用户执行以下命令,然后重新连接设备
echo 0 > /sys/bus/usb/drivers_autoprobe
它在一些设备上帮助了我。您是否尝试过增加超时值?您是否使用USB分析仪查看了总线以确定工作和故障情况的差异?是的,我增加了超时时间。没用。超时后出现相同错误
echo 0 > /sys/bus/usb/drivers_autoprobe