Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a command to list available serial ports #761

Merged
merged 1 commit into from
Feb 14, 2025

Conversation

AVee
Copy link
Contributor

@AVee AVee commented Feb 11, 2025

This pull request uses the existing logic for finding the serial ports to to create a new 'list-ports' command that just lists the ports that are available, with some additional information. This allows for some additional information when trying to resolve issues when flashing. It also opens some opportunities for scripting, e.g. to flash multiple connected devices from a single script.

By default only the ports that are 'known', that is ports that might be automatically selected are shown. The -a (or --all-ports) flag shows all serial ports available.

Tested on Ubuntu, Windows and OS-X.

Copy link
Member

@SergioGasquez SergioGasquez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! Thanks for your contribution, mostly LGTM only a few details! Did some suscesfull testing:

❯ cargo r -r --bin espflash -- list-ports --name-only
...
/dev/cu.usbserial-1110
/dev/cu.usbserial-1120
/dev/tty.usbserial-1110
/dev/tty.usbserial-1120

❯ cargo r -r --bin espflash -- list-ports
...
/dev/cu.usbserial-1110 Silicon Labs CP2102N USB to UART Bridge Controller [EA60:10C4]
/dev/cu.usbserial-1120 Silicon Labs CP2102N USB to UART Bridge Controller [EA60:10C4]
/dev/tty.usbserial-1110 Silicon Labs CP2102N USB to UART Bridge Controller [EA60:10C4]
/dev/tty.usbserial-1120 Silicon Labs CP2102N USB to UART Bridge Controller [EA60:10C4]

Maybe we could improve the formatting when printing all the details with some separators (- or |) between fields or adding the name of the field being printed (name, manufacturer..) for UsbPorts, but this is a nitpick that can be ignored

Comment on lines 66 to 69
/// List serial ports available for flashing.
///
/// Only lists ports of devices known to be used on development boards. Use
/// -a to show all available ports.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// List serial ports available for flashing.
///
/// Only lists ports of devices known to be used on development boards. Use
/// -a to show all available ports.
/// List serial ports available for flashing.

The -a info is incomplete and its already displayed when using -h/--help

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated, hopefully this is a bit clearer:

List serial ports available for flashing.

The default behavior is to only list ports of devices known to be used on development boards.

Usage: cargo espflash list-ports [OPTIONS]

Options:
  -a, --list-all-ports
          List all available serial ports, instead of just those likely to be development boards.
          Includes non-usb ports such as PCI devices
...

Comment on lines 91 to 94
/// List serial ports available for flashing.
///
/// Only lists ports of devices known to be used on development boards. Use
/// -a to show all available ports.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// List serial ports available for flashing.
///
/// Only lists ports of devices known to be used on development boards. Use
/// -a to show all available ports.
/// List serial ports available for flashing.

The -a info is incomplete and its already displayed when using -h/--help

