Skip to content

Commit 1763b53

Browse files
committed
fix: Filter serial ports on Linux to show only USB devices (Issue #5)
On Linux, the port list now only shows /dev/ttyUSB* and /dev/ttyACM* devices, filtering out system TTY devices that clutter the dropdown. This is platform-specific - Windows and macOS are unaffected and continue to show all available ports. Fixes #5
1 parent 649c6a4 commit 1763b53

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

src/connection/serial.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,31 @@ impl SerialConnection {
8686
///
8787
/// # Returns
8888
/// Vector of available serial port information
89+
///
90+
/// On Linux, only returns USB serial ports (/dev/ttyUSB* or /dev/ttyACM*)
91+
/// to avoid showing system TTY devices. On other platforms, returns all ports.
8992
pub fn list_ports() -> Result<Vec<SerialPortInfo>> {
90-
serialport::available_ports().map_err(|e| Error::Connection(e.to_string()))
93+
let all_ports = serialport::available_ports()
94+
.map_err(|e| Error::Connection(e.to_string()))?;
95+
96+
// On Linux, filter to only show USB serial ports (Issue #5)
97+
#[cfg(target_os = "linux")]
98+
{
99+
let filtered_ports: Vec<SerialPortInfo> = all_ports
100+
.into_iter()
101+
.filter(|port| {
102+
let port_name = &port.port_name;
103+
port_name.starts_with("/dev/ttyUSB") || port_name.starts_with("/dev/ttyACM")
104+
})
105+
.collect();
106+
Ok(filtered_ports)
107+
}
108+
109+
// On other platforms (Windows, macOS), return all ports
110+
#[cfg(not(target_os = "linux"))]
111+
{
112+
Ok(all_ports)
113+
}
91114
}
92115

93116
/// Get the current configuration

0 commit comments

Comments
 (0)