-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserial.js
77 lines (67 loc) · 2.04 KB
/
serial.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
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
console.log('THS700 Console');
// var SerialPort = require("serialport").SerialPort;
var com = require("serialport");
T = {}; // global
T.conn = { port: "COM4", baudrate: 9600, databits: 8, stopbits: 1, parity: 'none', parser: com.parsers.raw };
T.msg = 'Error text';
T.ports = [];
$(function () {
$("#dialog-msg").dialog({
// resizable: false,
// height:140,
// modal: true,
// buttons: { Cancel: function() { $( this ).dialog( "close" ) } }
autoOpen: false,
show: { effect: "blind", duration: 500 },
hide: { effect: "explode", duration: 500 }
});
$("#dialog").click(function () {
$("#dialog-msg").text(T.msg).dialog("open")
})
});
// global.setTimeout( function(){
// T.msg = 'setTimeout msg';
// $( "#dialog" ).click();
// console.log('Error: ' + T.msg); } , 1000);
$(function () {
$('#conn-refresh').click(function () {
com.list(function (err, ports) {
if (err) {
T.msg = err;
$("#dialog").click();
console.log('Error: ' + T.msg);
}
else {
T.ports = ports;
ports.forEach(function (port) {
console.log('Ports available:');
console.log(' ' + port.comName + ' - ' + port.pnpId + ' - ' + port.manufacturer);
$('#conn-port').append($('<option>', { value: port.comName }).text(port.comName))
})
}
})
});
$('#conn-refresh').click();
$('#conn-connect').click(function () {
var port = new com.SerialPort(T.conn.port, T.conn, false);
port.open(function () {
T.msg = 'Connected';
$("#dialog").click();
console.log('Error: ' + T.msg);
port.on('error', function (err) {
T.msg = err;
$("#dialog").click();
console.log('Error: ' + err);
});
port.on('data', function (data) { console.log('data: ' + data) });
port.write("ID?\r\n", function (err, results) {
if (err) {
T.msg = err;
$("#dialog").click();
console.log('Error: ' + err);
}
else { console.log('results ' + results) }
})
})
});
});