Click here to Skip to main content
15,907,687 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

C++
#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
Posted
Updated 15-Dec-10 20:18pm
v2
Comments
JF2015 16-Dec-10 2:18am    
Edited to add code formatting.
Sandeep Mewara 16-Dec-10 3:47am    
No need to form a new question if you are trying to interact based on some answer.

in cse it's a followup question then do provide the links that you are referring to.
For now: http://www.codeproject.com/Questions/136788/usb-programming-in-linux.aspx is the link that you asked your original question.

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.
 
Share this answer
 
hi,
I am getting interrupt read error -7.so please suggest me what might be the reason for this error
 
Share this answer
 
Comments
Toniyo Jackson 17-Dec-10 1:02am    
Don't write your comments here. You have add comment button below all answers. so write your comments below the appropriate answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900