Linux中的USB编程 [英] usb programming in linux

查看:179
本文介绍了Linux中的USB编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

感谢您的回复,

我使用libusb库编写了代码.成功打开设备后,我尝试声明该接口.但是在声明该设备时它给出了错误.当我编写分离内核函数时,它只能声明该接口.

Thanks for the reply,

I wrote the code using libusb library. After opening the device successfully I tried to claim the interface. But its giving error while claiming that device. When I write the detach kernel function only it can able to claim the interface.

#ifdef LINUX
        libusb_detach_kernel_driver(devh, 0);
#endif

        r = libusb_set_configuration(devh, 1);
        if (r < 0) {
                fprintf(stderr, "libusb_set_configuration error %d\n", r);
                goto out;
        }
        printf("Successfully set usb configuration 1\n");
        r = libusb_claim_interface(devh, 0);
        if (r < 0) {
                fprintf(stderr, "libusb_claim_interface error %d\n", r);
                goto out;
        }
        printf("Successfully claimed interface\n");

        r = libusb_bulk_transfer(devh, ENDPOINT_INT_IN, buf,sizeof(buf), &transferred, TIMEOUT);
            
        if (r < 0) {
                fprintf(stderr, "Interrupt read error %d\n", r);
                return r;
        }

        for(i = 0;i < 5; i++) {
                if(i%8 == 0)
                        printf("\n");
                printf("%02x ",buf[i]);
          
        }



这是从鼠标获取数据的正确方法吗?

请为我提供建议,并提供一些建议,以便我可以参考并解决此问题.
我正在等待您的宝贵信息.

谢谢您.



Is this correct way to get the data from the mouse?

Please suggest me how to go through, and some suggestions regarding this so that I can refer the same and get solved from this problem.
I''m awaiting for your valuable information.

Thank you

推荐答案

是的,您需要分离当前连接的驱动程序,否则内核将不允许您使用该接口.到目前为止,代码看起来还不错.
Yes you need to detach the currently attached driver otherwise the kernel won''t let you use the interface. Also the code till now looks fine.



我收到中断读取错误-7.所以请建议我该错误的原因是什么

I am getting interrupt read error -7.so please suggest me what might be the reason for this error


这篇关于Linux中的USB编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