Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port List could display product name #34

Open
vanevery opened this issue Sep 27, 2016 · 1 comment
Open

Port List could display product name #34

vanevery opened this issue Sep 27, 2016 · 1 comment

Comments

@vanevery
Copy link
Member

from @tigoe

Attached is a kluge for getting port's board name.

A real version could look for the user’s ~/Library/Arduino15/packages, and in each package folder keep looking for boards.txt files, and take any line with .pid in it and pull the pid for comparison.

But this will get the names for now.

ListPorts.js

/*
Lists serial ports.
Copied from https://github.com/voodootikigod/node-serialport readme

refactored to get rid of anonymous functions, to make it clearer for
those new to JavaScript
*/

var pids = [{productName : 'Yún', productId : 0x0041},
{productName : 'Yún', productId : 0x8041},
{productName : 'Yún', productId : 0x0041},
{productName : 'Yún', productId : 0x8041},
{productName : 'Uno', productId : 0x0043},
{productName : 'Uno', productId : 0x0001},
{productName : 'Uno', productId : 0x0043},
{productName : 'Uno', productId : 0x0243},
{productName : 'Mega', productId : 0x0010},
{productName : 'Mega', productId : 0x0042},
{productName : 'Mega', productId : 0x0010},
{productName : 'Mega', productId : 0x0042},
{productName : 'Mega', productId : 0x0210},
{productName : 'Mega', productId : 0x0242},
{productName : 'Mega ADK', productId : 0x003f},
{productName : 'Mega ADK', productId : 0x0044},
{productName : 'Mega ADK', productId : 0x003f},
{productName : 'Mega ADK', productId : 0x0044},
{productName : 'Leonardo', productId : 0x0036},
{productName : 'Leonardo', productId : 0x8036},
{productName : 'Leonardo', productId : 0x0036},
{productName : 'Leonardo', productId : 0x8036},
{productName : 'Micro', productId : 0x0037},
{productName : 'Micro', productId : 0x8037},
{productName : 'Micro', productId : 0x0037},
{productName : 'Micro', productId : 0x8037},
{productName : 'Micro', productId : 0x0237},
{productName : 'Micro', productId : 0x8237},
{productName : 'Esplora', productId : 0x003C},
{productName : 'Esplora', productId : 0x803C},
{productName : 'Esplora', productId : 0x003C},
{productName : 'Esplora', productId : 0x803C},
{productName : 'LilyPad USB', productId : 0x9207},
{productName : 'LilyPad USB', productId : 0x9208},
{productName : 'Robot Control Board', productId : 0x0038},
{productName : 'Robot Control Board', productId : 0x8038},
{productName : 'Robot Control Board', productId : 0x0038},
{productName : 'Robot Control Board', productId : 0x8038},
{productName : 'Robot Motor Board', productId : 0x0039},
{productName : 'Robot Motor Board', productId : 0x8039},
{productName : 'Robot Motor Board', productId : 0x0039},
{productName : 'Robot Motor Board', productId : 0x8039},
{productName : 'Gemma', productId : 0x0c9f},
{productName : 'Arduino Zero (Programming Port)', productId : 0x2157},
{productName : 'Arduino Zero native', productId : 0x804d},
{productName : 'Arduino Zero native', productId : 0x004d},
{productName : 'Arduino Zero native', productId : 0x824d},
{productName : 'Arduino Zero native', productId : 0x024d},
{productName : 'MKR1000', productId : 0x804e},
{productName : 'MKR1000', productId : 0x004e},
{productName : 'MKR1000', productId : 0x824e},
{productName : 'MKR1000', productId : 0x024e},
{productName : 'Arduino 101', productId : 0x0AB6},
{productName : 'Flora8', productId : 0x8004},
{productName : 'Bluefruit Micro', productId : 0x800A},
{productName : 'Feather 32u4', productId : 0x800C},
{productName : 'Adafruit 32u4', productId : 0x8001},
{productName : 'Circuit Playground 32u4 cat', productId : 0x8011},
{productName : 'Adafruit feather M0', productId : 0x800B},
{productName : 'Adafruit feather M0', productId : 0x000B},
{productName : '#Adafruit radio M0', productId : 0x8014},
{productName : '#Adafruit radio M0', productId : 0x0014},
{productName : '#Adafruit metro M0', productId : 0x8013},
{productName : '#Adafruit metro M0', productId : 0x0013},
{productName : 'Blend', productId : 0x0036},
{productName : 'Blend', productId : 0x8036},
{productName : 'Blend Micro 8', productId : 0x2404},
{productName : 'Blend Micro 16', productId : 0x2404}];

