attemped from google
This commit is contained in:
@@ -1,7 +1,29 @@
|
|||||||
let port;
|
"use strict";
|
||||||
|
async function connect() {
|
||||||
function setup() {
|
const port = await navigator.serial.requestPort();
|
||||||
port = createSerial();
|
// - Wait for the port to open.
|
||||||
port.open(9600);
|
await port.open({ baudRate: 9600 });
|
||||||
|
let decoder = new TextDecoderStream();
|
||||||
|
const inputDone = port.readable.pipeTo(decoder.writable);
|
||||||
|
const inputStream = decoder.readable;
|
||||||
|
reader = inputStream.getReader();
|
||||||
|
await readLoop();
|
||||||
|
}
|
||||||
|
async function clickConnect() {
|
||||||
|
// CODELAB: Add connect code here.
|
||||||
|
await connect();
|
||||||
|
}
|
||||||
|
async function readLoop() {
|
||||||
|
// CODELAB: Add read loop here.
|
||||||
|
while (true) {
|
||||||
|
const { value, done } = await reader.read();
|
||||||
|
if (value) {
|
||||||
|
log.textContent += value + '\n';
|
||||||
|
}
|
||||||
|
if (done) {
|
||||||
|
console.log('[readLoop] DONE', done);
|
||||||
|
reader.releaseLock();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user