ali-f 1 month ago
parent c22005c817
commit 96abffe191
  1. 32
      services/serialPortService.js

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

Loading…
Cancel
Save