jsonstein@masto.deoan.org ("Jeff Sonstein") wrote:
import std.stdio;
import std.file;
import std.path;
import std.string;void main() {
writeln("Scanning for connected USB serial devices on macOS...");
writeln("=====================================================");
string devPath = "/dev";
uint foundCount = 0;
try {
// Guard against an empty or missing /dev directory
if( !exists( devPath ) || !isDir( devPath ) ) {
stderr.writeln( "Error: /dev directory not found." );
return;
}
else {
// Iterate through all entries in /dev (shallow scan, no recursion)
foreach( DirEntry entry; dirEntries( devPath, SpanMode.shallow ) ) {
// Extract just the filename (e.g., "tty.SLAB_USBtoUART")
string name = baseName( entry.name );
// Filter for common macOS USB-to-Serial naming conventions:
// - tty.SLAB_ : Silicon Labs (Yaesu FT-991a)
// - tty.usb : Generic USB-to-serial bridges (FTDI, Prolific, CH340)
// - tty.uart : Built-in or external UART lines
if( name.startsWith( "tty.SLAB_" ) || name.startsWith( "tty.usb" ) || name.startsWith( "tty.uart" ) ) {
writefln( "Found Device: %s", entry.name );
foundCount++;
}
}
if( foundCount == 0 ) {
writeln( "No matching USB serial devices found. Is the radio turned on and plugged in?" );
}
else {
writefln( "\nScan complete. Total devices found: %d", foundCount );
}
}
}
catch( FileException e ) {
stderr.writeln( "Failed to scan directory: ", e.msg );
}
}