-
Notifications
You must be signed in to change notification settings - Fork 77
/
Copy pathserial-basic.html
52 lines (44 loc) · 1.65 KB
/
serial-basic.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
48
49
50
51
52
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta content="width=device-width, initial-scale=1, shrink-to-fit=no" name="viewport">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
<title>WebSocket Serial</title>
</head>
<body>
<main class="container" role="main">
<h1 class="mt-5">WebSocket Serial</h1>
<form id="form">
<p>Input:</p>
<div class="input-group mb-3">
<input class="form-control" id="input" name="input" placeholder="Input" type="text" value=""/>
<div class="input-group-append">
<button class="btn btn-success" type="submit">Send</button>
</div>
</div>
<p>Output:</p>
<textarea class="form-control" rows="10" id="output" name="output"></textarea>
</form>
<script src="websocket-serial.js"></script>
<script>
const $form = document.getElementById("form");
const $input = document.getElementById("input");
const $output = document.getElementById("output");
const serial = new WebSocketSerial({
url: 'ws://127.0.0.1:12212/serial/DISPLAY',
onMessage: function (message) {
$output.value = $output.value + message;
}
});
$form.onsubmit = function (e) {
serial.send($input.value);
$input.value = '';
e.preventDefault();
}
</script>
</main>
</body>
</html>