|
|
|
@ -106,8 +106,6 @@ |
|
|
|
}, |
|
|
|
//写入控制命令
|
|
|
|
async writeBLECharacteristicValue(onDone) { |
|
|
|
console.log('数据啊----------', data1) |
|
|
|
|
|
|
|
let printerJobs = new PrinterJobs(); |
|
|
|
|
|
|
|
printerJobs.setAlign('ct').setSize(2, 2).setLineSpacing(60).print( |
|
|
|
@ -251,24 +249,14 @@ |
|
|
|
|
|
|
|
const end = Math.min(currentIndex + maxChunk, totalLength); |
|
|
|
const chunkLength = end - currentIndex; |
|
|
|
|
|
|
|
// 创建一个全新的、长度精确的 ArrayBuffer
|
|
|
|
const valueToSend = new ArrayBuffer(chunkLength); |
|
|
|
const dstView = new Uint8Array(valueToSend); |
|
|
|
|
|
|
|
// 将源数据拷贝到新的 ArrayBuffer 中
|
|
|
|
dstView.set(srcView.subarray(currentIndex, end)); |
|
|
|
|
|
|
|
console.log('发送分包:', currentIndex, '长度:', chunkLength); |
|
|
|
|
|
|
|
// 【核心修复】:直接调用 bluetooth 对象封装好的方法
|
|
|
|
// 它内部会自动使用正确的 bluetooth.deviceId, bluetooth.serviceId, bluetooth.writeId
|
|
|
|
bluetooth.writeBLECharacteristicValue(valueToSend).then(() => { |
|
|
|
currentIndex = end; |
|
|
|
// 成功后,延迟再发下一个
|
|
|
|
setTimeout(sendNextChunk, delay); |
|
|
|
}).catch((err) => { |
|
|
|
console.error('发送失败:', err); |
|
|
|
|
|
|
|
isPrint = false; |
|
|
|
if (typeof onDone === 'function') onDone(err); |
|
|
|
}); |
|
|
|
|