Implemented auto port detection
This commit is contained in:
@@ -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.")]
|
||||
|
12
src/main.rs
12
src/main.rs
@@ -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),
|
||||
|
Reference in New Issue
Block a user