42 def get_com_port(com_search_text, descr_search_text, start):
47 global description_first
48 global description_last
49 global description_CDC
52 print(
'\nLooking for Serial Port\n')
55 pio_subprocess = subprocess.Popen([
'platformio',
'device',
'list'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
57 looking_for_description =
False
58 for line
in iter(pio_subprocess.stdout.readline,
''):
59 if 0 <= line.find(com_search_text):
60 looking_for_description =
True
61 com_last = line.replace(
'\n',
'')
64 if 0 <= line.find(descr_search_text)
and looking_for_description:
65 looking_for_description =
False
66 description_last = line[ start : ]
67 if description_first ==
'':
68 description_first = description_last
69 if 0 <= description_last.find(
'CDC'):
71 description_CDC = description_last
73 if com_CDC ==
'' and com_first !=
'':
75 description_CDC = description_first
77 com_CDC =
'COM_PORT_NOT_FOUND'
79 while 0 <= com_CDC.find(
'\n'):
80 com_CDC = com_CDC.replace(
'\n',
'')
81 while 0 <= com_CDC.find(
'\r'):
82 com_CDC = com_CDC.replace(
'\r',
'')
84 if com_CDC ==
'COM_PORT_NOT_FOUND':
87 print(
'FOUND: ', com_CDC)
88 print(
'DESCRIPTION: ', description_CDC,
'\n')