feat: optimize serial device discovery performance#164
feat: optimize serial device discovery performance#164
Conversation
- Filter COM ports by USB VID/PID before probing, using platform-specific detection (Windows registry, macOS ioreg, Linux sysfs) to skip non-DAQiFi devices without opening serial ports - Reduce probe commands to only GetDeviceInfo (SYSTem:SYSInfoPB?), deferring setup commands (DisableEcho, StopStreaming, etc.) to the connection phase - Shorten discovery timeouts: wake-up 200ms (was 1000ms), response 1000ms (was 4000ms), retry interval 300ms (was 1000ms), max retries 2 (was 3) - Probe filtered candidate ports in parallel via Task.WhenAll Closes #157 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Review Summary by QodoOptimize serial device discovery with USB VID/PID filtering and parallel probing
WalkthroughsDescription• Filter serial ports by USB VID/PID before probing to skip non-DAQiFi devices - Windows registry, macOS ioreg, Linux sysfs platform-specific detection - Keeps ports with unknown USB info as fallback candidates • Reduce discovery timeouts and remove setup commands from probe phase - Wake-up 200ms (was 1s), response 1s (was 4s), retry 300ms (was 1s), max retries 2 (was 3) - Defer DisableEcho, StopStreaming, TurnDeviceOn, SetProtobufStreamFormat to connection phase • Probe filtered candidate ports in parallel using Task.WhenAll • Add comprehensive unit tests for VID/PID filtering and USB detection logic Diagramflowchart LR
A["Get Available Ports"] --> B["Filter Port Names<br/>Exclude Bluetooth/Debug/WLAN"]
B --> C["Detect USB VID/PID<br/>Windows/macOS/Linux"]
C --> D["Filter by DAQiFi VID<br/>0x04D8"]
D --> E["Probe Candidates<br/>in Parallel"]
E --> F["Discovered Devices"]
File Changes1. src/Daqifi.Core/Device/Discovery/SerialPortUsbDetector.cs
|
Code Review by Qodo
1. FilterByUsbVidPid keeps unknown ports
|
| if (usbInfo.Count == 0) | ||
| { | ||
| // VID/PID detection unavailable — probe all ports | ||
| return portList; | ||
| } | ||
|
|
||
| var candidates = new List<string>(); | ||
| foreach (var port in portList) | ||
| { | ||
| if (usbInfo.TryGetValue(port, out var id)) | ||
| { | ||
| // USB info available — only include if VID matches DAQiFi | ||
| if (SerialPortUsbDetector.IsDaqifiVendor(id.VendorId)) | ||
| { | ||
| candidates.Add(port); | ||
| } | ||
| } | ||
| else | ||
| { | ||
| // No USB info for this port — include to be safe | ||
| // (could be a non-USB serial port or detection missed it) | ||
| candidates.Add(port); | ||
| } |
There was a problem hiding this comment.
1. filterbyusbvidpid keeps unknown ports 📎 Requirement gap ⛨ Security
Discovery can still open/probe ports that are not confirmed DAQiFi because unknown ports are retained and an empty USB-info result causes all ports to be probed. This can send SCPI commands to non-DAQiFi devices, violating the requirement to only probe VID/PID-matched ports.
Agent Prompt
## Issue description
`FilterByUsbVidPid` currently allows discovery to probe ports that are not positively identified as DAQiFi by USB VID/PID (and even probes all ports when VID/PID detection returns an empty dictionary). This violates the requirement that discovery must not open/probe non-DAQiFi devices.
## Issue Context
The compliance requirement expects discovery to only probe ports whose USB descriptor matches known DAQiFi VID/PID values.
## Fix Focus Areas
- src/Daqifi.Core/Device/Discovery/SerialDeviceFinder.cs[315-337]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
Use async stdout read with WaitForExit timeout instead of synchronous ReadToEnd() which blocks before the timeout can take effect. Kill the process tree if either times out. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary
0x04D8) before probing, using platform-specific detection (Windows registry, macOSioreg, Linux sysfs) to skip non-DAQiFi devices without opening serial portsGetDeviceInfo(SYSTem:SYSInfoPB?), deferring setup commands to the connection phaseTask.WhenAllCloses #157
Test plan
SerialPortUsbDetector(VID matching, constant consistency withHidDeviceFinder)--discover-serialon real device at/dev/cu.usbmodem101🤖 Generated with Claude Code