I am currently building a web application that allows users to type text and send an image that would be send to a laser engraver through a serial port. Now I'm stuck with a problem which is I can send a gcode string to the laser engraver but I can't send a file, so how would I send a file with Web Serial API.
let imageShow = canvas.toDataURL();
const regex = /data:.*base64,/;
console.log(imageShow.replace(regex, ""));
imageShow.replace(regex, "");
function b64_to_utf8(str) {
return decodeURIComponent(escape(window.atob(str)));
}
image = b64_to_utf8(imageShow);
const encoder = new TextEncoder();
const writer = port.writable.getWriter();
await writer.write(encoder.encode(image));
writer.releaseLock();