Board index » delphi » USB Interface

USB Interface

Hi,

Does somebody know a good tutorial/demo about interfacing with USB? I
already tried some Delphi USB components and example code but for some
reason, I can't find all devices. I tried a printer, memory stick and a
mouse.Only the mouse was noticed. Anyway, in my case I need to receive
strings from a barcode scanner so what could be a good method for
interfacing?

Greetings,
Rick

 

Re:USB Interface


Quote
Rick wrote:
> Hi,

> Does somebody know a good tutorial/demo about interfacing with USB? I
> already tried some Delphi USB components and example code but for some
> reason, I can't find all devices. I tried a printer, memory stick and a
> mouse.Only the mouse was noticed. Anyway, in my case I need to receive
> strings from a barcode scanner so what could be a good method for
> interfacing?

You could ask me :-)
Probably you used my HID component.

The problem with general USB access is that there is none.
USB devices are divided into classes and severla of these classes have
no USB specific API at all. Printers and USB sticks are among them.
Both are only accessed through non-USB APIs (printer API and filesystem
API).

The mouse is a HID device, but it is completely inaccessible because
Windows opens all mice with an exclusive CreateFile call to handle it
itself. The same is true for keyboards.

The barcode scanner probably shows up as keyboard also. There is a
special HID subclass for barcode scanner, but it is largely unused.
This means that you have to handle the keys the barcode scanner
generates as part of the normal WM_KEYDOWN/WM_KEYUP message flow.
The scanners usually allow to set a prefix and postfix char.

Re:USB Interface


Quote
> You could ask me :-)
> Probably you used my HID component.

:)

Quote
> This means that you have to handle the keys the barcode scanner generates
> as part of the normal WM_KEYDOWN/WM_KEYUP message flow.
> The scanners usually allow to set a prefix and postfix char.

Yep, for now I'm using a 'wedge' connection (keyboard and scanner are on the
same cable). Luckily, it sends a pre/postfix to recognize the scanner. If
the scanner acts like a keyboard via USB just like wedge, does that mean I
don't have to write any 'connect' or 'receivedata' methods like RS232
requires? If its just plug and play, that would be great.

But in the future, I might also need USB for scales. In that case, I need to
write data to the balance as well. What subclass would that require?

Greetings,
Rick

Re:USB Interface


I forgot:
Read the HID spec from
http://www.usb.org/developers/hidpage/
especially about Point of Sale devices which are mainly scales, barcode
scanners and cash drawers
http://www.usb.org/developers/devclass_docs/pos1_02.pdf

Re:USB Interface


Quote
Rick wrote:
> Yep, for now I'm using a 'wedge' connection (keyboard and scanner are on the
> same cable). Luckily, it sends a pre/postfix to recognize the scanner. If
> the scanner acts like a keyboard via USB just like wedge, does that mean I
> don't have to write any 'connect' or 'receivedata' methods like RS232
> requires? If its just plug and play, that would be great.

Those USB barcode scanners posing as keyboards are indistinguishable
from a normal keyboard.

Quote
> But in the future, I might also need USB for scales. In that case, I need to
> write data to the balance as well. What subclass would that require?

USB scales usually use the scales subclass of HID so my HID component
should handle them well.
HID devices have an elaborate descriptor which allows to precisely
identify the data to extract. The only problem is that scales
manufacturers do not make god descriptors. Expect the data to not match
the descriptor. At least you should always be able to read the data.
Only the interpretation may have to be done by hand.

Re:USB Interface


Thanks for all the help!!

Rick

Re:USB Interface


Quote
Rick wrote:
> Hi,

> Does somebody know a good tutorial/demo about interfacing with USB? I
> already tried some Delphi USB components and example code but for some
> reason, I can't find all devices. I tried a printer, memory stick and a
> mouse.Only the mouse was noticed. Anyway, in my case I need to receive
> strings from a barcode scanner so what could be a good method for
> interfacing?

> Greetings,
> Rick

are you saying that the barcode scanner and scale people do not provide
any interface software.  Dll's etc to talk to their devices. ? ? ?

Jim P.

Re:USB Interface


Quote
Jim P wrote:
> are you saying that the barcode scanner and scale people do not provide
> any interface software.  Dll's etc to talk to their devices. ? ? ?

For barcode scanners posing as keyboards a DLL makes no sense because no
access to the device is possible.
For scales it varies. It depends on the quality of the device. A well
behaved (ie correct HID descriptor) device is fully accesible through
Win32 API.

Re:USB Interface


Quote
Robert Marquardt wrote:
> Jim P wrote:

>> are you saying that the barcode scanner and scale people do not
>> provide any interface software.  Dll's etc to talk to their devices. ?
>> ? ?

> For barcode scanners posing as keyboards a DLL makes no sense because no
> access to the device is possible.
> For scales it varies. It depends on the quality of the device. A well
> behaved (ie correct HID descriptor) device is fully accesible through
> Win32 API.

Still are you telling me that for a USB scale they do not provide any
software to display the readings or for interfacing to - such as a DLL.

No demo software that shows the USB interface is working.  Is that what
you are saying.

Jim P.

Re:USB Interface


Quote
Jim P <Ji...@mad.scientist.com> wrote in message
> No demo software that shows the USB interface is working.  Is that what
> you are saying.

No, i just say that you should not need a DLL for that.
It is not uncommon though to write a DLL with a simplified API.
Not many programmers can handle plug & unplug or several devices of the same kind.

Other Threads