Automatic connection to device with new Serial Library?

edited May 2017 in Arduino

Hello, wondering if it is possible to read any of the lower-level USB device information from a USB serial device with Processing? For example, hardware ID's (VID, PID) or 'Bus reported device description', etc?

For my application, I would like to be able to plug in my USB serial device (Arduino, for example) and click one button to connect to it, or scan the ports and automatically connect when my app sees the device is plugged in. Of course, the challenge is that you don't always know which port it comes up as, and ports are assigned depending on the order they are plugged in, which is why I would like to look for something specific to the actual USB device.

Does the new serial library have any features that might make this possible?

Any other pointers or examples for doing this?

Thank you!



  • Looks like the Arduino developers may have solved this:

    But it looks like they are still using RXTX for their Serial library.

    Any thoughts on how to implement something similar with the new processing serial library?

  • Answer ✓

    Hi Josh,

    Which operating system are you using?

    In the process of writing the new serial library, I implemented exactly what you're describing - but we're currently not advertising it, since it's still lacking support for Windows, but if you're on OS X or Linux, let us know how if it works!

    The interface isn't set in stone yet, but here is how to use it on 2.1.1:

    import processing.serial.*;
    import java.util.Map;
    void setup() {
      String[] ports = Serial.list();
      for (int i=0; i < ports.length; i++) {
        Map<String, String> props = Serial.getProperties(ports[i]);
        print(ports[i]+": ");

    This should return more than an empty map for each USB-attached peripheral, and you should be able to iterate through the properties, and e.g. look for the USB PID and open a particular port etc. (I don't have any such devices at hand, but I can post a more complete code example later if needed.)


  • Gohai! Thank you so much for the reply. I am currently using Win7-64bit, but would like to make a cross-platform app eventually anyway. I'll try the what you suggested in OSX, and I would love to see a more complete example later. Good work on this library!

  • Gohai - I just wanted to check in to see if there has been any progress on adding the ".getProperties" function to the Windows version of Processing? You OS X example above works great! Thank you once again.

  • edited September 2014

    In the process of writing the new serial library, I implemented exactly what you're describing

    Outta curiosity, I've peeked at Serial.getProperties() and found out that it in turn invokes an unknown SerialPortList.getPortProperties() method, which is even absent from a very recent "jssc-2.8.0-sources.jar" library source!

    That, plus SerialPortList.getLinuxPortProperties() & SerialPortList.getNativePortProperties(), are an addendum to jssc lib!
    But there's no explanation about their author or which exactly jssc version it's forking from! @-)

    Anyways, here's a shorter @gohai's version: <):)

    // automatic-connection-to-device-with-new-serial-library
    import processing.serial.Serial;
    void setup() {
      for (String port: Serial.list()) {
        println('\n' + port + ':');
  • edited November 2014

    comment removed

  • Please post under Share Your Work

Sign In or Register to comment.