问题
I am developing a PHP based web app and adding support to create and read barcodes. I wanted to know how can I import data from a barcode reader connected via USB to the PC running the web app? Is there any standard format in which the barcode scanners transmit data?
回答1:
Obviously depends on producer and model. The better ones have more than a single mode. But three strategies are common:
1.) they act as a keyboard, thus "typing" whatever is scanned. This is fine for small volume duty only and forces you to have a connection to the system. So for a web app you need a simple text input field.
2.) they contain some sort of memory (typically an SD-Slot/-Card) where they store scanned codes. This enables you to "upload" the scanned data in an asynchronus schedule, for example when coming back from a trip through the shop or whatever. The SD cards have a standard filesystem, the codes are typically scanned into CSV files. So for a web app you require a file upload or have to process the codes in a batch run.
3.) they use WLAN and can use things like a REST-API to "upload" their data. Usually not really usable in my experience due to problems with the feedback. For a web app this means you would have to add such an API.
Oh, and a funny thing: the better ones have to be programmed. This is usually done by scanning endless series of codes from a manual booklet. A very "interesting" process :-)
回答2:
Most barcode scanners present themselves to computers as keyboards. If the one you are using is one of those, the data format will be the same as normal typing.
You can capture data with a regular <input>
(that has the focus) in the web application.
来源:https://stackoverflow.com/questions/12753248/import-data-from-a-barcode-reader-to-a-web-app