Mawg
Mawg

Reputation: 40185

How to read from a cheap generic USB device?

I bough a cheap RFID reader from eBay, just to play about with. There is no API, it just writes to stdin - that it to say, if you have Notepad open and tap an RFID tag to the reader its Id number appears in the Notepad window.

I am looking around for a reasonably priced reader/writer with an actual API (any recommendations?).

Until then I need to knock together a quick demo using what I have, just to prove the concept.

How can I best intercept the input from the USB connection? (and is there a free VCL control to do this?)

I guess if I just have a modal form with a control which is active then I can hook its on change event. But modal forms seem a bit rude. Maybe I can hook keyboard input, as it seems to be injecting like types chars?

Any idea? Please tell me if I cam not explaining this clearly enough.

Thanks in advance for your help.


In the end, I just hooked the keyboard, rather than trying to intercept the USB. It works if I check that my application is active and pass on the keystrokes otherwise. My app doesn't have any keyboard input, just mouse clicks (and what I read from RFID is digits only, so I can still handle things like Alt+F4. Maybe not the perfect solution for everyone, but all that I could get to work)

Upvotes: 2

Views: 2361

Answers (2)

Ritsaert Hornstra
Ritsaert Hornstra

Reputation: 5111

A Delphi library for doing HID devices:

http://www.soft-gems.net/index.php?option=com_content&task=view&id=14&Itemid=33

Upvotes: 3

Wil Cooley
Wil Cooley

Reputation: 940

Based on your description, it sounds like the RFID reader is providing a USB HID keyboard interface.

I don't know if there is anything similar in delphi, but in libusb there is a libusb_claim_interface, which requests that the OS hand control over to your program.

Upvotes: 5

Related Questions