提交 e5109733 authored 作者: vipcxj's avatar vipcxj

add: 加入读卡api

上级 a5aea730
import IDCard from '../native/IDCard';
import { tryIt } from '../utils/helper';
export const scan = async () => {
try {
await IDCard.open();
await tryIt(10, async () => IDCard.authenticate(150), 10);
return await tryIt(10, async () => IDCard.read(2300), 10);
} finally {
await IDCard.close();
}
};
...@@ -117,3 +117,20 @@ export function filterValidParams(params) { ...@@ -117,3 +117,20 @@ export function filterValidParams(params) {
return _.pickBy(params, _.negate(_.isUndefined)); return _.pickBy(params, _.negate(_.isUndefined));
} }
export async function tryIt(times, cb, delay) {
let err;
for (let i = 0; i < times; ++i) {
try {
return await cb();
} catch (e) {
err = e;
}
if (delay) {
await sleep(delay);
}
}
if (err) {
throw err;
}
};
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论