Lister les ports com disponible
salut, je travail sur un logiciel qui utilise les ports com. Et je souhaiterais donner la liste des ports com disponible. Voila ce que je fais pour le moment qui ne marche pas:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
ListPortAvailable = []
for i in range(1,4):
port = "COM%d" % (i,)
print port
handle = None
try:
handle = CreateFile(port,
win32con.GENERIC_READ | win32con.GENERIC_WRITE,
0, # exclusive access
None, # no security
win32con.OPEN_ALWAYS,
win32con.FILE_ATTRIBUTE_NORMAL,
None)
# It appears that an available COM port will always success here,
# just return 0 for the status flags. We only care that it has _any_ status
# flags (and therefore probably a real modem)
print handle
finally:
# No port, or modem status failed.
if handle != None:
if GetCommModemStatus(handle) == 0:
ListPortAvailable.append(port) |
ce code me renvoie l'exception suivante:
Exception in thread Thread-1:
Traceback (most recent call last):
File "c:\python22\lib\threading.py", line 408, in __bootstrap
self.run()
File "c:\python22\lib\threading.py", line 396, in run
apply(self.__target, self.__args, self.__kwargs)
File "Core\cattLoad.py", line 61, in Run
self.LoadingPort()
File "Core\cattLoad.py", line 111, in LoadingPort
print FindModem()
File "Core\cattSl3Ybus.py", line 45, in FindModem
None)
api_error: (2, 'CreateFile', 'Le fichier sp\xe9cifi\xe9 est introuvable.')
si quelqu'un peux m'aider, merci