Pergunta

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?

Foi útil?

Solução

import win32com.client 
wmi = win32com.client.GetObject("winmgmts:") 
for port in wmi.InstancesOf("Win32_SerialPort"): 
    print port.DeviceID, port.Name
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top