打印机型号:HM-A300
测试命令:! 0 200 200 320 1
PAGE - WIDTH 320
T 28 0 24 24 姓名:张三
T 28 0 24 60 收货日期:2024-3-9
T 28 0 24 96 订单号:20240309xxx
T 28 0 24 132 快递号:SF123456789
PRINT
问题:在小程序端没有问题,app端偶尔出现无线打印的情况。
打印代码:
print(device = {}) {
return new Promise((resolve, reject) => {
if (this.printing) {
resolve("正在打印中")
return
}
this.printing = true
let execCount = 0;
let asyncExecCount = 0;
let failCount = 0;
const maxChunk = 15;
const delay = 20;
const buffer = this.buffer();
for (
let i = 0, j = 0, length = buffer.byteLength; i < length; i += maxChunk, j++
) {
execCount++;
let subPackage = buffer.slice(
i,
i + maxChunk <= length ? i + maxChunk : length
);
setTimeout(() => {
asyncExecCount++;
uni.writeBLECharacteristicValue({
deviceId: device?.deviceId,
characteristicId: device?.characteristicId,
serviceId: device?.serviceId,
value: subPackage,
success: (res) => {
console.log('ok')
},
fail: (res) => {
console.log('fail')
failCount++;
},
complete(e) {
if (execCount == asyncExecCount) {
// 打印结束
console.log('complete', execCount, asyncExecCount,
failCount)
this.printing = false
setTimeout(() => {
resolve(failCount > 0 ? "打印失败" : "打印成功");
}, 200)
}
},
});
}, j * delay);
}
});
}
1 个回复
1***@qq.com (作者)
使用FORM命令在app端 基本上100%会无限打印