getAvailablePorts static method

List<String> getAvailablePorts()

read Registry in Windows to get ports getAvailablePorts can be called using SerialPort.getAvailablePorts()

Implementation

static List<String> getAvailablePorts() {
  /// availablePorts String list
  List<String> portsList = [];
  final int hKey;

  /// Get registry key of Serial Port
  try {
    hKey = _getRegistryKeyValue();
  } on Exception {
    return List.empty();
  }

  /// The index of the value to be retrieved.
  /// This parameter should be zero for the first call to the RegEnumValue function and then be incremented for subsequent calls.
  int dwIndex = 0;

  String? item;
  item = _enumerateKey(hKey, dwIndex);
  if (item == null) {
    portsList.add('');
  }

  while (item != null) {
    portsList.add(item);
    dwIndex++;
    item = _enumerateKey(hKey, dwIndex);
  }

  RegCloseKey(hKey);

  return portsList;
}