WebUSB可以将网站连接到Chromeos Chromebox中的Kmtronic USB一个中继设备吗?

发布于 2025-01-31 10:57:05 字数 96 浏览 4 评论 0原文

嗨,我试图直接在Chrome OS设备上直接对USB中继的网站进行控制。过去,我只是在Ubuntu设备上使用了一些终端脚本在启动时运行,但是Chrome OS使我很难做这项工作。

Hi I am trying to give a website direct on/off control of a usb relay on a chrome os device. In the past I just used some terminal scripts to run on start-up on a ubuntu device but chrome os is giving me a hard time making this work.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

五里雾 2025-02-07 10:57:05

基于示例linux代码看起来这些设备正在使用FTDI USB串行芯片并支持一组非常简单的命令,以打开和关闭中继。 FTDI芯片由Chromeos支持,因此您可以使用Web Serial API来控制设备:

let port = navigator.serial.requestPort();
await port.open({ baudRate: 9600 });
let writer = port.writable.getWriter();
writer.write(new Uint8Array([0xff, 0x01, 0x01]);  // Turn relay on command.
await writer.close();
await port.close();

这是一个非常最小的示例。您可以通过将过滤器传递到requestPort()仅选择所需的USB设备来改进此问题。您也不需要每次请求许可。您可以调用navigator.serial.getports()获取您的网站已经有权访问的端口列表。

参见 https://web.dev/serial https://wicg.github.io/serial 有关如何使用此API的更多信息。

Based on the sample Linux code it looks like these devices are using an FTDI USB serial chip and support a very simple set of commands to turn the relays on and off. The FTDI chips are supported by ChromeOS and so you can use the Web Serial API to control the device like this:

let port = navigator.serial.requestPort();
await port.open({ baudRate: 9600 });
let writer = port.writable.getWriter();
writer.write(new Uint8Array([0xff, 0x01, 0x01]);  // Turn relay on command.
await writer.close();
await port.close();

This is a very minimal example. You can improve this by passing a filter to requestPort() to select only the USB devices you want. You also don't need to request permission every time. You can call navigator.serial.getPorts() to get a list of ports that your site already has permission to access.

See https://web.dev/serial and https://wicg.github.io/serial for more information about how to use this API.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文