Barcode scanning within C#.NET applications

2,314 views
Skip to first unread message

Badawi

unread,
Sep 21, 2008, 7:18:45 PM9/21/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Hi all of you,

I'm a newbie in C#.NET development and i need help in handling barcode
scanners within C# application.
How i can read barcodes from a barcode scanner (both types USB and PS/
2)?
And if there is a way to read barcodes independently on the scanner
type (USB or PS/2), i will be so happy to know.

thanks in advance,
Badawi

Arsalan Tamiz

unread,
Sep 23, 2008, 2:26:08 AM9/23/08
to DotNetDe...@googlegroups.com
Normally PS/2, barcode scanners send keystrokes. Which means when you scan the code, it comes in like someone typing the barcode through keyboard. Usually it ends on CrLf.
 
And I haven't used the USB barcode scanners. Maybe they work in the same manner.

Paul

unread,
Sep 23, 2008, 8:53:10 AM9/23/08
to DotNetDe...@googlegroups.com
I use barcode scanners almost daily. The USB does indeed work like the PS/2. Most of the scanners are programmable as well. What I have found is inserting a tab after the bar code allows you to capture a lost focus event.
 
Try some testing. Create a form with a textbox. Make sure the textbox has the focus then scan the barcode.
 
If there are other issues you are trying to resolve, please post them.

--
_______________________________

Take care,
Paul

It is not we non-interventionists who are isolationists. The real isolationists are those who impose sanctions and embargos on countries and peoples across the globe and who choose to use force overseas to promote democracy. A counterproductive approach that actually leads the U.S. to be more resented and more isolated in the world.

Dr. Ron Paul

www.RonPaul2008.com

kodali ranganadh

unread,
Sep 23, 2008, 3:47:11 AM9/23/08
to DotNetDe...@googlegroups.com
Ya, there is no difference between PS/2 and USB .. i had work with both types of bar code scanners, both are using keystrocks only .. 

Grzegorz K

unread,
Sep 23, 2008, 4:47:21 AM9/23/08
to DotNetDe...@googlegroups.com
 Scanners works exactly like a keyboards. You can check it by opening a notepad,word etc and scan a code, it should appears on word processor you had open.

2008/9/23 Arsalan Tamiz <sall...@gmail.com>

Brock

unread,
Sep 24, 2008, 8:28:47 AM9/24/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
I use a USB scanner and tried the notepad trick and it writes fine.
One related question while we are on this topic... is it possible to
scan a barcode with say a 10 digit number that has the same value in a
database (that number being the key field) and have another field, the
CompanyName, display immediately in a textbox?
Thanks!

On Sep 23, 4:47 am, "Grzegorz K" <the.par...@gmail.com> wrote:
>  Scanners works exactly like a keyboards. You can check it by opening a
> notepad,word etc and scan a code, it should appears on word processor you
> had open.
>
> 2008/9/23 Arsalan Tamiz <sallus...@gmail.com>
>
>
>
> > Normally PS/2, barcode scanners send keystrokes. Which means when you scan
> > the code, it comes in like someone typing the barcode through keyboard.
> > Usually it ends on CrLf.
>
> > And I haven't used the USB barcode scanners. Maybe they work in the same
> > manner.
>
> > On Mon, Sep 22, 2008 at 4:18 AM, Badawi <badaw...@gmail.com> wrote:
>
> >> Hi all of you,
>
> >> I'm a newbie in C#.NET development and i need help in handling barcode
> >> scanners within C# application.
> >> How i can read barcodes from a barcode scanner (both types USB and PS/
> >> 2)?
> >> And if there is a way to read barcodes independently on the scanner
> >> type (USB or PS/2), i will be so happy to know.
>
> >> thanks in advance,
> >> Badawi- Hide quoted text -
>
> - Show quoted text -

CK

unread,
Sep 24, 2008, 9:19:22 AM9/24/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
knowing nothing about scanners, I MAY be able to answer your last
questions - if a scanner does indeed work like a keyboard, then you
can capture the text changed event, HOWEVER, you may find that this
event is fired as each digit is entered. Therefore you should check
for an expected length, or build a system with a time-boxed buffer so
that you can make sure you have captured all of the barcode.

Then you can do the database lookup and display the results you need.

CK

PS. This is assuming you are using a WinForms application, if it is
webforms then you need to do some AJAXY stuff.
> > - Show quoted text -- Hide quoted text -

Paul

unread,
Sep 24, 2008, 9:28:13 AM9/24/08
to DotNetDe...@googlegroups.com
I guess I'm not following your question. You can scan any barcode you like. Your business logic layer will be responsible for ensuring it is of the correct length and correct type (numeric, alpha, alpha-numeric etc). Once the code has been scanned, you have captured the data and can validate it, then do a look up for related information. Most of the scanners are programable. What I found useful was to code the gun to insert a tab after the data. This fires a lost focus event, assuming that you scan the data into a textbox. Take the resulting data and validate it. Then do what you need to do.
Didn't read CK's post. S/He is correct. The textchanged event will fire for each character in the scanned results. Checking for a specific length may not work. You may be trying to capture a 10 char entry. If the incorrect code is scanned and you have 11 or more characters, you could run into problems. That is why I advocate a tab character after the code is scanned.

mostafa badawi

unread,
Sep 24, 2008, 1:26:23 AM9/24/08
to DotNetDe...@googlegroups.com
So, if the barcode scanner works like a keyboard, is there a notifier
to the end of the input?

--
Mostafa Badawi

kierenj

unread,
Sep 24, 2008, 5:10:09 AM9/24/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
I've implemented barcode scanning in a recent project for a client.

Indeed it does work as a keyboard. The difficulty with this is, if
you are validating a barcode, or it has to be a specific length.. you
can't tell if the user is simply typing something, scanning a bad
barcode, etc. If you want 10 digits and set a textbox limit, what if
the user scans a 15 digit barcode (you won't know), or a 5 digit one,
followed by the correct 10 digit one (you'll get half of each).

What I found best is to create a user control, kind of like a stateful
textbox wrapper, specifically for barcodes. You can implement it like
this:

* Textbox, unlimited length
* Timer, set to ~500ms: check for valid barcode (length-wise, etc) -
if it's there, disable timer, fire event, run barcode processing
method, etc. If not, CLEAR the textbox text
* OnTextChanged event: disable, then re-enable the timer

This means if you scan an invalid code, it's cleared out after 500ms.
If the user has to be able to type a barcode too, they will have to
enter each keypress within 500ms, so you could modify that value or
have a 'manual entry' link with simple entry dialog.

Hope this helps.

Paul

unread,
Sep 24, 2008, 2:05:08 PM9/24/08
to DotNetDe...@googlegroups.com
Nope. Unless you are scanning into a textbox and set the scanner to tab out when completed.

sallushan

unread,
Sep 25, 2008, 1:13:43 AM9/25/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Hey Paul, the one I have used sends the CrLf at end, which indicates
the end of barcode.

On Sep 24, 11:05 pm, Paul <solde...@gmail.com> wrote:
> Nope. Unless you are scanning into a textbox and set the scanner to tab out
> when completed.
>

Paul

unread,
Sep 25, 2008, 9:18:43 AM9/25/08
to DotNetDe...@googlegroups.com
OK what you might be able to do is capture the keypress event for the textbox. Check the entered character for the ascii representation of CrLf. Capture the data and validate it.
 
HTH
Reply all
Reply to author
Forward
0 new messages