diff --git a/src/components/SerialProvider/SerialProvider.tsx b/src/components/SerialProvider/SerialProvider.tsx index 5df5cc5..8a54f88 100644 --- a/src/components/SerialProvider/SerialProvider.tsx +++ b/src/components/SerialProvider/SerialProvider.tsx @@ -386,17 +386,18 @@ const useWebSerial = ({ if (writer) { try { // Once speed is fixed, this can be swapped in for the loop below - await writer.write(data); + // await writer.write(data); - // let blob = new Blob([data]); - // const arrayBuffer = await blob.arrayBuffer(); - // const chunkSize = 350; + let blob = new Blob([data]); + const arrayBuffer = await blob.arrayBuffer(); + const chunkSize = 60; - // for (let i = 0; i < arrayBuffer.byteLength; i += chunkSize) { - // const chunk = arrayBuffer.slice(i, i + chunkSize); - // await delay(5); - // await writer.write(new Uint8Array(chunk)); - // } + for (let i = 0; i < arrayBuffer.byteLength; i += chunkSize) { + const chunk = arrayBuffer.slice(i, i + chunkSize); + await delay(5); + await writer.write(new Uint8Array(chunk)); + console.log("CHUNK:", `${i}/${arrayBuffer.byteLength}`); + } writer.releaseLock(); setMessageQueue((prevQueue) => prevQueue.slice(1)); // Remove the message we just wrote from the queue diff --git a/src/utils/serialUtils.tsx b/src/utils/serialUtils.tsx index 42d5787..cfe5d4e 100644 --- a/src/utils/serialUtils.tsx +++ b/src/utils/serialUtils.tsx @@ -93,7 +93,7 @@ export const useWriteCommand = () => { let blob = new Blob([bytes]); const arrayBuffer = await blob.arrayBuffer(); - const chunkSize = 100000; + const chunkSize = 9000; console.log("Total length: ", arrayBuffer.byteLength);