Implemented auto port detection

This commit is contained in:
2025-09-19 11:14:13 +02:00
parent d298db44d2
commit 1dbbaab197
5 changed files with 129 additions and 13 deletions

View File

@@ -6,8 +6,8 @@ use argp::FromArgs;
#[argp(description = "tulflash - Flashing utility for the TUL Výukový Přípravek v1.1™")]
pub struct Args {
#[argp(option)]
#[argp(description = "Path to the serial port. Probably will be `/dev/ttyUSBx` on Linux, `/dev/tty.usbserial-xxx` on macOS or `COMx` on Windows.")]
pub port: OsString,
#[argp(description = "Path to the serial port if auto detection fails. Probably will be `/dev/ttyUSBx` on Linux, `/dev/tty.usbserial-xxx` on macOS or `COMx` on Windows.")]
pub port: Option<OsString>,
#[argp(switch)]
#[argp(description = "Try this if it does not work the first time.")]

View File

@@ -216,7 +216,17 @@ fn main() {
let start = SystemTime::now();
let mut target = PhysicalTarget::init(args.port, if args.slow { 57600 } else { 312500 }).unwrap();
let port = args.port.or_else(|| {
for port in serial_enumerator::get_serial_list() {
if let Some(vendor) = port.vendor && vendor.as_str() == "TUL" {
return Some(port.name.into())
}
}
None
}).unwrap();
let mut target = PhysicalTarget::init(port, if args.slow { 57600 } else { 312500 }).unwrap();
let res = match args.command {
ArgCommand::Read(args) => read_chip(args, &mut target),