Question

I have a bar-code scanner with USB interface, so it appears as an HID.

There are reasons why I must breakpoint on the first character.

That brings my Delphi IDE to the front, it stops on the breakpoint and the rest of the bar-code is injected into my code as if it had been typed front the keyboard (which, in a way it has, as the USB scanner is just another HID).

Is there any way to avoid this? Or to add an initial check as to the source of the input?

It annoys me so much that I am now looking for a scanner with an RS232 interface.

Was it helpful?

Solution

The problem is that HID "devices" send information back to the computer in packets known as "reports".
In the case of a mag-swipe, or bar-code scanner, the "report" contains the entire number.

Which is to say, you don't receive reports character-by-character, but the entire string at once. (In the case of a mag-swipe, you will receive all two, or three, tracks in the same report).

So your code doesn't break "on the first character", it breaks "on the entire report". The fact that the remaining characters are there you can think of as a bonus (if you don't want to look at them you don't have to). But you won't be receiving any more "reports" for subsequent characters.

i cannot imagine any reason why you wouldn't want to know the bar-code at once. But most mag-swipe and bar-code scanners can be configured to emulate a keyboard, rather than a generic HID device. In that case you will receive multiple WM_KEYDOWN messages.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top