簡體   English   中英

Google Chrome Web Serial API:如何配置Modbus RTU的參數?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM