forked from serialport/electron-serialport
-
Notifications
You must be signed in to change notification settings - Fork 0
/
renderer.js
28 lines (24 loc) · 865 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
// 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 createTable = require('data-table')
serialport.list((err, ports) => {
console.log('ports', ports);
if (err) {
document.getElementById('error').textContent = err.message
return
} else {
document.getElementById('error').textContent = ''
}
if (ports.length === 0) {
document.getElementById('error').textContent = 'No ports discovered'
}
const headers = Object.keys(ports[0])
const table = createTable(headers)
tableHTML = ''
table.on('data', data => tableHTML += data)
table.on('end', () => document.getElementById('ports').innerHTML = tableHTML)
ports.forEach(port => table.write(port))
table.end();
})