@@ -135,7 +135,7 @@ def main(argv=None, esp=None):
135
135
parser .add_argument (
136
136
"--port-filter" ,
137
137
action = "append" ,
138
- help = "Serial port device filter, can be vid=NUMBER, pid=NUMBER, name=SUBSTRING" ,
138
+ help = "Serial port device filter, can be vid=NUMBER, pid=NUMBER, name=SUBSTRING, serial=SUBSTRING " ,
139
139
type = str ,
140
140
default = [],
141
141
)
@@ -728,6 +728,7 @@ def add_spi_flash_subparsers(
728
728
args .filterVids = []
729
729
args .filterPids = []
730
730
args .filterNames = []
731
+ args .filterSerials = []
731
732
for f in args .port_filter :
732
733
kvp = f .split ("=" )
733
734
if len (kvp ) != 2 :
@@ -738,6 +739,8 @@ def add_spi_flash_subparsers(
738
739
args .filterPids .append (arg_auto_int (kvp [1 ]))
739
740
elif kvp [0 ] == "name" :
740
741
args .filterNames .append (kvp [1 ])
742
+ elif kvp [0 ] == "serial" :
743
+ args .filterSerials .append (kvp [1 ])
741
744
else :
742
745
raise FatalError ("Option --port-filter argument key not recognized" )
743
746
@@ -776,7 +779,9 @@ def add_spi_flash_subparsers(
776
779
initial_baud = args .baud
777
780
778
781
if args .port is None :
779
- ser_list = get_port_list (args .filterVids , args .filterPids , args .filterNames )
782
+ ser_list = get_port_list (
783
+ args .filterVids , args .filterPids , args .filterNames , args .filterSerials
784
+ )
780
785
print ("Found %d serial ports" % len (ser_list ))
781
786
else :
782
787
ser_list = [args .port ]
@@ -1082,7 +1087,7 @@ def arg_auto_chunk_size(string: str) -> int:
1082
1087
return num
1083
1088
1084
1089
1085
- def get_port_list (vids = [], pids = [], names = []):
1090
+ def get_port_list (vids = [], pids = [], names = [], serials = [] ):
1086
1091
if list_ports is None :
1087
1092
raise FatalError (
1088
1093
"Listing all serial ports is currently not available. "
@@ -1103,6 +1108,11 @@ def get_port_list(vids=[], pids=[], names=[]):
1103
1108
port .name is None or all (name not in port .name for name in names )
1104
1109
):
1105
1110
continue
1111
+ if serials and (
1112
+ port .serial_number is None
1113
+ or all (serial not in port .serial_number for serial in serials )
1114
+ ):
1115
+ continue
1106
1116
ports .append (port .device )
1107
1117
return sorted (ports )
1108
1118
0 commit comments