Serialport library was updated and changed to Promise-based returns from callbacks as was being used in the arduino lib.

This commit is contained in:
mmcwilliams 2019-12-18 17:17:48 -05:00
parent c6ebab4032
commit 4c8c2b66f3
10 changed files with 90 additions and 96 deletions

View File

@ -42,37 +42,37 @@ class Arduino {
* @returns {Promise} Resolves after enumerating
**/
async enumerate() {
return new Promise((resolve, reject) => {
return SerialPort.list((err, ports) => {
let matches = [];
if (err) {
return reject(err);
}
ports.forEach((port) => {
if (this.known.indexOf(port.comName) !== -1) {
matches.push(port.comName);
}
else if ((port.manufacturer + '').toLowerCase().indexOf('arduino') !== -1) {
matches.push(port.comName);
}
else if ((port.comName + '').toLowerCase().indexOf('usbserial') !== -1) {
matches.push(port.comName);
}
else if ((port.comName + '').toLowerCase().indexOf('usbmodem') !== -1) {
matches.push(port.comName);
}
else if ((port.comName + '').toLowerCase().indexOf('ttyusb') !== -1) {
matches.push(port.comName);
}
});
if (matches.length === 0) {
return reject('No USB devices found');
}
else if (matches.length > 0) {
return resolve(matches);
}
});
let ports;
let matches = [];
try {
ports = await SerialPort.list();
}
catch (err) {
throw err;
}
ports.forEach((port) => {
if (this.known.indexOf(port.path) !== -1) {
matches.push(port.path);
}
else if ((port.manufacturer + '').toLowerCase().indexOf('arduino') !== -1) {
matches.push(port.path);
}
else if ((port.path + '').toLowerCase().indexOf('usbserial') !== -1) {
matches.push(port.path);
}
else if ((port.path + '').toLowerCase().indexOf('usbmodem') !== -1) {
matches.push(port.path);
}
else if ((port.path + '').toLowerCase().indexOf('ttyusb') !== -1) {
matches.push(port.path);
}
});
if (matches.length === 0) {
throw new Error('No USB devices found');
}
else if (matches.length > 0) {
return matches;
}
}
/**
* Send a command to an Arduino using async/await

File diff suppressed because one or more lines are too long

View File

@ -427,7 +427,6 @@ class Devices {
this.settings.save();
}
}
;
/**
*
**/
@ -460,7 +459,6 @@ class Devices {
this.ui.send('ready', args);
return true;
}
;
}
module.exports = function (arduino, settings, mainWindow, cam) {
return new Devices(arduino, settings, mainWindow, cam);

File diff suppressed because one or more lines are too long

View File

@ -42,37 +42,37 @@ class Arduino {
* @returns {Promise} Resolves after enumerating
**/
async enumerate() {
return new Promise((resolve, reject) => {
return SerialPort.list((err, ports) => {
let matches = [];
if (err) {
return reject(err);
}
ports.forEach((port) => {
if (this.known.indexOf(port.comName) !== -1) {
matches.push(port.comName);
}
else if ((port.manufacturer + '').toLowerCase().indexOf('arduino') !== -1) {
matches.push(port.comName);
}
else if ((port.comName + '').toLowerCase().indexOf('usbserial') !== -1) {
matches.push(port.comName);
}
else if ((port.comName + '').toLowerCase().indexOf('usbmodem') !== -1) {
matches.push(port.comName);
}
else if ((port.comName + '').toLowerCase().indexOf('ttyusb') !== -1) {
matches.push(port.comName);
}
});
if (matches.length === 0) {
return reject('No USB devices found');
}
else if (matches.length > 0) {
return resolve(matches);
}
});
let ports;
let matches = [];
try {
ports = await SerialPort.list();
}
catch (err) {
throw err;
}
ports.forEach((port) => {
if (this.known.indexOf(port.path) !== -1) {
matches.push(port.path);
}
else if ((port.manufacturer + '').toLowerCase().indexOf('arduino') !== -1) {
matches.push(port.path);
}
else if ((port.path + '').toLowerCase().indexOf('usbserial') !== -1) {
matches.push(port.path);
}
else if ((port.path + '').toLowerCase().indexOf('usbmodem') !== -1) {
matches.push(port.path);
}
else if ((port.path + '').toLowerCase().indexOf('ttyusb') !== -1) {
matches.push(port.path);
}
});
if (matches.length === 0) {
throw new Error('No USB devices found');
}
else if (matches.length > 0) {
return matches;
}
}
/**
* Send a command to an Arduino using async/await

File diff suppressed because one or more lines are too long

View File

@ -427,7 +427,6 @@ class Devices {
this.settings.save();
}
}
;
/**
*
**/
@ -460,7 +459,6 @@ class Devices {
this.ui.send('ready', args);
return true;
}
;
}
module.exports = function (arduino, settings, mainWindow, cam) {
return new Devices(arduino, settings, mainWindow, cam);

File diff suppressed because one or more lines are too long

View File

@ -52,32 +52,31 @@ class Arduino {
* @returns {Promise} Resolves after enumerating
**/
async enumerate () {
return new Promise( (resolve, reject) => {
return SerialPort.list((err : any, ports : any[]) => {
let matches : string[] = []
if (err) {
return reject(err)
}
ports.forEach((port : any) => {
if (this.known.indexOf(port.comName) !== -1) {
matches.push(port.comName)
} else if ((port.manufacturer + '').toLowerCase().indexOf('arduino') !== -1) {
matches.push(port.comName)
} else if ((port.comName + '').toLowerCase().indexOf('usbserial') !== -1) {
matches.push(port.comName)
} else if ((port.comName + '').toLowerCase().indexOf('usbmodem') !== -1) {
matches.push(port.comName)
} else if ((port.comName + '').toLowerCase().indexOf('ttyusb') !== -1) {
matches.push(port.comName)
}
})
if (matches.length === 0) {
return reject('No USB devices found');
} else if (matches.length > 0) {
return resolve(matches)
}
})
let ports : any[]
let matches : string[] = []
try {
ports = await SerialPort.list()
} catch (err) {
throw err
}
ports.forEach((port : any) => {
if (this.known.indexOf(port.path) !== -1) {
matches.push(port.path)
} else if ((port.manufacturer + '').toLowerCase().indexOf('arduino') !== -1) {
matches.push(port.path)
} else if ((port.path + '').toLowerCase().indexOf('usbserial') !== -1) {
matches.push(port.path)
} else if ((port.path + '').toLowerCase().indexOf('usbmodem') !== -1) {
matches.push(port.path)
} else if ((port.path + '').toLowerCase().indexOf('ttyusb') !== -1) {
matches.push(port.path)
}
})
if (matches.length === 0) {
throw new Error('No USB devices found')
} else if (matches.length > 0) {
return matches
}
}
/**

View File

@ -405,7 +405,6 @@ class Devices {
c.intval = this.settings.state.camera.intval
}
return this.ready(p, c, l, cs, ps)
}
/**
@ -427,7 +426,7 @@ class Devices {
this.settings.update('devices', this.settings.state.devices)
this.settings.save()
}
};
}
/**
*
**/
@ -463,7 +462,7 @@ class Devices {
this.ui.send('ready', args)
return true
};
}
/**
*