mirror of
https://github.com/espressif/esptool.git
synced 2025-10-19 20:13:00 +08:00
feat: add filtering based on serial number
Closes https://github.com/espressif/esptool/issues/1027
This commit is contained in:
@@ -158,5 +158,6 @@ at least one FilterValue for each specified FilterType to be considered. Example
|
|||||||
* ``--port-filter vid=0x303A --port-filter pid=0x0002`` matches Espressif ESP32-S2 in USB-OTG mode by VID and PID.
|
* ``--port-filter vid=0x303A --port-filter pid=0x0002`` matches Espressif ESP32-S2 in USB-OTG mode by VID and PID.
|
||||||
* ``--port-filter vid=0x303A --port-filter pid=0x1001`` matches Espressif USB-Serial/JTAG unit used by multiple chips by VID and PID.
|
* ``--port-filter vid=0x303A --port-filter pid=0x1001`` matches Espressif USB-Serial/JTAG unit used by multiple chips by VID and PID.
|
||||||
* ``--port-filter name=ttyUSB`` matches ports where the port name contains the specified text.
|
* ``--port-filter name=ttyUSB`` matches ports where the port name contains the specified text.
|
||||||
|
* ``--port-filter serial=7c98d1065267ee11bcc4c8ab93cd958c`` matches ports where the serial number contains the specified text.
|
||||||
|
|
||||||
See also the `Espressif USB customer-allocated PID repository <https://github.com/espressif/usb-pids>`_
|
See also the `Espressif USB customer-allocated PID repository <https://github.com/espressif/usb-pids>`_
|
||||||
|
@@ -135,7 +135,7 @@ def main(argv=None, esp=None):
|
|||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--port-filter",
|
"--port-filter",
|
||||||
action="append",
|
action="append",
|
||||||
help="Serial port device filter, can be vid=NUMBER, pid=NUMBER, name=SUBSTRING",
|
help="Serial port device filter, can be vid=NUMBER, pid=NUMBER, name=SUBSTRING, serial=SUBSTRING",
|
||||||
type=str,
|
type=str,
|
||||||
default=[],
|
default=[],
|
||||||
)
|
)
|
||||||
@@ -728,6 +728,7 @@ def main(argv=None, esp=None):
|
|||||||
args.filterVids = []
|
args.filterVids = []
|
||||||
args.filterPids = []
|
args.filterPids = []
|
||||||
args.filterNames = []
|
args.filterNames = []
|
||||||
|
args.filterSerials = []
|
||||||
for f in args.port_filter:
|
for f in args.port_filter:
|
||||||
kvp = f.split("=")
|
kvp = f.split("=")
|
||||||
if len(kvp) != 2:
|
if len(kvp) != 2:
|
||||||
@@ -738,6 +739,8 @@ def main(argv=None, esp=None):
|
|||||||
args.filterPids.append(arg_auto_int(kvp[1]))
|
args.filterPids.append(arg_auto_int(kvp[1]))
|
||||||
elif kvp[0] == "name":
|
elif kvp[0] == "name":
|
||||||
args.filterNames.append(kvp[1])
|
args.filterNames.append(kvp[1])
|
||||||
|
elif kvp[0] == "serial":
|
||||||
|
args.filterSerials.append(kvp[1])
|
||||||
else:
|
else:
|
||||||
raise FatalError("Option --port-filter argument key not recognized")
|
raise FatalError("Option --port-filter argument key not recognized")
|
||||||
|
|
||||||
@@ -776,7 +779,9 @@ def main(argv=None, esp=None):
|
|||||||
initial_baud = args.baud
|
initial_baud = args.baud
|
||||||
|
|
||||||
if args.port is None:
|
if args.port is None:
|
||||||
ser_list = get_port_list(args.filterVids, args.filterPids, args.filterNames)
|
ser_list = get_port_list(
|
||||||
|
args.filterVids, args.filterPids, args.filterNames, args.filterSerials
|
||||||
|
)
|
||||||
print("Found %d serial ports" % len(ser_list))
|
print("Found %d serial ports" % len(ser_list))
|
||||||
else:
|
else:
|
||||||
ser_list = [args.port]
|
ser_list = [args.port]
|
||||||
@@ -1082,7 +1087,7 @@ def arg_auto_chunk_size(string: str) -> int:
|
|||||||
return num
|
return num
|
||||||
|
|
||||||
|
|
||||||
def get_port_list(vids=[], pids=[], names=[]):
|
def get_port_list(vids=[], pids=[], names=[], serials=[]):
|
||||||
if list_ports is None:
|
if list_ports is None:
|
||||||
raise FatalError(
|
raise FatalError(
|
||||||
"Listing all serial ports is currently not available. "
|
"Listing all serial ports is currently not available. "
|
||||||
@@ -1103,6 +1108,11 @@ def get_port_list(vids=[], pids=[], names=[]):
|
|||||||
port.name is None or all(name not in port.name for name in names)
|
port.name is None or all(name not in port.name for name in names)
|
||||||
):
|
):
|
||||||
continue
|
continue
|
||||||
|
if serials and (
|
||||||
|
port.serial_number is None
|
||||||
|
or all(serial not in port.serial_number for serial in serials)
|
||||||
|
):
|
||||||
|
continue
|
||||||
ports.append(port.device)
|
ports.append(port.device)
|
||||||
return sorted(ports)
|
return sorted(ports)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user