Getting friendly device names in python

后端 未结 6 1119
夕颜
夕颜 2021-01-04 10:29

I have an 2-port signal relay connected to my computer via a USB serial interface. Using the pyserial module I can control these relays with ease. However, this is based on

6条回答
  •  南方客
    南方客 (楼主)
    2021-01-04 11:07

    As far as Windows goes, you could scan the registry:

    import _winreg as reg
    from itertools import count
    
    key = reg.OpenKey(reg.HKEY_LOCAL_MACHINE, 'HARDWARE\\DEVICEMAP\\SERIALCOMM')
    try:
        for i in count():
            device, port = reg.EnumValue(key, i)[:2]
            print device, port
    except WindowsError:
        pass
    

提交回复
热议问题