From: Peter S. <stu...@cd...> - 2006-10-31 23:47:19
|
On Tue, Oct 31, 2006 at 08:08:04PM +0800, 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. USB is great in many ways, very flexible, but it may be unintuitive to newcomers. The keyboard-equivalent bytes sent to applications are not sent in the clear over the bus. They're sent in blocks of data called reports, which are specific to the USB HID device class. Long story short there's lots of code to support this device already and I'm not sure libusb is the best way to go. Please read recent discussion on the list about why trying to read files from a USB memory key with libusb is not the best way to go. Granted this is less complicated, but the principle is the same. What requirements do you have on portability? If you're writing a Linux-only application, perhaps using the other end of the existing HID/Input software in the kernel is better? Or even change your application so that it doesn't matter which human interface device is used to enter the barcode number. This can be a feature, think torn barcode with numbers below intact. It will depend on your usage scenario and requirements. USB is a lot like an expert consultant - if you know exactly what you want it can all be incredibly rewarding for everyone involved. If you're not sure of what you want or fail to express it sufficiently clearly, all you get is more problems. If you need portability, depending on *_np() is a no-no. (np is short for non-portable) As for re-attaching, I'm not sure that's possible. Another option may be the hiddev kernel interface, which also lets the kernel hid driver remain attached. There's a libhid too, but unfortunately it doesn't use hiddev yet. I just need some free time.. ;) //Peter |