41 std::vector<SerialPortEntry> ports;
43#if defined(MAYAFLUX_PLATFORM_WINDOWS)
45 if (RegOpenKeyExA(HKEY_LOCAL_MACHINE,
"HARDWARE\\DEVICEMAP\\SERIALCOMM", 0, KEY_READ, &key) == ERROR_SUCCESS) {
46 for (DWORD index = 0;; ++index) {
47 char value_name[256] {};
48 DWORD value_name_size =
sizeof(value_name);
50 DWORD data_size =
sizeof(data);
52 const LONG status = RegEnumValueA(key, index, value_name, &value_name_size,
nullptr, &type,
53 reinterpret_cast<LPBYTE
>(data), &data_size);
54 if (status == ERROR_NO_MORE_ITEMS) {
57 if (status != ERROR_SUCCESS || type != REG_SZ) {
60 const std::string port(data, std::find(data, data + data_size,
'\0'));
62 ports.push_back({ .path = port, .name = port });
67#elif defined(MAYAFLUX_PLATFORM_MACOS)
69 for (std::filesystem::directory_iterator entry(
"/dev", ec), end; !ec && entry != end; entry.increment(ec)) {
70 const std::string file = entry->path().filename().string();
71 if (file.starts_with(
"cu.")) {
72 ports.push_back({ .path = entry->path(), .name = file });
76 std::map<std::filesystem::path, std::filesystem::path> stable;
78 for (std::filesystem::directory_iterator entry(
"/dev/serial/by-id", ec), end; !ec && entry != end; entry.increment(ec)) {
79 std::error_code resolve_ec;
80 const auto target = std::filesystem::canonical(entry->path(), resolve_ec);
82 stable[target] = entry->path();
87 for (std::filesystem::directory_iterator entry(
"/dev", ec), end; !ec && entry != end; entry.increment(ec)) {
88 const std::string file = entry->path().filename().string();
89 if (!file.starts_with(
"ttyACM") && !file.starts_with(
"ttyUSB")) {
92 std::error_code resolve_ec;
93 const auto target = std::filesystem::canonical(entry->path(), resolve_ec);
94 const auto link = resolve_ec ? stable.end() : stable.find(target);
95 if (link != stable.end()) {
96 ports.push_back({ .path = link->second, .name = link->second.filename().string() });
98 ports.push_back({ .path = entry->path(), .name = file });