{"id":2112,"date":"2019-02-01T07:56:57","date_gmt":"2019-02-01T05:56:57","guid":{"rendered":"https:\/\/www.kurokesu.com\/main\/?p=2112"},"modified":"2019-02-01T09:02:00","modified_gmt":"2019-02-01T07:02:00","slug":"which-usb-to-com-port-is-the-most-recent-one","status":"publish","type":"post","link":"https:\/\/www.kurokesu.com\/main\/2019\/02\/01\/which-usb-to-com-port-is-the-most-recent-one\/","title":{"rendered":"Which USB to COM port is the most recent one?"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">How many times did you find yourself looking for Windows Control Panel and wondering which is the most recent plugged USB to SERIAL com port? Well simple and clean Python script comes very handy for this task.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"463\" src=\"https:\/\/www.kurokesu.com\/main\/wp-content\/uploads\/2019\/02\/IMG_8326_r-1024x463.jpg\" alt=\"\" class=\"wp-image-2129\" srcset=\"https:\/\/www.kurokesu.com\/main\/wp-content\/uploads\/2019\/02\/IMG_8326_r-1024x463.jpg 1024w, https:\/\/www.kurokesu.com\/main\/wp-content\/uploads\/2019\/02\/IMG_8326_r-300x136.jpg 300w, https:\/\/www.kurokesu.com\/main\/wp-content\/uploads\/2019\/02\/IMG_8326_r-768x347.jpg 768w, https:\/\/www.kurokesu.com\/main\/wp-content\/uploads\/2019\/02\/IMG_8326_r-1140x515.jpg 1140w, https:\/\/www.kurokesu.com\/main\/wp-content\/uploads\/2019\/02\/IMG_8326_r.jpg 1500w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Just start a script and plug in new device &#8211; new com port will be displayed with minimal lag. This also gives great opportunity to run production scripts to flash new firmware or automate other tasks.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><em>import<\/em> sys, re<br><em>import<\/em> subprocess<br><em>import<\/em> time<br><em>import<\/em> serial.tools.list_ports<br><br>def grep(<em>regexp<\/em>):<br>    <em>for<\/em> port, desc, hwid in serial.tools.list_ports.comports():<br>        <em>if<\/em> re.search(regexp, port, re.I) or re.search(regexp, desc) or re.search(regexp, hwid):<br>            <em>yield<\/em> port, desc, hwid<br><br><em># Discover all COM ports and show them<\/em><br>port_list_initial = serial.tools.list_ports.comports()<br><em>for<\/em> port, desc, hwid in port_list_initial:<br>    print('-', port, desc)<br><br>print('\\nWaiting for new USB to SERIAL device to be plugged in...\\n')<br><br><em># Wait for new device to be plugged in and show it<\/em><br><em>while<\/em> True:<br>    port_list_poll = serial.tools.list_ports.comports()<br><br>    <em>for<\/em> p in port_list_poll:<br>        <em>if<\/em> p not in port_list_initial:<br>            print('-', p)<br>            input('\\nAll done, press enter to quit')<br>            sys.exit(1)<br>        <em>else<\/em>:<br>            time.sleep(0.5) <em># Don't poll too often<\/em> <\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"466\" src=\"https:\/\/www.kurokesu.com\/main\/wp-content\/uploads\/2019\/02\/compare-1024x466.png\" alt=\"\" class=\"wp-image-2118\" srcset=\"https:\/\/www.kurokesu.com\/main\/wp-content\/uploads\/2019\/02\/compare-1024x466.png 1024w, https:\/\/www.kurokesu.com\/main\/wp-content\/uploads\/2019\/02\/compare-300x137.png 300w, https:\/\/www.kurokesu.com\/main\/wp-content\/uploads\/2019\/02\/compare-768x350.png 768w, https:\/\/www.kurokesu.com\/main\/wp-content\/uploads\/2019\/02\/compare.png 1125w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Also code is uploaded to <a href=\"https:\/\/github.com\/Kurokesu\/find_fresh_plugged_usb2com_port\/blob\/master\/show_new_port.py\">GitHub<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>How many times did you find yourself looking for Windows Control Panel and wondering which is the most recent plugged USB to SERIAL com port? Well simple and clean Python script comes very handy for this task. Just start a script and plug in new device &#8211; new com port will be displayed with minimal [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2129,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[157],"tags":[350,95,49,351,353,87,352],"class_list":["post-2112","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-how-to","tag-com-port","tag-github","tag-python","tag-script","tag-source","tag-usb","tag-utility"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/www.kurokesu.com\/main\/wp-content\/uploads\/2019\/02\/IMG_8326_r.jpg","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p6VSmB-y4","_links":{"self":[{"href":"https:\/\/www.kurokesu.com\/main\/wp-json\/wp\/v2\/posts\/2112","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kurokesu.com\/main\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kurokesu.com\/main\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kurokesu.com\/main\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kurokesu.com\/main\/wp-json\/wp\/v2\/comments?post=2112"}],"version-history":[{"count":7,"href":"https:\/\/www.kurokesu.com\/main\/wp-json\/wp\/v2\/posts\/2112\/revisions"}],"predecessor-version":[{"id":2131,"href":"https:\/\/www.kurokesu.com\/main\/wp-json\/wp\/v2\/posts\/2112\/revisions\/2131"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.kurokesu.com\/main\/wp-json\/wp\/v2\/media\/2129"}],"wp:attachment":[{"href":"https:\/\/www.kurokesu.com\/main\/wp-json\/wp\/v2\/media?parent=2112"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kurokesu.com\/main\/wp-json\/wp\/v2\/categories?post=2112"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kurokesu.com\/main\/wp-json\/wp\/v2\/tags?post=2112"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}