0

I'm trying to contact an usb barcode scanner as a serial port, using his virtual COM port name and the Serial Port class.

The reason I'm trying to do it this way is to avoid using the scanner as a keyboard wedge since I need the possibility to scan even when the form is hidden.

Problem is that when I connect the barcode scanner to the usb port, and I run the "GetPortNames" function, I get an empty list. Any suggestions why? Thanks

Skipper Geffen
  • 75
  • 2
  • 11
  • What operating system are you using? Have you checked the OS to see if the scanner is registered at a com port after you've plugged it in? – ChrisBD Dec 12 '11 at 08:45

2 Answers2

1

Typically many USB barcode scanners will just appear as virtual keyboard devices - not virtual COM ports. That would explain why it doesn't appear.

Does your scanner support some kind of serial emulation mode? You may need to configure it or install different drivers to enable this. Does it appear as a serial port in Device Manager? (Look under the Ports tree)

As an aside:

Take a look at this question if you find that the 'keyboard mode' is the only one supported: Reading a barcode using a USB barcode scanner along with ignoring keyboard data input while scanner product id and vendor id are not known

This question refers to this article with a large amount of good information relating to keyboard hooks and filtering out the scanned barcodes: http://nicholas.piasecki.name/blog/2009/02/distinguishing-barcode-scanners-from-the-keyboard-in-winforms/

Community
  • 1
  • 1
Lummo
  • 1,159
  • 9
  • 14
  • I didn't find any references to a serial emulation mode in the guide, so I take it doesn't exist, but I did find interesting the article relating to keyboard, but I find it rather convoluted. Any chacne you might send me the raw code I need to get it going? Thanks ahead – Skipper Geffen Dec 12 '11 at 20:24
  • The blog page has a link to download a sample application (with source code) at the end of the post. I'd take a look at that and go from there - that should be enough to get started. – Lummo Dec 13 '11 at 00:35
0

I cannot guarantee that it will work with your specific device, but I've seen code that solved a similar problem once. The solution was looking for the port name in the registry.

The code for it can be found in the open source project ez430chronosnet; a .NET library that can access TI's EZ430 Chronos watch via its USB dongle.

You'll want to look at the PortName.cs file that looks for the name in the registry (it will at least point you to the right keys) and the Chronos.cs file that does the actual port opening with SerialPort.

madd0
  • 9,053
  • 3
  • 35
  • 62