A common occurrence is for barcode readers to simply 'type' the
decoded value as if it were a keyboard, if there isn't some (usually
proprietary) software running that steals that input on the driver-api
level.

Note that this also commonly occurs with many magnetic card readers --
no special software needed, as it acts like a USB Human-input-device
by default.

In such a case (assuming the browser window has focus), you can just
read key events on the document object in javascript -- after a
hardcoded input length has been read, or a timeout of say 1 second
since the last 'keypress', you submit an ajax event.  However,
distinguishing between the barcode reader and a *real* keyboard is
something you have to watch out for.  On the other hand, you can
intentionally not distinguish between *real* and barcode-reader
'keyboards', and transparently handle manually typed barcodes when it
won't scan.

The simplest solution is just to make a regular text input that you
give focus to when the page loads so that the user can see the value
that's being scanned.

----

If you are using proprietary software or whatever, then it does get
really tricky and Alexey and Michele's advice is as good as it gets
unless you want to write a Java applet or ActiveX control, for
example.

On Aug 25, 3:59 am, Michele Comitini <michele.comit...@gmail.com>
wrote:
> Is the barcode reader connected on the same machine running web2py?
>
> If yes you just need to create a function in the controller that you
> can call and reads the value and puts it in the session or
> where you need.
> something like this (it will be more complex depending on hw):
>
> def barcoderead:
>      barfile = file('<barcode device>', 'r')
>      code = barfile.read() # blocks  here until data arrives
>      barfile.close()
>      return dict(barcode=code)
>
> You can callit as a normal 
> url:http://your.host.name/barcodeapplication/barcodecontroller/barcoderead
> so you
> can use anything you like for instance ajax
>
> hope that helps!
> mic
>
> 2010/8/25 Neveen Adel <nevo.a...@gmail.com>:
>
> > Hello,
>
> > Is there a way to connect my  web2py application to barcode reader and
> > then get the data  after passing
> > barcode card into the barcode?
>
> > Thanks in Advance
>
> > Neveen
>
>

Reply via email to