Question

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?

Was it helpful?

Solution

import win32com.client 
wmi = win32com.client.GetObject("winmgmts:") 
for port in wmi.InstancesOf("Win32_SerialPort"): 
    print port.DeviceID, port.Name
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top