1

I'm creating an application in vb.net 2013, where I need to implement a way to read from USB bar-code readers. I've read that most bar-code readers should be treated like simple keyboards. But this is the problem.

On my Main form, I have several TextBoxes. One of them is Barcode TextBox, where a user can write the bar-code manually or can read from the bar-code reader.

On other TextBoxes, only manual input from the keyboard should be permitted and not from the bar-code reader.

So is there a way to make this possible?

Blackwood
  • 4,504
  • 16
  • 32
  • 41
  • Check this: [How to distinguish between multiple input devices in C#](http://stackoverflow.com/questions/587840/how-to-distinguish-between-multiple-input-devices-in-c-sharp) – Fabio Jan 25 '16 at 03:44
  • I can't remember 100%, but I don't think a barcode reader causes the KeyDown and KeyUp events, only a TextChanged event, so you might be able to do something with that. Try testing that. – LarsTech Jan 25 '16 at 16:43
  • Check to see if your barcode reader surrounds its input with any special characters. For example, the text produced by the barcode reader might be *123456789# where the * and # are added by the barcode reader to the scanned data. This is normally configurable in the readers configuration somehow. You could use this to determine if the data came from the reader or not. – Chris Dunaway Jan 25 '16 at 20:45
  • Sorry but i want to make my application general so to support all kinds of USB barcode readers. Actually , the barcode reader that i'm using now for tests doesn't add such characters at the begin or end. – Havir strechko Jan 25 '16 at 23:19
  • Possible duplicate of [How to read input from a barcode scanner in vb.net without using a textbox?](http://stackoverflow.com/questions/14134126/how-to-read-input-from-a-barcode-scanner-in-vb-net-without-using-a-textbox) – topshot Oct 11 '16 at 14:28
  • See my answer among others at http://stackoverflow.com/questions/14134126/how-to-read-input-from-a-barcode-scanner-in-vb-net-without-using-a-textbox/ – topshot Oct 11 '16 at 14:28

3 Answers3

1

I have always used the TextChanged event and check to see the number of characters added since the last text changed. If typing, it will always be 1. If scanning, it will be more. The one issue is a paste will appear as a scan but in my experience, that is also what I want.

Steve
  • 5,585
  • 2
  • 18
  • 32
  • Sorry , i've found this library : http://www.microsoft.com/en-us/download/details.aspx?id=42081. do you know if this can help me to get full control over the barcode reader and to solve my problem ? – Havir strechko Jan 25 '16 at 19:13
  • No, I don't know anything about that. – Steve Jan 25 '16 at 23:06
0

This would probably not be possible since the barcode reader emulates a keyboard and as far as the computer OS concerns, the barcode reader IS a keyboard.

Many readers can be put into several different modes. If I want a bit more flexibility than emulated keyboard mode I go for RS232 (serial). The Datalogic and Honeywell scanners I have used supports RS232 but I am sure most scanners do.

Just use a System.IO.Ports.SerialPort object to capture data sent from the scanner to the computer.

LinusN
  • 51
  • 3
  • Sorry , i've found this library : http://www.microsoft.com/en-us/download/details.aspx?id=42081. do you know if this can help me to get full control over the barcode reader and to solve my problem ? – Havir strechko Jan 25 '16 at 19:13
  • I have no idea, but to deal with your issue it seems like complete overkill and will likely cause you much more trouble. If you go with a barcode reader with serial port emulation it takes only a few lines of code to do what you want. – LinusN Jan 25 '16 at 22:08
  • sorry friend , but most of barcodes today are USB .The new PC have no SErial port at all. So i think to create my application to support USB barcode readers. – Havir strechko Jan 25 '16 at 23:17
  • All USB connected scanners I have worked with have serial port emulation (just as they can emulate a keyboard). They are connected to the USB port but communicates through a virtual serial port driver. You just switch modes between keyboard/serial etc by scanning configuration codes. – LinusN Jan 26 '16 at 08:59
  • Sorry friend , my barcode reader has only an usb cable to connect on the PC. There are no drivers , no extra software to install. The device is recognized automatically by windows. there are no buttons to switch modes. So how can i switch between Keyboard/Serial as you suggest ? – Havir strechko Jan 26 '16 at 19:16
  • Since you have not mentioned what model you have, and also not mentioned Barcode Reader model as a constraint for the project, I assumed getting a barcode reader that would work could be a feasible option. I have used several different brand and models - all with USB and option to run as virtual serial port instead of keyboard emulation. As I wrote, the communication mode is usually switched by scanning configuration codes with the reader. Drivers are usually native Windows ones, but this could differ. – LinusN Jan 26 '16 at 21:26
  • I'm creating my application as a general application that can be used with Barcode Readers. But supposing that most of barcode readers today are USB , i have several types and i'm testing them during the application creation's process. But all these barcode readers that i've chosen for test, are recognized by Windows automatically as keyboards. So you speak about ".. option to run as virtual serial port instead of keyboard emulation..." How can i detect that my devices have this option , and do you think a client that tomorrow will use my application can easily configure his Barcode Reader ? – Havir strechko Jan 27 '16 at 00:54
  • "How can i detect that my devices have this option...". Read the manual. "...and do you think a client that tomorrow will use my application can easily configure his Barcode Reader". Probably not, but the need for the application to be "general" was not a known constraint to me until now. – LinusN Jan 27 '16 at 13:02
  • Sorry , of course that the application should be General..On my main question i didn't say that i want to create the application for only a specific brand of Barcode Reader. I said " .. from USB Barcode Readers..." – Havir strechko Jan 27 '16 at 18:37
0

The following three conditions that differentiate a barcode scanner from the data input keyboard.

  1. Data from a barcode scanner ends up within 0.3 seconds
  2. Barcode scanner data ends up with an character "enter".
  3. Barcode string length is mostly around 10 characters.

Making use of these conditions you can make programs to capture barcodes from barcode scanner easily and display on proper place very easily. Such programs are simple and their performance is very high. Most barcode recognising software programs are costly and their speed and performance are extremely poor.

Fabrizio
  • 7,603
  • 6
  • 44
  • 104