getAvailablePorts static method
Returns all serial ports currently available on this device.
The implementation is platform-specific:
- Windows — reads
HKLM\HARDWARE\DEVICEMAP\SERIALCOMMfrom the registry. - Linux — scans
/sys/class/ttyforttyUSB*,ttyACM*,ttyS*entries. - macOS — scans
/dev/cu.*(call-out devices only). - Android — queries connected USB serial devices via the USB Host API
platform channel; returns
usb:-prefixed paths. - Web — returns a single synthetic
"Web Serial Port"entry; opening it shows the browser's native port-picker dialog.
Implementation
static Future<List<SerialPortInfo>> getAvailablePorts() async {
if (kIsWeb) return _scanWeb();
if (Platform.isWindows) {
return _scanWindows();
} else if (Platform.isLinux) {
return _scanLinux();
} else if (Platform.isMacOS) {
return _scanMacOS();
} else if (Platform.isAndroid) {
return _scanAndroid();
}
return [];
}