-
Notifications
You must be signed in to change notification settings - Fork 0
/
renderer.js
36 lines (29 loc) · 983 Bytes
/
renderer.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
// This file is required by the index.html file and will
// be executed in the renderer process for that window.
// All of the Node.js APIs are available in this process.
const { SerialPort } = require('serialport')
const tableify = require('tableify')
async function listSerialPorts() {
await SerialPort.list().then((ports, err) => {
if(err) {
document.getElementById('error').textContent = err.message
return
} else {
document.getElementById('error').textContent = ''
}
console.log('ports', ports);
if (ports.length === 0) {
document.getElementById('error').textContent = 'No ports discovered'
}
tableHTML = tableify(ports)
document.getElementById('ports').innerHTML = tableHTML
})
}
function listPorts() {
listSerialPorts();
setTimeout(listPorts, 2000);
}
// Set a timeout that will check for new serialPorts every 2 seconds.
// This timeout reschedules itself.
setTimeout(listPorts, 2000);
listSerialPorts()