-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnect-and-receive-tagdata.html
48 lines (47 loc) · 1.23 KB
/
connect-and-receive-tagdata.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
<html>
<head>
<style>
</style>
</head>
<body>
<script src="https://www.puck-js.com/puck.js"></script>
<script type="text/javascript">
var tagDataAll="";
// Called when we get a line of data - updates the light color
function onLine(v) {
tagDataAll+=v;
document.getElementById("result").value = tagDataAll;
}
// When clicked, connect or disconnect
var connection;
function connectReader() {
if (connection) {
connection.close();
connection = undefined;
}
Puck.connect(function(c) {
if (!c) {
alert("Couldn't connect!");
return;
}
connection = c;
tagDataAll="";
onLine("");
// Handle the data we get back, and call 'onLine'
// whenever we get a line
var buf = "";
connection.write("echo(false);\n");
connection.on("data", function(d) {
onLine(d);
});
});
}
</script>
<div>
<button id="connectreader" onclick="connectReader()">Connect tag reader</button>
<p>
<label for="result">Result of scan</label></p>
<textarea id="result" name="result" rows="20" cols="50" readonly="true"></textarea>
</div>
</body>
</html>