|
|
|
@ -8,19 +8,24 @@ import { autoDetect } from '@serialport/bindings-cpp' |
|
|
|
|
async function serialPortList(req, res) { |
|
|
|
|
|
|
|
|
|
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) { |
|
|
|
|
.then(async pathsList => { |
|
|
|
|
for (const pathObject of pathsList) { |
|
|
|
|
await new Promise(resolve => { |
|
|
|
|
setTimeout(() => resolve(), 100); |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
const serialPort = new SerialPort({ path: pathObject.path, baudRate: 9600, autoOpen: false, }, function (err) { |
|
|
|
|
if (err) { |
|
|
|
|
return console.log('Error: ', err.message); |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
console.log(111111, serialPort) |
|
|
|
|
|
|
|
|
|
const buff = Buffer.allocUnsafe(4); |
|
|
|
|
buff.writeUInt8(`#0${req.params.id}$`); |
|
|
|
|
|
|
|
|
|
serialport.write(buff) |
|
|
|
|
serialPort.write(buff) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
.catch((error) => { |
|
|
|
|