var serialport = require("serialport");
var myName = "unknown";
// list serial ports:
serialport.list(listPorts);

function listPorts(error, ports) {
ports.forEach(printPort);

function printPort(port) {
    for (p in pids) {
        if (pids[p].productId == port.productId) {
            myName = pids[p].productName;
        }
    }
    console.log(port.comName + "\t" + port.manufacturer + "\t" + port.productId  + "\t" + myName );
}

}

@tigoe
Copy link
Contributor

tigoe commented Sep 27, 2016

Here's an updated version. I suggest putting the PID/VID array in its own document, but I don't know how you'd like to organize things. Also, I recommend listing manufacturer name when you list, so that if the device type isn't in this array, at least the user can know the vendor and guess at the device from there.

There's probably a way to pull product name using the PID from USB.org, but I don't know how.

/*
Lists serial ports.
Copied from https://github.com/voodootikigod/node-serialport readme

refactored to get rid of anonymous functions, to make it clearer for
those new to JavaScript
*/

var pids = [{productName : 'Yún',  productId : 0x0041, vendorId : 0x2341}, // Arduino
{productName : 'Yún',  productId : 0x8041, vendorId : 0x2341},
{productName : 'Yún',  productId : 0x0041, vendorId : 0x2341},
{productName : 'Yún',  productId : 0x8041, vendorId : 0x2341},
{productName : 'Uno',  productId : 0x0043, vendorId : 0x2341},
{productName : 'Uno',  productId : 0x0001, vendorId : 0x2341},
{productName : 'Uno',  productId : 0x0043, vendorId : 0x2341},
{productName : 'Uno',  productId : 0x0243, vendorId : 0x2341},
{productName : 'Mega',  productId : 0x0010, vendorId : 0x2341},
{productName : 'Mega',  productId : 0x0042, vendorId : 0x2341},
{productName : 'Mega',  productId : 0x0010, vendorId : 0x2341},
{productName : 'Mega',  productId : 0x0042, vendorId : 0x2341},
{productName : 'Mega',  productId : 0x0210, vendorId : 0x2341},
{productName : 'Mega',  productId : 0x0242, vendorId : 0x2341},
{productName : 'Mega ADK',  productId : 0x003f, vendorId : 0x2341},
{productName : 'Mega ADK',  productId : 0x0044, vendorId : 0x2341},
{productName : 'Mega ADK',  productId : 0x003f, vendorId : 0x2341},
{productName : 'Mega ADK',  productId : 0x0044, vendorId : 0x2341},
{productName : 'Leonardo',  productId : 0x0036, vendorId : 0x2341},
{productName : 'Leonardo',  productId : 0x8036, vendorId : 0x2341},
{productName : 'Leonardo',  productId : 0x0036, vendorId : 0x2341},
{productName : 'Leonardo',  productId : 0x8036, vendorId : 0x2341},
{productName : 'Micro',  productId : 0x0037, vendorId : 0x2341},
{productName : 'Micro',  productId : 0x8037, vendorId : 0x2341},
{productName : 'Micro',  productId : 0x0037, vendorId : 0x2341},
{productName : 'Micro',  productId : 0x8037, vendorId : 0x2341},
{productName : 'Micro',  productId : 0x0237, vendorId : 0x2341},
{productName : 'Micro',  productId : 0x8237, vendorId : 0x2341},
{productName : 'Esplora',  productId : 0x003C, vendorId : 0x2341},
{productName : 'Esplora',  productId : 0x803C, vendorId : 0x2341},
{productName : 'Esplora',  productId : 0x003C, vendorId : 0x2341},
{productName : 'Esplora',  productId : 0x803C, vendorId : 0x2341},
{productName : 'LilyPad USB',  productId : 0x9207, vendorId : 0x2341},
{productName : 'LilyPad USB',  productId : 0x9208, vendorId : 0x2341},
{productName : 'Robot Control Board',  productId : 0x0038, vendorId : 0x2341},
{productName : 'Robot Control Board',  productId : 0x8038, vendorId : 0x2341},
{productName : 'Robot Control Board',  productId : 0x0038, vendorId : 0x2341},
{productName : 'Robot Control Board',  productId : 0x8038, vendorId : 0x2341},
{productName : 'Robot Motor Board',  productId : 0x0039, vendorId : 0x2341},
{productName : 'Robot Motor Board',  productId : 0x8039, vendorId : 0x2341},
{productName : 'Robot Motor Board',  productId : 0x0039, vendorId : 0x2341},
{productName : 'Robot Motor Board',  productId : 0x8039, vendorId : 0x2341},
{productName : 'Due Native USB',  productId : 0x003d, vendorId : 0x2341},
{productName : 'Due (Programming Port)',  productId : 0x003e, vendorId : 0x2341},
{productName : 'Gemma',  productId : 0x0c9f, vendorId : 0x2341},
{productName : 'Arduino Zero (Programming Port)',  productId : 0x2157, vendorId : 0x2341},
{productName : 'Arduino Zero native',  productId : 0x804d, vendorId : 0x2341},
{productName : 'Arduino Zero native',  productId : 0x004d, vendorId : 0x2341},
{productName : 'Arduino Zero native',  productId : 0x824d, vendorId : 0x2341},
{productName : 'Arduino Zero native',  productId : 0x024d, vendorId : 0x2341},
{productName : 'MKR1000',  productId : 0x804e, vendorId : 0x2341},
{productName : 'MKR1000',  productId : 0x004e, vendorId : 0x2341},
{productName : 'MKR1000',  productId : 0x824e, vendorId : 0x2341},
{productName : 'MKR1000',  productId : 0x024e, vendorId : 0x2341},
{productName : 'Arduino 101',  productId : 0x0AB6, vendorId: 0x8087},  // Intel
{productName : 'Flora8',  productId : 0x8004, vendorId: 0x239a},  // Adafruit
{productName : 'Bluefruit Micro',  productId : 0x800A, vendorId: 0x239a},
{productName : 'Feather 32u4',  productId : 0x800C, vendorId: 0x239a},
{productName : 'Adafruit 32u4',  productId : 0x8001, vendorId: 0x239a},
{productName : 'Circuit Playground 32u4 cat',  productId : 0x8011, vendorId: 0x239a},
{productName : 'Adafruit feather M0',  productId : 0x800B, vendorId: 0x239a},
{productName : 'Adafruit feather M0',  productId : 0x000B, vendorId: 0x239a},
{productName : '#Adafruit radio M0',  productId : 0x8014, vendorId: 0x239a},
{productName : '#Adafruit radio M0',  productId : 0x0014, vendorId: 0x239a},
{productName : '#Adafruit metro M0',  productId : 0x8013, vendorId: 0x239a},
{productName : '#Adafruit metro M0',  productId : 0x0013, vendorId: 0x239a},
{productName : 'Blend',  productId : 0x0036, vendorId: 0x2b04},   // RedBer
{productName : 'Blend',  productId : 0x8036, vendorId: 0x2b04},
{productName : 'Blend Micro 8',  productId : 0x2404, vendorId: 0x2b04},
{productName : 'Blend Micro 16',  productId : 0x2404, vendorId: 0x2b04},
{productName : 'RedBear Duo',  productId : 0xc058, vendorId: 0x2b04},
{productName : 'BBC MicroBit',  productId : 0x0204, vendorId: 0x0d28},   // MBED
{productName : 'Particle',  productId : 0xc006, vendorId: 0x2b04},          // Particle.io (Spark Devices)
{productName : 'BeagleBone Black',  productId : 0x0104, vendorId: 0x1d6b},  // CircuitCo
{productName : 'Espruino',  productId : 0x5740, vendorId: 0x0483}           // ST Micro
]

var serialport = require("serialport");
var myName = "unknown";
// list serial ports:
serialport.list(listPorts);

function listPorts(error, ports) {
    ports.forEach(printPort);

    function printPort(port) {
        for (p in pids) {
            if (pids[p].productId == port.productId && port.vendorId == pids[p].vendorId) {
                myName = pids[p].productName;
            }
        }
        console.log(port.comName + "\t" + port.manufacturer + "\t" + port.vendorId  + "\t" + port.productId  + "\t" + myName );
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants