将条码扫描器集成到 php 应用程序中?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8465839/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 04:47:49  来源:igfitidea点击:

integrating barcode scanner into php application?

php

提问by user1035388

We have been developing web application in php.
We need barcode scanner to be integrated into our application.

我们一直在用 php 开发 web 应用程序。
我们需要将条码扫描器集成到我们的应用程序中。

Our application is divided into two modules, users and merchant.

我们的应用程序分为两个模块,用户和商家。

When user comes and scans the card, merchant should be identified the user by barcode number. Admin will give barcode number and that is being sent to the card manufacturer and the number will be assigned to the magnetic stripe.

当用户来扫卡时,商户应通过条码号识别用户。管理员将提供条形码编号,并将该编号发送给卡制造商,该编号将分配给磁条。

As i know scanner can acts as a key board, can you please tell the method to integrate barcode scanner into this php web based application?

据我所知,扫描仪可以充当键盘,您能否告诉将条码扫描仪集成到这个基于 php 的 web 应用程序中的方法?

回答by Tahir Yasin

PHP can be easily utilized for reading bar codes printed on paper documents. Connecting manual barcode reader to the computer via USB significantly extends usability of PHP (or any other web programming language) into tasks involving document and product management, like finding a book records in the database or listing all bills for a particular customer.

PHP 可以很容易地用于读取打印在纸质文档上的条形码。通过 USB 将手动条码阅读器连接到计算机,将 PHP(或任何其他 Web 编程语言)的可用性显着扩展到涉及文档和产品管理的任务中,例如在数据库中查找书籍记录或列出特定客户的所有账单。

Following sections briefly describe process of connecting and using manual bar code reader with PHP.

以下部分简要描述了连接和使用手动条码阅读器与 PHP 的过程。

The usage of bar code scanners described in this article are in the same way applicable to any web programming language, such as ASP, Python or Perl. This article uses only PHP since all tests have been done with PHP applications.

本文中描述的条码扫描器的使用方式同样适用于任何 Web 编程语言,例如 ASP、Python 或 Perl。本文仅使用 PHP,因为所有测试均已使用 PHP 应用程序完成。

What is a bar code reader (scanner)

什么是条码阅读器(扫描仪)

Bar code reader is a hardware pluggable into computer that sends decoded bar code strings into computer. The trick is to know how to catch that received string. With PHP (and any other web programming language) the string will be placed into focused input HTML element in browser. Thus to catch received bar code string, following must be done:

条形码阅读器是一种可插入计算机的硬件,可将解码后的条形码字符串发送到计算机中。诀窍是知道如何捕获接收到的字符串。使用 PHP(和任何其他 Web 编程语言),字符串将被放置到浏览器中的焦点输入 HTML 元素中。因此,要捕获接收到的条形码字符串,必须执行以下操作:

just before reading the bar code, proper input element, such as INPUT TEXT FIELD must be focused (mouse cursor is inside of the input field). once focused, start reading the code when the code is recognized (bar code reader usually shortly beeps), it is send to the focused input field. By default, most of bar code readers will append extra special character to decoded bar code string called CRLF (ENTER). For example, if decoded bar code is "12345AB", then computer will receive "12345ABENTER". Appended character ENTER(or CRLF) emulates pressing the key ENTER causing instant submission of the HTML form:

在读取条码之前,必须聚焦正确的输入元素,例如 INPUT TEXT FIELD(鼠标光标位于输入域内)。一旦聚焦,当代码被识别时开始读取代码(条形码阅读器通常会发出短促的哔哔声),它被发送到聚焦的输入字段。默认情况下,大多数条码阅读器会在解码后的条码字符串中附加额外的特殊字符,称为 CRLF (ENTER)。例如,如果解码的条码是“12345AB”,那么计算机将收到“12345AB ENTER”。附加字符ENTER(或CRLF)模拟按 ENTER 键导致 HTML 表单的即时提交:

<form action="search.php" method="post">
    <input name="documentID" onmouseover="this.focus();" type="text">
</form>

