Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Calculator

0

45
Views
How to send a file with web serial api

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();
7 months ago ยท Santiago Gelvez
Answer question
Find remote jobs