-
Notifications
You must be signed in to change notification settings - Fork 4
/
serial.html
115 lines (107 loc) · 3.71 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<!DOCTYPE html>
<head>
<script src="xpwLib.js"></script>
</head>
<body>
<script>
function clickColor(event)
{
event = event || window.event; // handle IE issues
var target = event.target || event.srcElement; // more IE issues
var xmlhttp;
var lineSelect = document.getElementById("lineSelector");
xpw.serialTransmit({line: lineSelect.value,
message: target.style.getPropertyValue('background-color')+"\r\n"});
}
function updateData()
{
var lineSelect = document.getElementById("lineSelector");
var textBox = document.getElementById("textBox");
xpw.serialReceive( {line: lineSelect.value,
async: false,
done: function(data) {
if (data.success) {
textBox.textContent = textBox.textContent+data.message;
}
setTimeout(function(){updateData();}, 1000);
}
});
}
function updateConfig()
{
var lineSelect = document.getElementById("lineSelector");
xpw.getLineConfig({line:lineSelect.value,
done: function(data) {
if (data.success) {
console.log(data.lineConfig);
document.getElementById("lineProtocol").textContent = data.lineConfig["Protocol"];
document.getElementById("lineBaudRate").textContent = data.lineConfig["Baud Rate"];
if(data.lineConfig.Protocol != "None") {
xpw.setLineConfig({line:lineSelect.value,
items: {Protocol: "None"},
done: function(data) {
if(data.success)
updateConfig();
}
});
}
}
}
});
}
window.onload = function() {
updateConfig();
updateData();
};
</script>
<div style="margin:auto;width:800px;">
Selecting a serial port will automatically change the Protocol to None to enable the WebToSerial function<br/>
<table style="margin:auto;width:400px">
<tr>
<th>Serial port</th>
<th>Protocol</th>
<th>Baud Rate</th>
</tr>
<tr>
<td>
<select id="lineSelector" onchange="updateConfig();">
<option>1</option>
<option>2</option>
<option>CDC_ACM</option>
</select>
</td>
<td id="lineProtocol"></td>
<td id="lineBaudRate"></td>
</tr>
</table>
</div>
<hr />
<div style="float:left;width:50%;">
<h3 style="margin:auto;width:340px;">
Click a color to send it to the serial port
</h3>
<div style="margin:auto;width:250px;">
<div style="background-color:aqua;" onclick="clickColor(event)"> </div>
<div style="background-color:black;" onclick="clickColor(event)"> </div>
<div style="background-color:blue;" onclick="clickColor(event)"> </div>
<div style="background-color:fuchsia;" onclick="clickColor(event)"> </div>
<div style="background-color:gray;" onclick="clickColor(event)"> </div>
<div style="background-color:green;" onclick="clickColor(event)"> </div>
<div style="background-color:lime;" onclick="clickColor(event)"> </div>
<div style="background-color:maroon;" onclick="clickColor(event)"> </div>
<div style="background-color:navy;" onclick="clickColor(event)"> </div>
<div style="background-color:olive;" onclick="clickColor(event)"> </div>
<div style="background-color:purple;" onclick="clickColor(event)"> </div>
<div style="background-color:red;" onclick="clickColor(event)"> </div>
<div style="background-color:silver;" onclick="clickColor(event)"> </div>
<div style="background-color:teal;" onclick="clickColor(event)"> </div>
<div style="background-color:white;" onclick="clickColor(event)"> </div>
<div style="background-color:yellow;" onclick="clickColor(event)"> </div>
</div>
</div>
<div style="float:left;width:50%;">
Data from the serial port (updated once per second):
<div style="color:white;background-color:gray;width=400px;height=400px;overflow:scroll;"
id="textBox"> </div>
</div>
</body>