gpt4 book ai didi

printing - 写入时 libusb_bulk_transfer 超时

转载 作者:行者123 更新时间:2023-12-02 02:12:41 28 4
gpt4 key购买 nike

我有一个 USB 打印机设备。我想从 Linux 发送文件数据到 USB 打印机。我的代码使用 libUsb。我在发送时总是超时(libusb 返回值 -7)。但我可以在 Windows 中为同一台打印机发送数据。什么地方出了错 ? ehci 或 uhci 似乎没有向打印机发送数据。请帮忙。

OS : Ubuntu 12.04 (32 Bit)

下面是我的代码片段。

    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

最佳答案

尝试从 super 用户执行以下命令,然后重新连接设备。

echo 0 > /sys/bus/usb/drivers_autoprobe

它帮助我使用了一些设备。

关于printing - 写入时 libusb_bulk_transfer 超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21018047/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com