This commit is contained in:
Sam
2023-10-02 12:05:22 +02:00
parent b7be959f83
commit f2e51dee81
4 changed files with 1 additions and 96 deletions

View File

@@ -1,29 +0,0 @@
"use strict";
async function connect() {
const port = await navigator.serial.requestPort();
// - Wait for the port to open.
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;
}
}
}

View File

@@ -1,47 +0,0 @@
async function connect(){
const port = await navigator.serial.requestPort();
// - Wait for the port to open.
await port.open({ baudRate: 9600 });
let decoder = new TextDecoderStream();
const inputDone = port.readable.pipeTo(decoder.writable);
const inputStream = decoder.readable;
let reader = inputStream.getReader();
const encoder = new TextEncoderStream();
const outputDone = encoder.readable.pipeTo(port.writable);
const outputStream = encoder.writable;
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;
}
}
}
await function writeToStream(){
// CODELAB: Write to output stream
const writer = outputStream.getWriter();
lines.forEach((line) => {
console.log('[SEND]', line);
writer.write(line + '\n');
});
writer.releaseLock();
}

View File

@@ -1,6 +1,6 @@
let port;
async function bwa() {
async function start() {
port = createSerial();
port.open(9600);