Home > Archive > Visual Basic > February 2006 > Capture data from a USB Port
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Capture data from a USB Port
|
|
| stephen@ebacuk.demon.co.uk 2006-02-25, 6:55 pm |
| Can anyone point me in the direction of some sample VB code which
provides some examples on how to capture data from a USB port and store
in a Acces database
Thank you
| |
| Dick Grier 2006-02-25, 6:55 pm |
| Hi,
You normally use whatever API is required for the specific hardware device
that is attached to the USB port. There is no general-purpose driver for
this. So, if you are connecting to a serial device, you use the Windows
serial APIs. If a sound device, you use the MCI APIs. If a disk drive, you
use the various file APIs. The actual driver that is installed when Windows
detects the USB device translates these Windows APIs to the device specific
commands required for the actual hardware.
However, if you have custom built USB hardware, you need lower level access
to the device. You must know A LOT about the hardware before this sort of
thing is useful. I suggest that you get a copy of Jan Axelson's book, USB
Complete, 3rd Edition. You can get information on it from the Books link on
my homepage.
If you just want to use a USB serial port adapter to connect to an RS-232
device, then you may use MSComm or any of the other serial communications
methods that are described in detail in my book.
Some USB devices act as HID keyboard devices. With these devices data is
sent to a text window (such as a TextBox) just as though it had been typed
at the keyboard. You may be able to set the input focus to a textbox and
interpret the data in the KeyPress event. A more satisfactory mechanism
that some devices, though only a small subset, support is/are the HID
APIs -- these may work without focus being set to a textbox. Only the
device manufacturer's information will reveal these operations; there is no
universal standard.
Dick
--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition,
ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004.
See www.hardandsoftware.net for details and contact information.
| |
| stephen@ebacuk.demon.co.uk 2006-02-27, 6:56 pm |
| Hi Dick
Thank you for your reply....The device is actuall a Barcode Scanner,
and you are right, Windows has detected and installed the relavant USB
drivers, I belive it's HID keybord driver, as if i have Notepad open,
and blip the scanner, then the scanned info apears in Notepad.
The plan is to have mulitpule Barcode Scanners connected via a USB HUB,
each scanning a different operation....The scans from these devices
need to end up being apended to a Access Database Table.....
Are you able to suggest any sample VB code to start this project ?
Stephen
| |
| Dick Grier 2006-02-27, 6:56 pm |
| Hi,
You simply (IMO) cannot get there from here.
USB barcode readers are "one-man, one-machine, one-application" devices.
For your application you need a network designed for the purpose. There are
both serial (these normally use RS-485 serial connections for the network)
and wireless readers that connect using TCP/IP over 802.11b. There may be
some that connect using a standard ethernet, too. The protocol that the
manufacturer implements will include device identification information, such
that your application can determine which scan came from which reader.
While it wouldn't be impossible for a USB barcode reader to be designed to
be used with a hub and work the way that you want, I have NEVER heard of
such a device. Imagine connecting multiple keyboards to a PC via a hub and
trying to sort out what keystrokes came from each keyboard. HID simply
isn't designed for this purpose.
Dick
--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition,
ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004.
See www.hardandsoftware.net for details and contact information.
|
|
|
|
|