检测条形码扫描仪何时结束输入

发布于 2024-11-06 06:32:42 字数 440 浏览 3 评论 0原文

我正在编写一个从条形码扫描仪读取输入的应用程序,我希望它的工作方式是:它作为键盘记录器工作,当输入足够快时,我知道我正在从条形码扫描仪获取输入。

现在我的问题是我不知道何时从条形码扫描仪获得最后一个字符,所以我知道我有一个最终且有效的条形码。

我的方法仅在收到字符时才会被调用,因此此时我必须检查我的字符是否是最后收到的字符。

我想要做到这一点的方法是,我在方法末尾创建一个新线程,该线程休眠 MAXIMUM_TIME_BETWEEN_CHARACTERS_FROM_BARCODE_SCANNER + 1 毫秒,唤醒后它会验证是否收到任何新字符,如果我这样做了,线程就会死亡,如果没有收到新字符,这意味着收到完整的条形码并且我可以使用它。

但通过这样做,我开始遇到各种奇怪的错误,比如执行过早终止。

谁能提出不同的解决方案?

如果相关的话,我正在用 C# 编写此内容。

I am writing an app that reads the input from a barcode scanner, the way I want it to work like is: it works as a keylogger and when the input is fast enough I know I'm getting input from the barcode scanner.

Now my problem is I don't know when I get the last character from the barcode scanner so I know I have a final and valid barcode.

My method only gets called when a character is received, so this is when I have to check if my character is the final one received.

The way I wanted to do this is, I create a new thread at the end of my method that sleeps for MAXIMUM_TIME_BETWEEN_CHARACTERS_FROM_BARCODE_SCANNER + 1 milliseoconds, after it wakes up it verifies if I received any new characters, if I did it the thread dies, if no new characters are received it means the full barcode is received and I can use it.

But by doing this I started getting all sorts of weird bugs, like execution dying prematurely.

Can anyone suggest a different solution?

I am writing this in C# if it's relevant.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

戏剧牡丹亭 2024-11-13 06:32:42

您是否使用实际的条形码扫描仪测试过您的程序?因为根据我的经验,我使用的条形码在它扫描的字符串/数字的末尾附加换行符。

Have you tested your program with actual barcode scanner? Because from my experience the barcode which I use append newline character at the end of the string/number it scanned.

酸甜透明夹心 2024-11-13 06:32:42

我重组了这个解决方案:

我想要做到这一点的方法是,我在方法末尾创建一个新线程,该线程休眠 MAXIMUM_TIME_BETWEEN_CHARACTERS_FROM_BARCODE_SCANNER + 1 毫秒,唤醒后它会验证是否收到任何新字符(如果我对线程执行了此操作)死了,如果没有收到新字符,则意味着已收到完整的条形码,我可以使用它。

最终成功了。我仍然不知道是什么导致了我之前的错误,但在重组代码之后,我对这种方法完全没有任何问题。

I restructured this solution:

The way I wanted to do this is, I create a new thread at the end of my method that sleeps for MAXIMUM_TIME_BETWEEN_CHARACTERS_FROM_BARCODE_SCANNER + 1 milliseoconds, after it wakes up it verifies if I received any new characters, if I did it the thread dies, if no new characters are received it means the full barcode is received and I can use it.

and it eventually worked. I still do not know what caused my previous errors but after restructuring the code I have had no problems with this approach at all.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文