c++ - 从设备文件中读取提供了额外的输入
问题描述
我在 USB-COM 模式下通过 USB 将 QR-Code-Scanner 连接到我的 Linux-PC。当我这样做时,会创建一个文件:/dev/serial/by-id/usb-Datalogic_ADC__Inc._Handheld_Barcode_Scanner_S_N_E18C59366.-if00
我像这样从这个文件中读取:
#include <iostream>
#include <fstream>
#include <string>
#include <unistd.h>
using namespace std;
int main () {
while (1) {
ifstream bufferLink("/dev/serial/by-id/usb-Datalogic_ADC__Inc._Handheld_Barcode_Scanner_S_N_E18C59366.-if00");
if (bufferLink.is_open()) {
string line;
while (!bufferLink.eof()) {
cout << "Waiting for input: " << endl;
getline(bufferLink, line);
cout << "+++++++++ Line: " << line << endl;
}
}
}
usleep(1000*1000);
return 0;
}
然后我用数据创建了一个二维码:Andre Mantei ist der Beste。
但是当我用我的扫描仪读取二维码时,它给了我很多额外的输出:
Waiting for input:
+++++++++ Line: Andre Mantei ist der Beste.
Waiting for input:
+++++++++ Line:
Waiting for input:
+++++++++ Line:
Waiting for input:
+++++++++ Line: !"#$%&'()*+,-./0123456789:;<=>?@
Waiting for input:
+++++++++ Line:
Waiting for input:
+++++++++ Line: ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`
Waiting for input:
+++++++++ Line:
Waiting for input:
+++++++++ Line: abcdefghijklmnopqrstuvwxyz{|}
Waiting for input:
+++++++++ Line:
Waiting for input:
+++++++++ Line:
Waiting for input:
+++++++++ Line:
Waiting for input:
+++++++++ Line:
Waiting for input:
+++++++++ Line:
Waiting for input:
+++++++++ Line:
Waiting for input:
+++++++++ Line: !"#$%&'()*+,-./0123456789:;<=>?@
Waiting for input:
+++++++++ Line:
Waiting for input:
+++++++++ Line: ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`
Waiting for input:
+++++++++ Line:
Waiting for input:
+++++++++ Line: abcdefghijklmnopqrstuvwxyz{|}
Waiting for input:
+++++++++ Line:
Waiting for input:
它并不总是发生,而是大多数时候发生。谁能解释这种行为?
解决方案
推荐阅读
- android - 即使使用正确的注释,Firestore 数据也不会显示在 RecyclerView 中
- android - Pan Responder 中的 ScrollView 不滚动
- material-ui - 材料版本 5 中是否删除了 createBreakpoints 方法?
- javascript - 使用 javascript Math.sin, Math.cos 在 2D 中旋转 svg 多边形
- javascript - 对象数组的反应本机映射函数中的“未定义”错误
- android - 如何在不暂停 Calling-Activity 的情况下启动 Intent?
- python - 获取 python 可执行文件的原始脚本名称
- ios - 如果一个应用程序只显示加密消息,它是否属于出口合规性
- php - Xampp 上的 Laravel 虚拟主机无法正常工作
- react-native - 尝试在模拟器中 luanch avd 时出现 android studio 错误