繁体   English   中英

如何使用 Web 序列号 API 发送文件?

[英]How would I send a file with Web Serial API?

我是一个完全的新手,我今天才开始研究这个。 我有一个运行 chrome 版本 96.0.4664.111(官方构建)(64 位)的 chromebook,还有一个树莓派 pico,我已经在(拖放)上加载了 python 引导加载程序。 我试图从我的浏览器串行访问 pico 以加载我的源代码,因为我无法在我的 chromebook 上安装 thawny。 我拼凑了这个 javascript function,它使用 web 序列号 Z8A5DA52ED126447D359E70C057 连接到 pico2。

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。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM