LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   help me --- interrupt_read() in libusb (http://www.linuxquestions.org/questions/programming-9/help-me-interrupt_read-in-libusb-367476/)

shiva_teknic 09-27-2005 09:17 AM

help me --- interrupt_read() in libusb
 
hi all,
i need to develop some applications using libusb library.. just now i started with this library... first i want to read the USB mouse interrupts... i have written program... but it doesnt receive the interrupts... .here i include my program...i dono wher i made mistake... so kindly help me to interface the USB mouse(for receiving interrupts)...

my program is working fine upto claiming the interfaces,,, after that the interrupt_read() function returns only negative value...

here i include my program :


#include <stdio.h>
#include <usb.h>
#include <stdlib.h>
#include <unistd.h>


int vid = 0x04fc;
int prod = 0x0013;

struct usb_bus *bus;
struct usb_device *dev;
int stat, scancnt;
unsigned char buf[1024];
usb_dev_handle *udev;
int j,c,i,a,verbose = 0;

int main(int argc, char *argv[])
{
char *cbuf;
int i;
int show_listing = 0;
int found_device = 0;
struct usb_device *fnd_dev;

usb_init();
usb_find_busses();
usb_find_devices();

for (bus = usb_busses; bus; bus = bus->next) {
for (dev = bus->devices; dev; dev = dev->next) {
int ret;
char string[256];

if ((dev->descriptor.idVendor == vid) &&
(dev->descriptor.idProduct == prod)) {
found_device = 1;
fnd_dev = dev;
break;
}
}
if (found_device)
break;
}


printf("value%d",found_device);


if (found_device) {
udev = usb_open(dev);
printf("udev=%x\n", udev);

if (udev) {
stat = usb_set_configuration (udev,
dev->config[0].bConfigurationValue);
printf ("stat:%d from usb_set_config to %x\n",stat,dev->config[0].bConfigurationValue);


stat = usb_claim_interface(udev, 0);
printf ("stat:%d from claim\n",stat);

memset(buf, 0, sizeof(buf));

scan:
stat = usb_interrupt_read(udev, 0x81, buf, 8,1000);


if (stat<0)
goto scan;

else
printf ("\nstat:%5d, ", stat);

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

printf ("closing port\n");
usb_close (udev);
udev = 0;
}
}

exit (0);
}


thanks in advance...

regards
siva


All times are GMT -5. The time now is 03:26 AM.