From d1098f26590417ce7081b67b7df4c965790761dc Mon Sep 17 00:00:00 2001 From: aihe <961836564@qq.com> Date: Sun, 12 May 2024 02:21:02 +0800 Subject: [PATCH] uu --- .../tpx-bluetooth-print/print/printJob.js | 35 +++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/components/tpx-bluetooth-print/print/printJob.js b/components/tpx-bluetooth-print/print/printJob.js index f6d0444..752fdb1 100644 --- a/components/tpx-bluetooth-print/print/printJob.js +++ b/components/tpx-bluetooth-print/print/printJob.js @@ -24,24 +24,31 @@ export function sendDataToDevice(options) { let byteLength = options.value.byteLength; - //这里默认一次20个字发送 + // 这里默认一次20个字发送 const speed = options.onceByleLength || 20; + console.log('byteLength====', byteLength) if (byteLength > 0) { + console.log('speed====', speed) + console.log('value====', options.value) uni.writeBLECharacteristicValue({ ...options, // writeType:"writeNoResponse", value: options.value.slice(0, byteLength > speed ? speed : byteLength), success: function (res) { - if (byteLength > speed) { - sendDataToDevice({ - ...options, - value: options.value.slice(speed, byteLength), - }); - } else { - options.lasterSuccess && options.lasterSuccess(); - } + // 【writeBLECharacteristicValue】安卓存在频繁调用失败的情况,下次调用前必须加上延迟 + setTimeout(()=> { + if (byteLength > speed) { + sendDataToDevice({ + ...options, + value: options.value.slice(speed, byteLength), + }); + } else { + options.lasterSuccess && options.lasterSuccess(); + } + },10) }, fail: function (res) { + console.log('writeBLECharacteristicValue:fail====', res) options.onError && options.onError(res); }, }); @@ -116,7 +123,6 @@ function grayPixle(pix) { } */ export function overwriteImageData(data) { - console.log("overwriteImageData data====", data) let sendWidth = data.width, sendHeight = data.height; const threshold = data.threshold || 180; @@ -174,13 +180,16 @@ export function overwriteImageData(data) { */ export function sendDataToPrint(options, allUint8Array) { const allLenth = allUint8Array.length; - console.log("====allLenth===", allLenth) + console.log("sendDataToPrint:allLenth=======", allLenth) + console.log("sendDataToPrint:allUint8Array-len=======", allUint8Array.length) const writeArrayCopyer = allUint8Array.slice(0); const print = (options, writeArray) => { + console.log("===writeArray.length===", writeArray.length) if (writeArray.length) { + let curBuffer = writeArray.shift().buffer sendDataToDevice({ ...options, - value: writeArray.shift().buffer, + value: curBuffer, lasterSuccess: () => { options.onProgress && options.onProgress(Math.floor(((allLenth - writeArray.length) / allLenth) * 100)); @@ -246,8 +255,6 @@ export function getImageCommandArray(opt = {}, imageInfo = {}) { } */ export function getPrintImageWriteArray(opt = {}, imageInfo = {}) { - console.log('getPrintImageWriteArray:opt======', opt) - console.log('getPrintImageWriteArray:imageInfo=====', imageInfo) const lineByLine = typeof opt.lineByLine !== 'boolean' ? true : opt.lineByLine; const width = imageInfo.width; let arr = imageInfo.array;