pub struct ListPortsArgs {
/// List all available serial ports.
#[arg(short, long)]
pub all_ports: bool,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub all_ports: bool,
pub list_all_ports: bool,

To be consistent with the similar arg in ConnectArgs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated this one, but kept the -a short argument, that just feels like the obvious 'all' argument to me.

@AVee
Copy link
Contributor Author

AVee commented Feb 14, 2025

...
/dev/cu.usbserial-1110 Silicon Labs CP2102N USB to UART Bridge Controller [EA60:10C4]
/dev/cu.usbserial-1120 Silicon Labs CP2102N USB to UART Bridge Controller [EA60:10C4]
/dev/tty.usbserial-1110 Silicon Labs CP2102N USB to UART Bridge Controller [EA60:10C4]
/dev/tty.usbserial-1120 Silicon Labs CP2102N USB to UART Bridge Controller [EA60:10C4]


Maybe we could improve the formatting when printing all the details with some separators (`-` or `|`) between fields or adding the name of the field being printed (`name`, manufacturer..) for `UsbPort`s, but this is a nitpick that can be ignored

It does actually have a fixed width first column of 15 characters for the name, but OS-X device names are longer then that. But I could create columns based on the length of the actual content, that would be something like this:

/dev/ttyACM0  Espressif              USB JTAG/serial debug unit             1001:303A
/dev/ttyUSB0  Silicon Labs           CP2102N USB to UART Bridge Controller  EA60:10C4
/dev/ttyUSB1  SimTech, Incorporated  SimTech SIM7080                        9205:1E0E
/dev/ttyUSB2  FTDI                   FT232R USB UART                        6001:0403
/dev/ttyUSB3  Telit                  Telit ME910                            110A:1BC7
/dev/ttyUSB4  Telit                  Telit ME910                            110A:1BC7
/dev/ttyUSB5  Telit                  Telit ME910                            110A:1BC7
/dev/ttyUSB6  SimTech, Incorporated  SimTech SIM7080                        9205:1E0E
/dev/ttyUSB7  SimTech, Incorporated  SimTech SIM7080                        9205:1E0E
/dev/ttyUSB8  SimTech, Incorporated  SimTech SIM7080                        9205:1E0E

Or maybe this looks a bit nicer:

/dev/ttyACM0  1001:303A  Espressif              USB JTAG/serial debug unit             
/dev/ttyUSB0  EA60:10C4  Silicon Labs           CP2102N USB to UART Bridge Controller  
/dev/ttyUSB1  9205:1E0E  SimTech, Incorporated  SimTech SIM7080                        
/dev/ttyUSB2  6001:0403  FTDI                   FT232R USB UART                        
/dev/ttyUSB3  110A:1BC7  Telit                  Telit ME910                            
/dev/ttyUSB4  110A:1BC7  Telit                  Telit ME910                            
/dev/ttyUSB5  110A:1BC7  Telit                  Telit ME910                            
/dev/ttyUSB6  9205:1E0E  SimTech, Incorporated  SimTech SIM7080                        
/dev/ttyUSB7  9205:1E0E  SimTech, Incorporated  SimTech SIM7080                        
/dev/ttyUSB8  9205:1E0E  SimTech, Incorporated  SimTech SIM7080                        

Or maybe the USB ID isn't that interesting here and we should just leave it out?

/dev/ttyACM0  Espressif              USB JTAG/serial debug unit             
/dev/ttyUSB0  Silicon Labs           CP2102N USB to UART Bridge Controller  
/dev/ttyUSB1  SimTech, Incorporated  SimTech SIM7080                        
/dev/ttyUSB2  FTDI                   FT232R USB UART                        
/dev/ttyUSB3  Telit                  Telit ME910                            
/dev/ttyUSB4  Telit                  Telit ME910                            
/dev/ttyUSB5  Telit                  Telit ME910                            
/dev/ttyUSB6  SimTech, Incorporated  SimTech SIM7080                        
/dev/ttyUSB7  SimTech, Incorporated  SimTech SIM7080                        
/dev/ttyUSB8  SimTech, Incorporated  SimTech SIM7080                        

Personallly I like the second one best, it seems the easiest to read to me. And keeping the USB ID might be useful for someone in some script.

@SergioGasquez
Copy link
Member

Personallly I like the second one best, it seems the easiest to read to me. And keeping the USB ID might be useful for someone in some script.

Agree, second format is the one also like the most!

@AVee
Copy link
Contributor Author

AVee commented Feb 14, 2025

Ok, that was slightly more commits then should have been needed, but this should have better comments and column output.

@SergioGasquez
Copy link
Member

Do you also mind rebasing and resolving the conflicts?

@AVee AVee force-pushed the list-ports branch 3 times, most recently from 6ef2bd5 to c1abbdb Compare February 14, 2025 14:06
@AVee
Copy link
Contributor Author

AVee commented Feb 14, 2025

Do you also mind rebasing and resolving the conflicts?

Done, I also squashed it to a single commit.

Copy link
Member

@SergioGasquez SergioGasquez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks

@SergioGasquez SergioGasquez added this pull request to the merge queue Feb 14, 2025
Merged via the queue into esp-rs:main with commit 7b6e5e1 Feb 14, 2025
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants