我需要列出或枚举现有串行端口,直到现在我一直在使用这种方法enumerate_serial_ports(),但它不适用于 Windows 7。你知道一些替代方法,我如何在 Windows 7 下找到可用的串行端口?
def enumerate_serial_ports():
""" Uses the Win32 registry to return an
iterator of serial (COM) ports
existing on this computer.
"""
path = 'HARDWARE\\DEVICEMAP\\SERIALCOMM'
try:
key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, path)
except WindowsError:
raise IterationError
for i in itertools.count():
try:
val = winreg.EnumValue(key, i)
yield str(val[1])
except EnvironmentError:
break
我得到迭代错误