{"record":{"id":"ef169565a713f527","repo":"arduino/Arduino","slug":"serial-port-0-not-found-did-you-select-the","errorCode":null,"errorMessage":"Serial port ''{0}'' not found. Did you select the right one from the Tools > Serial Port menu?","messagePattern":"Serial port ''(.+?)'' not found\\. Did you select the right one from the Tools > Serial Port menu\\?","errorType":"exception","errorClass":"SerialNotFoundException","httpStatus":null,"severity":"error","filePath":"arduino-core/src/processing/app/Serial.java","lineNumber":156,"sourceCode":"\n    try {\n      port = new SerialPort(iname);\n      port.openPort();\n      boolean res = port.setParams(irate, idatabits, stopbits, parity, setRTS, setDTR);\n      if (!res) {\n        System.err.println(format(tr(\"Error while setting serial port parameters: {0} {1} {2} {3}\"),\n                                  irate, iparity, idatabits, istopbits));\n      }\n      port.addEventListener(this);\n    } catch (SerialPortException e) {\n      if (e.getPortName().startsWith(\"/dev\") && SerialPortException.TYPE_PERMISSION_DENIED.equals(e.getExceptionType())) {\n        throw new SerialException(format(tr(\"Error opening serial port ''{0}''. Try consulting the documentation at http://playground.arduino.cc/Linux/All#Permission\"), iname));\n      }\n      throw new SerialException(format(tr(\"Error opening serial port ''{0}''.\"), iname), e);\n    }\n\n    if (port == null) {\n      throw new SerialNotFoundException(format(tr(\"Serial port ''{0}'' not found. Did you select the right one from the Tools > Serial Port menu?\"), iname));\n    }\n  }\n\n  public void setup() {\n    //parent.registerCall(this, DISPOSE);\n  }\n\n  public void dispose() throws IOException {\n    if (port != null) {\n      try {\n        if (port.isOpened()) {\n          port.closePort();  // close the port\n        }\n      } catch (SerialPortException e) {\n        throw new IOException(e);\n      } finally {\n        port = null;\n      }","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/arduino/Arduino/blob/a0df6e0e83b652c72bc78b0a1376c54d6ebc3bee/arduino-core/src/processing/app/Serial.java#L138-L174","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Re-open Tools > Serial Port and select the actual current port","Check the device exists (ls /dev/tty* or Device Manager) before opening","Refresh the port list; replug the board","Catch SerialNotFoundException and prompt the user to pick a valid port"],"exampleFix":"// before\nserialPort = new Serial(\"COM7\");\n// after\nif (Arrays.asList(Serial.list()).contains(\"COM7\")) {\n  serialPort = new Serial(\"COM7\");\n} else {\n  System.err.println(\"COM7 not available; available: \" + Arrays.toString(Serial.list()));\n}","handlingStrategy":"validation","validationCode":"if (!Arrays.asList(Serial.list()).contains(portName)) {\n  throw new IllegalArgumentException(\"Port not present: \" + portName);\n}","typeGuard":"static boolean portExists(String name) {\n  return name != null && Arrays.asList(Serial.list()).contains(name);\n}","tryCatchPattern":"try {\n  serialPort = new Serial(portName);\n} catch (SerialNotFoundException e) {\n  String[] avail = Serial.list();\n  System.err.println(portName + \" missing; available: \" + Arrays.toString(avail));\n}","preventionTips":["Refresh Serial.list() right before opening — ports change on replug","Never hard-code COM numbers; pick from the current list","Confirm the board is powered and enumerated before connecting","Persist a default only after confirming the port existed"],"tags":["serial","device-not-found","arduino"],"backgroundTag":"resource-not-found","analyzedSha":"a0df6e0e83b652c72bc78b0a1376c54d6ebc3bee","analyzedAt":"2026-09-06T10:13:38.901Z","contentChangedAt":"2026-09-06T10:13:38.901Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}