我有一台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);
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);
}
输出
The return value of r is -7::::0
The return value of r is -7::::0
答案 0 :(得分:0)
尝试从超级用户执行以下命令,然后重新连接设备。
echo 0 > /sys/bus/usb/drivers_autoprobe
它在一些设备上帮助了我。