Link to home
Start Free TrialLog in
Avatar of vlachosg
vlachosg

asked on

How to accept input from USB barcode Reader with Python

Hello,

I am trying to create a program that will accept input from a usb barcode reader and then perform an HTML request to a website forming a url based on the input

eg (http://thewebsite.com/user/432432).

Looking around I found out that using pyusb library, I can lock a specific USB device and accept input from it.

Also using urllib2.urlopen i can perform the html request.

Firstly, how can I make the python script to continuously wait for user input ( the first barcode card is scanned, the url is formed and then again make the script return to wait for user input? )

Secondly, is it possible to create an executable of that script. Not having experience with python I searched and found that there is py2exe. Because this script depends on 3rd party libraries, is py2exe going to automatically package these libraries eg pyusb ( windows installation says that for pyusb to work you need cygwin ...? does that still makes sense if i develop and package under linux) or do i have to do something specific.

Thanks.

PS: if anyone else is aware of other libraries or a better way of doing what I am trying please let me know.
ASKER CERTIFIED SOLUTION
Avatar of clockwatcher
clockwatcher

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of vlachosg
vlachosg

ASKER

thanks for that. I am aware that usb barcode scanners act as keyboard input the problem though is that in the computer that this program is going to be installed the python program will run in the background. So for example when someone is typing something on a texteditor the input is not going to be transferred to the python program as well, is this correct?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
So the scanner is dedicated to your app alone and you want it available regardless of whatever else is going on with the computer at the time?  

In that case, maybe libusb and pyusb will be your best bet.   Not sure if Windows 7 is applicable to you or not, but I have doubts that you'll be able to get a libusb-win32 device driver installed under it since Microsoft cut out support for loading non-signed drivers (in non Test Mode).   It may not be applicable to a libusb-win32 filter-based driver (if that's the direction you end up going) but guessing that it will be--  don't see how the filter driver won't have to have some kernel mode component involved.

If this is windows only, raw input would probably be Microsoft's answer for how to do what it sounds like you want to do-- http://msdn.microsoft.com/en-us/library/ms645543%28VS.85%29.aspx

A C# example:

   http://www.codeproject.com/KB/system/rawinput.aspx?fid=375378&df=90&mpp=25&noise=3&sort=Position&view=Quick&select=2811936
ok so thats what I decided to do after some research. I will write a key logger with pyhook and also add in the barcode card some prefix eg( bc00c ). So when the input from the barcode (acting as keyboard) is entered the key logger will check letter by letter and if it matches the prefix then it will accept the rest as input and process it accordingly.

I guess that is the best choice because it does not tie the bar-code reader to a specific application.

Not completely covered the questions asked.