Open DavesCodeMusings opened 5 months ago
Old code dug out of commit history is below. This was prior to the context menu-based system the extension uses now, but it does give an example of how to parse mpremote devs
output.
async function getDevicePort() {
return new Promise((resolve, reject) => {
let port = ''
let deviceList = childProcess.execSync('py -m mpremote devs').toString().split('\r\n')
if (deviceList == null || deviceList.length == 0) {
reject('')
}
if (deviceList[deviceList.length - 1] == '') {
deviceList.pop()
}
console.debug('Attached devices:', deviceList)
if (deviceList.length == 1) {
port = deviceList[0].split(' ')[0]
console.debug(`Only one device attached: ${port}`)
resolve(port)
}
else {
let options = {
title: 'Device Selection',
canSelectMany: false
}
vscode.window.showQuickPick(deviceList, options)
.then(selection => {
port = selection.split(' ')[0]
console.debug(`User selection is: ${port}`)
resolve(port)
})
}
})
}
In serialportExplorer.ts let comPortList = await SerialPort.list();
needs to be replaced with a function that runs mpremote devs
and parses the output to return an array of port paths (e.g. COM3, /dev/ttyUSB0) at a minimum. Returning an object with more robust information like: port.path, port.manufacturer, and port.serialNumber, port.productId, and port.vendorId, should be possible as well, since this is all returned by mpremote devs
.
For example: COM3 0001 10c4:ea60 Silicon Labs None
equates to port.path port.serialNumber port.vendorId:port.productId port.manufacturer None
. Though what None corresponds to, I don't know.
Raspberry Pi 2 can run VS Code (slowly), but the MPRemote extension does not work. Best guess is there is an incompatibility with the serialport npm package, because enumerating serial ports is the first task in the extension's activate function. Possibly there's x86 specific code in there???
However, the
mpremote devs
command works fine and will detect and enumerate serial ports without a problem.A possible solution is to use a call to
mpremote devs
and then parse the output to determine what serial ports are available. This should make the MPRemote VS Code Extension more cross-platform. The extension was using this method in early revisions, so digging up the old code should be easy.Sample output from
mpremote devs
running on Raspberry Pi: