arduino/Arduino · error · SerialNotFoundException

Serial port ''{0}'' not found. Did you select the right one

Error message

Serial port ''{0}'' not found. Did you select the right one from the Tools > Serial Port menu?

What it means

Thrown as SerialNotFoundException when the serial driver object (port) is null after attempting to open the port, meaning jSSC could not locate a port with the given name. The IDE-facing message steers the user back to the Tools > Serial Port menu.

Source

Thrown at arduino-core/src/processing/app/Serial.java:156

    try {
      port = new SerialPort(iname);
      port.openPort();
      boolean res = port.setParams(irate, idatabits, stopbits, parity, setRTS, setDTR);
      if (!res) {
        System.err.println(format(tr("Error while setting serial port parameters: {0} {1} {2} {3}"),
                                  irate, iparity, idatabits, istopbits));
      }
      port.addEventListener(this);
    } catch (SerialPortException e) {
      if (e.getPortName().startsWith("/dev") && SerialPortException.TYPE_PERMISSION_DENIED.equals(e.getExceptionType())) {
        throw new SerialException(format(tr("Error opening serial port ''{0}''. Try consulting the documentation at http://playground.arduino.cc/Linux/All#Permission"), iname));
      }
      throw new SerialException(format(tr("Error opening serial port ''{0}''."), iname), e);
    }

    if (port == null) {
      throw new SerialNotFoundException(format(tr("Serial port ''{0}'' not found. Did you select the right one from the Tools > Serial Port menu?"), iname));
    }
  }

  public void setup() {
    //parent.registerCall(this, DISPOSE);
  }

  public void dispose() throws IOException {
    if (port != null) {
      try {
        if (port.isOpened()) {
          port.closePort();  // close the port
        }
      } catch (SerialPortException e) {
        throw new IOException(e);
      } finally {
        port = null;
      }

View on GitHub (pinned to a0df6e0e83)

Solutions

  1. Re-open Tools > Serial Port and select the actual current port
  2. Check the device exists (ls /dev/tty* or Device Manager) before opening
  3. Refresh the port list; replug the board
  4. Catch SerialNotFoundException and prompt the user to pick a valid port

Example fix

// before
serialPort = new Serial("COM7");
// after
if (Arrays.asList(Serial.list()).contains("COM7")) {
  serialPort = new Serial("COM7");
} else {
  System.err.println("COM7 not available; available: " + Arrays.toString(Serial.list()));
}
Defensive patterns

Strategy: validation

Validate before calling

if (!Arrays.asList(Serial.list()).contains(portName)) {
  throw new IllegalArgumentException("Port not present: " + portName);
}

Type guard

static boolean portExists(String name) {
  return name != null && Arrays.asList(Serial.list()).contains(name);
}

Try / catch

try {
  serialPort = new Serial(portName);
} catch (SerialNotFoundException e) {
  String[] avail = Serial.list();
  System.err.println(portName + " missing; available: " + Arrays.toString(avail));
}

Prevention

When it happens

Trigger: Constructing/opening Serial with a port name that does not exist on the system (typo, stale COM port number, device unplugged), so portOpen succeeds in returning a null/invalid handle.

Common situations: Sketch launched with a saved preference pointing at a port that no longer exists; USB adapter enumerated under a new name; board unplugged between listing and opening.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of arduino/Arduino@a0df6e0e83 (2026-09-06). Data as JSON: /api/errors/ef169565a713f527. Report an issue: GitHub.