简体   繁体   English

如何为我的 Java 应用程序模拟条形码扫描仪?

[英]how to simulate barcode scanner for my java application?

I created a Java application and want to use barcode scanner in my Java application.我创建了一个 Java 应用程序并想在我的 Java 应用程序中使用条形码扫描仪。
but don't have a device Barcode Scanner但没有设备条码扫描仪
How can I simulate a Barcode Scanner for testing my Java Application?如何模拟条形码扫描仪来测试我的 Java 应用程序?

If you are running your application from the console,如果您从控制台运行您的应用程序,

Scanner scan = new Scanner(System.in);
String barcode = scan.nextLine();

Otherwise just pass your barcode to main method args.否则只需将您的条形码传递给main方法 args。

It really depends on how you want the scanner to connect to the system later on.这实际上取决于您希望扫描仪稍后如何连接到系统。

There are scanners that just use keyboard emulation.有些扫描仪只使用键盘模拟。 In that case you don't need to do anything (just make sure the right input box is active when expecting barcode input).在这种情况下,您无需执行任何操作(只需确保在需要输入条码时正确的输入框处于活动状态)。

Other scanners connect to the system through a serial port emulation (for example, there's an USB to serial driver for Symbol/Motorola and Datalogic gun scanners).其他扫描仪通过串行端口仿真连接到系统(例如,Symbol/Motorola 和 Datalogic 枪式扫描仪有一个 USB 转串口驱动程序)。 In that case, you open the serial port in Java and get scanner input as serial data.在这种情况下,您在 Java 中打开串行端口并将扫描仪输入作为串行数据。 To simulate this, you'd have to connect your PC to another PC using a cross-over RS232 cable and could then use Hyperterminal/Putty/[whatever there is on linux or other OSs] to send data to your PC over the serial cable.要模拟这一点,您必须使用交叉 RS232 电缆将您的 PC 连接到另一台 PC,然后可以使用 Hyperterminal/Putty/[Linux 或其他操作系统上的任何内容] 通过串行电缆将数据发送到您的 PC .

I had a similar need and found the barcode-simulator project on GitHub.我有类似的需求,并在 GitHub 上找到了条形码模拟器项目。 It covers a portion of the concerns raised in the comments, at least for the initial testing.它涵盖了评论中提出的部分问题,至少对于初始测试而言。

Still, there is nothing like the real deal.尽管如此,没有什么比真正的交易更好。 Expect that the mix of real users and real scanners are going to find unexpected holes in your application.预计真实用户和真实扫描仪的组合会在您的应用程序中发现意想不到的漏洞。

Provide really clear input to your clients:为您的客户提供非常清晰的输入:

  • When the users cursor is in the correct field have it change color and show a message like "Waiting for Scan",当用户光标在正确的字段中时,它会改变颜色并显示“等待扫描”之类的消息,
  • Clearly and quickly show if a scan is valid or invalid,清晰快速地显示扫描是有效还是无效,
  • Make it trivial to rescan.使重新扫描变得微不足道。

If your users are clear about what the path of success looks like then it should be good.如果您的用户清楚成功的道路是什么样的,那么它应该是好的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM