开发者

Trying to understand USB, using C

开发者 https://www.devze.com 2023-04-08 20:54 出处:网络
I have searched for these answers but had no luck :( I have been working with a RFID device from China, so I know next to nothing about it. I am trying to write a program (actualy i\'m trying to use s

I have searched for these answers but had no luck :( I have been working with a RFID device from China, so I know next to nothing about it. I am trying to write a program (actualy i'm trying to use someone else's library) to interact with it. When a tag goes over the RFID device the device types out the numbers like a HID keyboard and then presses the enter key and waits for the next one. (I am using windows 7 btw) My questions are these:

  1. Apart from knowing the VID (Vendor ID) and PID (Product ID) Is there anything else I would need to know about the device to start reading from it.

  2. In a example I saw, before reading the device the example program wrote to the device first, sending 8 bytes in an array (bytes[8]) with each byte being somthing like [0] = 60, [1] = 0, [2] = 20 and so on. When the device stops being read it a开发者_开发百科lso sent a bunch of stop bytes. Could someone explain this a bit more to me and weather this is neccesary, and wether these start/stop bytes are device specific or it is a general start/stop thing with USB's?

  3. Does anybody know any good, simple source out there (or application) that is set up to do what I would like to do?

Answers to any of the questions are appreciated, thanks.


Before trying to partially reverse-engineer the basic USB protocol you could read the (open) USB-specification (see http://www.usb.org/) and familiarize yourself with the keywords (endpoint, URB, pipes) and principles control/bulk/isochronous/interrupt-transfers).

I liked a lot the linux-usb-implementation as it is simply implemented and easy to read: linux/include/usb.h.

To address USB devices from user-space you could use libusb (exists for Windows and Linux). This way you can access USB devices without writing a kernel-driver.


If your RFID reader is really a virtual USB HID keyboard than you might just register for RawInput and listen for data. In this case you really don't care about the hardware beneath and I think that somebody else already responded here how to do it.

If this approach doesn't work, it means that your RFID reader is not a realy USB HID keyboard device and you should ask your vendor for a driver, or for the structure of data sent over USB.

If you can't find neither a driver or some specs in this case you have to start to make reverse engineering over your USB device. One tool you could start with it is USBView.exe from Microsoft you can find it Windows Driver Kit - the source code, you just build it and have the application. After this you should try to get the USB descriptor structure and analyzed, you will find lots of valuable information there that can help your to understand how data is sent.

As you see a lots of Ifs...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号