blob: cdc8524e71504564af5dfa8f8dbeaf2629d5e92a (
plain)
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
53
54
55
56
57
58
59
60
61
62
63
64
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content = "height = device-height, width = 420, user-scalable = no" />
<title>WebIOPi | Serial Monitor</title>
<script type="text/javascript" src="/webiopi.js"></script>
<script type="text/javascript">
webiopi().ready(function() {
$("#inputText").keyup(function(event){
if(event.keyCode == 13){
sendData();
}
});
$.get("/devices/*", function(data) {
var devices = $("#devices");
var added = false;
for (i in data) {
if (data[i].type=="Serial") {
added = true;
devices.append($("<option>" + data[i].name + "</option>"))
}
}
if (added) {
readData();
}
});
});
function readData() {
webiopi().Serial($("#devices").val()).read(function(data) {
if (data.length > 0) {
var d = $("#output").text() + data;
$("#output").text(d);
}
});
setTimeout(readData, 500);
}
function sendData() {
var data = $("#inputText").val() + "\n";
webiopi().Serial($("#devices").val()).write(data);
$("#inputText").val("");
}
function deviceChanged() {
$("#output").text("");
}
</script>
<style type="text/css">
#inputText {
width: 550px;
}
</style>
</head>
<body>
<h1>Serial Monitor</h1>
<span>Serial device : </span><select id="devices" onchange="deviceChanged()"></select><br/>
<span>Input : </span><br/>
<textarea id="output" rows="30" cols="100" disabled="disabled"></textarea><br/>
<span>Output : </span><input id="inputText" type="text"/>
</body>
</html>
|