Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect device names on serial ports in Python

I use a USB connected Nokia phone to send SMS messages via a COM port in Windows using Python. Evertyhing works fine until a COM port changes. Is there a way to detect which COM port my phone is sitting on? If I understand correctly, only way to do this is to get a list of all availalbe ports and to poll them one by one. What would be the safest and quickest way of doing this?

like image 244
user2458481 Avatar asked Dec 29 '25 11:12

user2458481


1 Answers

import win32com.client 
wmi = win32com.client.GetObject("winmgmts:") 
for port in wmi.InstancesOf("Win32_SerialPort"): 
    print port.DeviceID, port.Name
like image 63
user2458481 Avatar answered Dec 31 '25 01:12

user2458481



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!