Choosing the right bar code scanner

选择合适的条码扫描器

When choosing bar code reader, one should consider what types of bar codes will be read with it. Some bar codes allow only numbers, others will not have checksum, some bar codes are difficult to print with inkjet printers, some barcode readers have narrow reading pane and cannot read for example barcodes with length over 10 cm. Most of barcode readers support common barcodes, such as EAN8, EAN13, CODE 39, Interleaved 2/5, Code 128 etc.

选择条码阅读器时,应考虑使用它读取什么类型的条码。有些条码只允许数字,有些则没有校验和,有些条码很难用喷墨打印机打印,有些条码阅读器的阅读范围很窄,无法读取例如长度超过 10 厘米的条码。大多数条码阅读器都支持常见的条码,例如 EAN8、EAN13、CODE 39、Interleaved 2/5、Code 128 等。

For office purposes, the most suitable barcodes seem to be those supporting full range of alphanumeric characters, which might be:

对于办公用途,最合适的条码似乎是支持全范围字母数字字符的条码,可能是:

  • code 39 - supports 0-9, uppercased A-Z, and few special characters (dash, comma, space, $, /, +, %, *)
  • code 128 - supports 0-9, a-z, A-Z and other extended characters
  • 代码 39 - 支持 0-9、大写的 AZ 和少数特殊字符(破折号、逗号、空格、$、/、+、%、*)
  • 代码128——支持0-9、az、AZ等扩展字符

Other important things to note:

其他需要注意的重要事项:

  • make sure all standard barcodes are supported, at least CODE39, CODE128, Interleaved25, EAN8, EAN13, PDF417, QRCODE.
  • use only standard USB plugin cables. RS232 interfaces are meant for industrial usage, rather than connecting to single PC.
  • the cable should be long enough, at least 1.5 m - the longer the better.
  • bar code reader plugged into computer should not require other power supply - it should power up simply by connecting to PC via USB.
  • if you also need to print bar code into generated PDF documents, you can use TCPDF open source library that supports most of common 2D bar codes.
  • 确保支持所有标准条码,至少支持 CODE39、CODE128、Interleaved25、EAN8、EAN13、PDF417、QRCODE。
  • 仅使用标准 USB 插件电缆。RS232 接口适用于工业用途,而不是连接到单个 PC。
  • 电缆应足够长,至少 1.5 m - 越长越好。
  • 插入计算机的条形码阅读器不需要其他电源 - 只需通过 USB 连接到 PC 即可启动。
  • 如果您还需要将条码打印到生成的PDF文档中,您可以使用支持大多数常见二维条码的TCPDF开源库。

Installing scanner drivers

安装扫描仪驱动程序

Installing manual bar code reader requires installing drivers for your particular operating system and should be normally supplied with purchased bar code reader.

安装手动条码阅读器需要为您的特定操作系统安装驱动程序,并且通常应与购买的条码阅读器一起提供。

Once installed and ready, bar code reader turns on signal LED light. Reading the barcode starts with pressing button for reading.

安装并准备就绪后,条码阅读器会打开信号 LED 灯。读取条码从按下读取按钮开始。

Scanning the barcode - how does it work?

扫描条形码 - 它是如何工作的?

STEP 1- Focused input field ready for receiving character stream from bar code scanner:

第 1步 - 准备好接收来自条形码扫描仪的字符流的重点输入字段:

step 1

step 1

STEP 2- Received barcode string from bar code scanner is immediatelly submitted for search into database, which creates nice "automated" effect:

第 2 步- 从条码扫描器接收到的条码字符串会立即提交到数据库中进行搜索,这会产生很好的“自动化”效果:

step 2

step 2

STEP 3- Results returned after searching the database with submitted bar code:

第 3 步- 使用提交的条形码搜索数据库后返回的结果:

step 3

step 3

Conclusion

结论

It seems, that utilization of PHP (and actually any web programming language) for scanning the bar codes has been quite overlooked so far. However, with natural support of emulated keypress (ENTER/CRLF) it is very easy to automate collecting & processing recognized bar code strings via simple HTML (GUI) fomular.

