简体   繁体   English

如何在不冻结程序主线程的情况下等待条形码阅读器输入?

[英]How to wait for a barcode reader input without freezing the main thread of my program?

i'm writing a program using C++ that finds an object on a video, then the user must scan, with a barcode reader, some code in a list, then if the code is correct, the information is sent to a table in MySql.我正在使用 C++ 编写一个程序,用于在视频中查找对象,然后用户必须使用条形码阅读器扫描列表中的一些代码,如果代码正确,则将信息发送到 MySql 中的表。

i am stuck in the part of waiting for the user to scan the barcode.我被困在等待用户扫描条形码的部分。 if i use a loop then the program gets frezed, so maybe i must wait for some keyboard event(because the barcode behaves like it), but this function can't continue if the code hasn't been readed.如果我使用循环,那么程序会被冻结,所以也许我必须等待一些键盘事件(因为条形码的行为与它类似),但是如果尚未读取代码,则此功能无法继续。

so any one can point me what is the best way to do it?..所以任何人都可以指出我最好的方法是什么?..

If your barcode scanner is attached as a keyboard as many of them are, then you need asynchronous IO.如果您的条码扫描器作为键盘连接,那么您需要异步 IO。 Here is example how to read from keyboard without blocking.这是如何在不阻塞的情况下从键盘读取的示例。

C non-blocking keyboard input C 非阻塞键盘输入

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

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