-
Notifications
You must be signed in to change notification settings - Fork 19
/
jsDRO.js
35 lines (27 loc) · 807 Bytes
/
jsDRO.js
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
var ws = null;
function OpenWebsocket(address) {
ws = new WebSocket(address);
ws.onopen = function () {
// ...
document.getElementById("myDRO").textContent = "Connected";
};
ws.onclose = function () {
// ...
};
ws.onerror = function (error) {
console.log('WebSocket Error: ' + error);
};
ws.onmessage = function (event) {
//console.log('ws data:' + event.data);
if (event.data[0] == '{') {
var msg = JSON.parse(event.data);
document.getElementById("myDRO").textContent = msg.axis0.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,');
}
}
}
function CloseWebsocket() {
ws.close();
}
window.onload = function() {
OpenWebsocket('ws://' + document.getElementById("ip").value);
};