Returns a list of serial ports discovered on the system
| 209 | |
| 210 | // Returns a list of serial ports discovered on the system |
| 211 | void SerialIO::enumSerialPorts(std::vector<SerialPortInformation>& serialPorts) { |
| 212 | serialPorts.clear(); |
| 213 | |
| 214 | #ifdef FTDI_D2XX_AVAILABLE |
| 215 | // Add in the FTDI ports detected |
| 216 | DWORD numDevs; |
| 217 | FTDI::FTDIInterface ftdi; |
| 218 | FTDI::FT_STATUS status = ftdi.FT_CreateDeviceInfoList(&numDevs); |
| 219 | if ((status == FTDI::FT_STATUS::FT_OK) && (numDevs)) { |
| 220 | FTDI::FT_DEVICE_LIST_INFO_NODE* devList = (FTDI::FT_DEVICE_LIST_INFO_NODE*)malloc(sizeof(FTDI::FT_DEVICE_LIST_INFO_NODE) * numDevs); |
| 221 | if (devList) { |
| 222 | |
| 223 | status = ftdi.FT_GetDeviceInfoList(devList, &numDevs); |
| 224 | if (status == FTDI::FT_STATUS::FT_OK) { |
| 225 | for (unsigned int index = 0; index < numDevs; index++) { |
| 226 | SerialPortInformation info; |
| 227 | info.instanceID = std::to_wstring(devList[index].LocId); |
| 228 | info.pid = devList[index].ID & 0xFFFF; |
| 229 | info.vid = devList[index].ID >> 16; |
| 230 | quicka2w(devList[index].Description, info.productName); |
| 231 | |
| 232 | // Ensure no duplicate port numbers names |
| 233 | int portIndex = 0; |
| 234 | do { |
| 235 | // Create name |
| 236 | std::string tmp = FTDI_PORT_PREFIX; |
| 237 | if (portIndex) tmp += std::to_string(portIndex) + "-"; |
| 238 | portIndex++; |
| 239 | tmp += std::string(devList[index].SerialNumber); |
| 240 | |
| 241 | // Convert to wide |
| 242 | quicka2w(tmp, info.portName); |
| 243 | |
| 244 | // Finish it |
| 245 | info.portName += L" (" + info.productName + L")"; |
| 246 | info.ftdiIndex = index; |
| 247 | |
| 248 | // Test if one with this name already exists |
| 249 | } while (std::find_if(serialPorts.begin(), serialPorts.end(), [&info](const SerialPortInformation& port)->bool { |
| 250 | return (info.portName == port.portName); |
| 251 | }) != serialPorts.end()); |
| 252 | |
| 253 | // Save |
| 254 | serialPorts.push_back(info); |
| 255 | } |
| 256 | } |
| 257 | free(devList); |
| 258 | } |
| 259 | } |
| 260 | #endif |
| 261 | |
| 262 | |
| 263 | #ifdef _WIN32 |
| 264 | std::vector<GUID> toSearch; |
| 265 | |
| 266 | // Check normal COMPORTS guids |
| 267 | toSearch.push_back(GUID_DEVINTERFACE_COMPORT); |
| 268 |
no test coverage detected