-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSerial.html
47 lines (41 loc) · 1.35 KB
/
Serial.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Web TTY</title>
<script src="https://cdn.jsdelivr.net/npm/xterm@4.1.0/lib/xterm.js"></script>
<link rel="stylesheet" href='https://cdn.jsdelivr.net/npm/xterm@4.1.0/css/xterm.css'>
</head>
<body>
<div id="terminal" style="width: 500px; height: 500px;"></div>
<script>
async function start() {
const port = await navigator.serial.requestPort({});
await port.open({ baudRate: 115200 });
const reader = port.readable.getReader();
//const writer = port.writable.getWriter();
//writer.write(buffy);
let buffer = '';
while (true) {
const { done, value } = await reader.read();
if (done) break;
const s = new TextDecoder("utf-8").decode(value);
buffer += s;
if (s.endsWith('\r\n') || s.endsWith('\n')) {
console.log(buffer)
buffer = '';
}
}
}
Object.assign(window, {
ptr(v) {
return '0x' + v.toString(16)
}
})
</script>
<button onclick="start()">
<h1>CONNECT</h1>
</button>
</body>
</html>