Commit 38e6d930 by pye52

修复扫码流程异常:

1、在等待数据时不再是"正在扫描"状态,当串口存在数据时才修改为"正在扫描"状态
2、存在测试值时,仍会读取串口,避免串口数据堆积
3、修复读取串口数据时,读取到终止符仍不结束读取过程的异常(漏写!)
parent cac1b270
......@@ -34,7 +34,7 @@ public abstract class BaseQRCodeScan implements IQRCodeScan {
}
byte[] buf = null;
int len = 0;
while (buf == null || end(buf)) {
while (buf == null || !end(buf)) {
byte[] b = new byte[64];
int l = serialPortIS.read(b);
if (l == 0) break;
......
......@@ -77,25 +77,20 @@ public class QRCodeViewModel extends ViewModel {
private Runnable scanRunnable = () -> {
qrCodeState.postValue(new QRCodeState(QRCodeState.IDLE));
LogUtils.i(TAG, "开始扫描二维码");
// 等待串口数据
// noinspection LoopStatementThatDoesntLoop
while (!scan.available()) {
qrCodeState.postValue(new QRCodeState(QRCodeState.SCANNING));
break;
}
while (!scan.available()) {}
qrCodeState.postValue(new QRCodeState(QRCodeState.SCANNING));
// 读取串口扫描的二维码数据
String scanData;
// 若存在测试数据,则直接读取测试数据
try {
scanData = scan.scan();
} catch (Exception e) {
LogUtils.e(TAG, "读取串口数据失败: " + e.getMessage(), e);
qrCodeState.postValue(new QRCodeState(QRCodeState.FAILED));
return;
}
// 若存在测试数据,则使用测试数据覆盖
if (!TextUtils.isEmpty(SmartCanteenUtils.testQRCode)) {
scanData = SmartCanteenUtils.testQRCode;
} else {
try {
scanData = scan.scan();
} catch (Exception e) {
LogUtils.e(TAG, "读取串口数据失败: " + e.getMessage(), e);
qrCodeState.postValue(new QRCodeState(QRCodeState.FAILED));
return;
}
}
// 需要识别二维码的类型
String terminalType = PayData.matchTerminalType(scanData);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment