|
|
@ -6,18 +6,26 @@ import { autoDetect } from '@serialport/bindings-cpp' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function serialPortList(req, res) { |
|
|
|
async function serialPortList(req, res) { |
|
|
|
const portList = await SerialPort.list() |
|
|
|
|
|
|
|
console.log(portList) |
|
|
|
SerialPort.list() |
|
|
|
res.send(portList) |
|
|
|
.then((pathsList) => { |
|
|
|
// .then((ports) => {
|
|
|
|
console.log('Available serial ports:'); |
|
|
|
// console.log('Available serial ports:');
|
|
|
|
for (const path of pathsList) { |
|
|
|
// ports.forEach((port) => {
|
|
|
|
const serialport = new SerialPort({ path, baudRate: 9600, autoOpen: false, }, function (err) { |
|
|
|
// console.log(`- ${port.comName} (${port.pnpId})`);
|
|
|
|
if (err) { |
|
|
|
// });
|
|
|
|
return console.log('Error: ', err.message); |
|
|
|
// })
|
|
|
|
} |
|
|
|
// .catch((error) => {
|
|
|
|
}) |
|
|
|
// console.error('Error listing serial ports:', error);
|
|
|
|
|
|
|
|
// });
|
|
|
|
const buff = Buffer.allocUnsafe(4); |
|
|
|
|
|
|
|
buff.writeUInt8(`#0${req.params.id}$`); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
serialport.write(buff) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
.catch((error) => { |
|
|
|
|
|
|
|
console.error('Error listing serial ports:', error); |
|
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async function serialPort(req, res) { |
|
|
|
async function serialPort(req, res) { |
|
|
|