SerialportAccess serial ports with JavaScript. Examples below describe how you can use node-serialport library in your projects.
Listing all available serialports
import * as serial from 'serialport';
serial.list().then((list) => {
list.map((port)=>{
console.log(`COM name: ${port.comName}, Manufacturer : ${port.manufacturer}`)
});
}).catch(console.error);
Result
Listing all available ports in DOM
import * as serial from 'serialport';
serial.list().then((list) => {
list.map((port) => {
console.log(`COM name: ${port.comName}, Manufacturer : ${port.manufacturer}`)
});
}).catch(console.error);
const view = quark.views.createTabsView('Serial ports');
view.onDidConnectElement = async () => {
try {
const list = await serial.list();
let html = '<h1>Available Ports</h1>';
list.map((port) => {
html = html.concat(`<h3>${port.comName}</h3>`);
});
view.element.style.padding = '20px';
view.element.innerHTML = html;
} catch (err) {
console.err(err);
}
}
view.focus();