There is a code that should get a list of COM ports, and then go through each port and get the value returned by the device connected to the port
let portsPathes = [];
SerialPort.SerialPort.list().then((ports)=>{
ports.forEach(port=>{
portsPathes.push(port.path);
});
ports.close();
});
let datas = [];
portsPathes.forEach(portPath=>{
let port = new SerialPort.SerialPort({
path: portPath,
baudRate: 9600,
dataBits: 8,
parity: 'none',
stopBits: 1,
flowControl: false
});
//port.close();
//port.setMaxListeners(10000);
//port.pipe(new ReadlineParser.ReadlineParser({delimiter: 'rn'}));
//parser.once('data', data=>{console.log(data);});
});
When executing this code, I get an error
node:internal/process/promises:288
triggerUncaughtException(err, true /* fromPromise */);
^
Error: Opening COM9: Access denied
Emitted 'error' event on SerialPort instance at:
at SerialPort._error (C:Users1Desktopneftandurino-callbacknode_modules
@serialportstreamdistindex.js:78:18)
at C:Users1Desktopneftandurino-callbacknode_modules@serialportstream
distindex.js:111:18
The same thing happens if you transfer the creation of SerialPort to forEach in the SerialPort.list()