到目前为止,使用 PHP(实际上是任何 Web 编程语言)来扫描条码似乎都被忽视了。但是,由于对模拟按键 (ENTER/CRLF) 的自然支持,通过简单的 HTML (GUI) 公式可以很容易地自动收集和处理已识别的条形码字符串。

The key is to understand, that recognized bar code string is instantly sent to the focused HTML element, such as INPUT text field with appended trailing character ASCII 13 (=ENTER/CRLF, configurable option), which instantly sends input text field with populated received barcode as a HTML formular to any other script for further processing.

关键是要了解,识别的条形码字符串会立即发送到聚焦的 HTML 元素,例如带有附加尾随字符 ASCII 13(=ENTER/CRLF,可配置选项)的 INPUT 文本字段,它会立即发送填充了已接收的输入文本字段条形码作为任何其他脚本的 HTML 公式,以便进一步处理。

Reference: http://www.synet.sk/php/en/280-barcode-reader-scanner-in-php

参考:http://www.synet.sk/php/en/280-barcode-reader-scanner-in-php

Hope this helps you :)

希望这对你有帮助:)

回答by Pablo Santa Cruz

You can use AJAX for that. Whenever you scan a barcode, your scanner will act as if it is a keyboard typing into your input type="text"components. With JavaScript, capture the corresponding event, and send HTTP REQUEST and process responses accordingly.

您可以为此使用 AJAX。每当您扫描条码时,您的扫描仪就像是键盘输入您的input type="text"组件一样。使用 JavaScript 捕获相应的事件,并发送 HTTP REQUEST 并相应地处理响应。

回答by Jesper Veldhuizen

I've been using something like this. Just set up a simple HTML page with an textinput. Make sure that the textinput always has focus. When you scan a barcode with your barcode scanner you will receive the code and after that a 'enter'. Realy simple then; just capture the incoming keystrokes and when the 'enter' comes in you can use AJAX to handle your code.

我一直在使用这样的东西。只需使用文本输入设置一个简单的 HTML 页面。确保 textinput 始终具有焦点。当您使用条码扫描器扫描条码时,您将收到代码,然后“输入”。那么真的很简单;只需捕获传入的击键,当“输入”进入时,您就可以使用 AJAX 来处理您的代码。

回答by Trey Ellis

If you have Bluetooth, Use twedge on windows and getblue app on android, they also have a few videos of it. It's made by TEC-IT. I've got it to work by setting the interface option to bluetooth server in TWedge and setting the output setting in getblue to Bluetooth client and selecting my computer from the Bluetooth devices list. Make sure your computer and phone is paired. Also to get the barcode as input set the action setting in TWedge to Keyboard Wedge. This will allow for you to first click the input text box on said form, then scan said product with your phone and wait a sec for the barcode number to be put into the text box. Using this method requires no php that doesn't already exist in your current form processing, just process the text box as usual and viola your phone scans bar codes, sends them to your pc via Bluetooth wirelessly, your computer inserts the barcode into whatever text field is selected in any application or website. Hope this helps.

如果您有蓝牙,在 Windows 上使用 twedge 并在 android 上使用 getblue 应用程序,他们也有一些关于它的视频。它是由 TEC-IT 制造的。我通过在 TWedge 中将接口选项设置为蓝牙服务器并将 getblue 中的输出设置设置为蓝牙客户端并从蓝牙设备列表中选择我的计算机来使其工作。确保您的计算机和手机已配对。还要将条码作为输入,将 TWedge 中的操作设置设置为 Keyboard Wedge。这将允许您首先单击所述表单上的输入文本框,然后用您的手机扫描所述产品并等待几秒钟,以便将条形码编号放入文本框中。使用此方法不需要在当前表单处理中尚不存在的 php,只需像往常一样处理文本框,然后手机扫描条形码,将它们通过蓝牙无线发送到您的电脑,您的计算机会将条形码插入到任何应用程序或网站中选择的任何文本字段中。希望这可以帮助。