diff options
author | cliechti <cliechti@f19166aa-fa4f-0410-85c2-fa1106f25c8a> | 2002-03-03 20:11:47 +0000 |
---|---|---|
committer | cliechti <cliechti@f19166aa-fa4f-0410-85c2-fa1106f25c8a> | 2002-03-03 20:11:47 +0000 |
commit | 7fe54d52ac6ec9918326724298e9bb64099fd952 (patch) | |
tree | b73ad1cc776b67d00b8d33133a3ace8b629ebd78 /pyserial/serial/serialwin32.py | |
parent | 576de25542db50e756a32fe783a1ffa32ae51fb2 (diff) | |
download | pyserial-git-7fe54d52ac6ec9918326724298e9bb64099fd952.tar.gz |
added SerialException if port can not be opened
Diffstat (limited to 'pyserial/serial/serialwin32.py')
-rw-r--r-- | pyserial/serial/serialwin32.py | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/pyserial/serial/serialwin32.py b/pyserial/serial/serialwin32.py index c4aa142..8fda924 100644 --- a/pyserial/serial/serialwin32.py +++ b/pyserial/serial/serialwin32.py @@ -11,7 +11,7 @@ import win32con # constants. import sys, string import serialutil -VERSION = string.split("$Revision: 1.3 $")[1] #extract CVS version +VERSION = string.split("$Revision: 1.4 $")[1] #extract CVS version PARITY_NONE, PARITY_EVEN, PARITY_ODD = range(3) STOPBITS_ONE, STOPBITS_TWO = (1, 2) @@ -43,13 +43,17 @@ class Serial(serialutil.FileLike): self.portstr = 'COM%d' % (port+1) #numbers are transformed to a string #self.portstr = '\\\\.\\COM%d' % (port+1) #WIN NT format?? - self.hComPort = win32file.CreateFile(self.portstr, - win32con.GENERIC_READ | win32con.GENERIC_WRITE, - 0, # exclusive access - None, # no security - win32con.OPEN_EXISTING, - win32con.FILE_ATTRIBUTE_NORMAL | win32con.FILE_FLAG_OVERLAPPED, - None) + try: + self.hComPort = win32file.CreateFile(self.portstr, + win32con.GENERIC_READ | win32con.GENERIC_WRITE, + 0, # exclusive access + None, # no security + win32con.OPEN_EXISTING, + win32con.FILE_ATTRIBUTE_NORMAL | win32con.FILE_FLAG_OVERLAPPED, + None) + except: + self.hComPort = None #'cause __del__ is called anyway + raise serialutil.SerialException, "could not open port" # Setup a 4k buffer win32file.SetupComm(self.hComPort, 4096, 4096) |