|
From: John L. <lib...@ia...> - 2006-10-31 23:11:31
|
Your device may need to be initialized or may require additional work to
get it going... Have you tested the device? If you have it working
somewhere you might try using a USB sniffer to figure out what the
device is doing - what packets are being sent to it and what packets it
is receiving. You might look at a keyboard driver to figure out the
protocol...
That being said, if it acts like a keyboard, then why are you trying to
fiddle with it on the USB level? Couldn't you just grab your input from
STDIN? Or maybe there is a way to redirect the input from the scanner
to another stream? Seems much simpler than delving into libusb.
Ian
Brice Rebsamen wrote:
> Hello,
>
> I have a USB barcode scanner that acts like a keyboard: whenever a
> barcode is read it sends the code where the keyboard would normally
> write. I am writing some code in C to read from the scanner. This is
> my first application using libusb, and it is the first time I am
> working with a USB device.
> I found out how to open the usb device, detach the kernel driver and
> claim the interface. I got this information by reading the code of the
> phidget library that makes use of libusb. To read from the phidgets
> they call usb_interrupt_read. So I am doing the same but I get
> nothing, although I am managing to read 8 bytes, always the same: 0 0
> 30 0 0 0 0 0
> What's wrong? I pasted my code below (I removed error checking code).
>
> One more question (not so important):
> When detaching the kernel driver, it returns an error if it had been
> previously detached. How to check that and make the distinction with
> other kind of errors?
> Or:
> How to reattach the driver at the end?
>
>
>
>
> int main(){
> usb_dev_handle *udev;
> struct usb_bus *bus;
> struct usb_device *dev;
> char barcode[8];
>
> // search for the scanner, open the device and claim interface
> usb_init();
> usb_find_busses();
> usb_find_devices();
> for( bus=usb_get_busses(); bus; bus = bus->next )
> for( dev = bus->devices; dev; dev = dev->next )
> if( dev->descriptor.idVendor==0x5e0 && dev->descriptor.idProduct==0x200 )
> udev = usb_open(dev);
> usb_detach_kernel_driver_np(udev, 0);
> usb_claim_interface(udev, 0);
>
> //prompt scanner until we get 8 bytes.
> while( usb_interrupt_read(udev,1,barcode,8,1000)!=8 );
>
> int i;
> printf("barcode: ");
> for( i=0; i<8; i++ ) printf("%u ",barcode[i]);
> printf("\n");
>
> usb_release_interface(udev, 0);
> usb_close(udev);
> return 1;
> }
>
> -------------------------------------------------------------------------
> Using Tomcat but need to do more? Need to support web services, security?
> Get stuff done quickly with pre-integrated technology to make your job easier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
> _______________________________________________
> Libusb-devel mailing list
> Lib...@li...
> https://lists.sourceforge.net/lists/listinfo/libusb-devel
>
>
>
>
|