我如何使用 Web Serial API 发送文件?

How would I send a file with Web Serial API?

我是个新手,我今天才开始研究这个。我有一本 chromebook 运行 chrome 版本 96.0.4664.111(官方构建)(64 位),以及我已加载 python 的 raspberry pi pico引导加载程序打开(拖放)。我试图从我的浏览器串行访问 pico 以加载我的源代码,因为我无法在我的 chromebook 上安装 thawny。我拼凑了这个 javascript 函数,它使用网络串行 api 连接到 pico。

const filters = [
  { usbVendorId: 0x2E8A, usbProductId: 0x0003 },
  { usbVendorId: 0x2E8A, usbProductId: 0x0005 }
];

// Prompt user to select an Arduino Uno device.
const port = await navigator.serial.requestPort({ filters });

const { usbProductId, usbVendorId } = port.getInfo();

// Wait for the serial port to open.
await port.open({ baudRate: 9600 });

const textDecoder = new TextDecoderStream();
const readableStreamClosed = port.readable.pipeTo(textDecoder.writable);
const reader = textDecoder.readable.getReader();

// Listen to data coming from the serial device.
while (true) {
  const { value, done } = await reader.read();
  if (done) {
    // Allow the serial port to be closed later.
    reader.releaseLock();
    break;
  }
  // value is a Uint8Array.
  console.log(value);
}

// Listen to data coming from the serial device.
while (true) {
  const { value, done } = await reader.read();
  if (done) {
    // Allow the serial port to be closed later.
    reader.releaseLock();
    break;
  }
  // value is a string.
  console.log(value);
}

const textEncoder = new TextEncoderStream();
const writableStreamClosed = textEncoder.readable.pipeTo(port.writable);

const writer = textEncoder.writable.getWriter();

await writer.write("hi");

// Allow the serial port to be closed later.
writer.releaseLock();

我找不到让这个程序上传文件的方法,如果有人能帮助我,我将不胜感激。 如果我不清楚或非常愚蠢,请原谅,我对此完全陌生,昨晚新年过后我真的很累。谢谢!

我找到了适合我的问题的解决方案,tinkerdoodle.cc.