|
1 | 1 | /* |
2 | 2 | * USBComPort.cpp |
3 | | -* Ver 1.2 |
| 3 | +* Ver 1.3 |
4 | 4 | */ |
5 | 5 |
|
6 | 6 | /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
7 | 7 |
|
8 | | -Copyright (C) 2014-2023 TectroLabs L.L.C. https://tectrolabs.com |
| 8 | +Copyright (C) 2014-2024 TectroLabs L.L.C. https://tectrolabs.com |
9 | 9 |
|
10 | 10 | THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, |
11 | 11 | INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. |
@@ -241,11 +241,12 @@ void USBComPort::clear_comm_err() { |
241 | 241 | * @param int maxPorts - the maximum number of SwiftRNG devices to discover |
242 | 242 | * @param int *actualCount - a pointer to the actual number of SwiftRNG devices found |
243 | 243 | * @param WCHAR *hardwareId - a pointer to SwiftRNG device hardware ID |
| 244 | +* @param WCHAR* serialId - a pointer to SwiftRNG device hardware serial ID |
244 | 245 | * |
245 | 246 | * @return 0 - successful operation, otherwise the error code |
246 | 247 | * |
247 | 248 | */ |
248 | | -void USBComPort::get_connected_ports(int ports[], int maxPorts, int *actualCount, WCHAR *hardwareId) { |
| 249 | +void USBComPort::get_connected_ports(int ports[], int maxPorts, int *actualCount, WCHAR *hardwareId, WCHAR* serialId) { |
249 | 250 |
|
250 | 251 | DWORD devIdx = 0; |
251 | 252 | int foundPortIndex = 0; |
@@ -295,13 +296,22 @@ void USBComPort::get_connected_ports(int ports[], int maxPorts, int *actualCount |
295 | 296 | if (_tcsnicmp(curPortName, _T("COM"), 3) == 0) |
296 | 297 | { |
297 | 298 | TCHAR* src = (TCHAR*)curHardwareId; |
298 | | - int size = (int)_tcsnlen(hardwareId, 80); |
299 | | - |
300 | 299 | if (_tcsnicmp(hardwareId, (TCHAR*)curHardwareId, _tcsnlen(hardwareId, 80)) == 0) { |
301 | | - int nPortNr = _ttoi(curPortName + 3); |
302 | | - if (nPortNr != 0) |
| 300 | + int port_nr = _ttoi(curPortName + 3); |
| 301 | + if (port_nr != 0) |
303 | 302 | { |
304 | | - ports[foundPortIndex++] = nPortNr; |
| 303 | + DEVINST dev_instance_parent_id; |
| 304 | + TCHAR sz_dev_instance_id[MAX_DEVICE_ID_LEN]; |
| 305 | + CONFIGRET status = CM_Get_Parent(&dev_instance_parent_id, devInfoData.DevInst, 0); |
| 306 | + if (status == CR_SUCCESS) |
| 307 | + { |
| 308 | + status = CM_Get_Device_ID(dev_instance_parent_id, sz_dev_instance_id, MAX_DEVICE_ID_LEN, 0); |
| 309 | + if (status == CR_SUCCESS) { |
| 310 | + if (std::wstring(sz_dev_instance_id).find(serialId) != std::string::npos) { |
| 311 | + ports[foundPortIndex++] = port_nr; |
| 312 | + } |
| 313 | + } |
| 314 | + } |
305 | 315 | } |
306 | 316 | } |
307 | 317 |
|
|
0 commit comments