![](/img/trans.png)
[英]Google Chrome Web Serial API: How do I address a Modbus device with a hex code?
[英]Google Chrome Web Serial API: How do I configure the parameters for Modbus RTU?
我打算在 Google Chrome 中使用 Web 串行 API 来寻址具有 Modbus RTU 的设备。
必须指定波特率才能开始设置 - 因此这已经完成。
以下链接指向描述如何设置参数的文档部分:Googhttps://wicg.github.io/serial/#serialoptions-dictionary
我不明白语法解释。 Javascript 不知道“字典”。
谢谢你的帮助
正如https://web.dev/serial/#open-port所解释的,一旦你有一个SerialPort
object,使用所需的波特率调用port.open()
将打开串行端口。 baudRate
字典成员指定通过串行线路发送数据的速度。 它以比特每秒 (bps) 为单位表示。
检查您设备的文档以获取正确的值,因为如果指定不正确,您发送和接收的所有数据都将是乱码。 对于某些模拟串行端口的 USB 和蓝牙设备,此值可以安全地设置为任何值,因为它会被模拟忽略。
// Prompt user to select any serial port.
const port = await navigator.serial.requestPort();
// Wait for the serial port to open.
await port.open({ baudRate: 9600 });
async function start()
{
// Prompt user to select any serial port.
const port = await navigator.serial.requestPort();
// Wait for the serial port to open.
await port.open({ baudRate: 9600, dataBits: 8, stopBits: 2, ParityType: "none"});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.