diff options
author | cliechti <cliechti@f19166aa-fa4f-0410-85c2-fa1106f25c8a> | 2008-06-24 12:11:57 +0000 |
---|---|---|
committer | cliechti <cliechti@f19166aa-fa4f-0410-85c2-fa1106f25c8a> | 2008-06-24 12:11:57 +0000 |
commit | 8b7cff02814bdd6343af788ae646b186ff18db2a (patch) | |
tree | 38e25ed0ea32ebc839ecd2271a13fa1a88d8f164 | |
parent | c53a8cacf340c4f54dc16eb7107da9ddbbcbbeec (diff) | |
download | pyserial-git-8b7cff02814bdd6343af788ae646b186ff18db2a.tar.gz |
move the name patching code
-rw-r--r-- | pyserial/serial/serialwin32.py | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/pyserial/serial/serialwin32.py b/pyserial/serial/serialwin32.py index cbabc4e..94371c1 100644 --- a/pyserial/serial/serialwin32.py +++ b/pyserial/serial/serialwin32.py @@ -34,8 +34,14 @@ class Serial(SerialBase): if self._port is None: raise SerialException("Port must be configured before it can be used.") self.hComPort = None + # the "\\.\COMx" format is required for devices other than COM1-COM8 + # not all versions of windows seem to support this properly + # so that the first few ports are used with the DOS device name + port = self.portstr + if port.upper().startswith('COM') and int(port[3:]) > 8: + port = '\\\\.\\' + port try: - self.hComPort = win32file.CreateFile(self.makeDeviceName(self.portstr), + self.hComPort = win32file.CreateFile(port, win32con.GENERIC_READ | win32con.GENERIC_WRITE, 0, # exclusive access None, # no security @@ -185,12 +191,7 @@ class Serial(SerialBase): self._isOpen = False def makeDeviceName(self, port): - # the "\\.\COMx" format is required for devices other than COM1-COM8 - # not all versions of windows seem to support this properly - # so that the first few ports are used with the DOS device name - if port.upper().startswith('COM') and int(port[3:]) <= 8: - return port - return '\\\\.\\' + port + return device(port) # - - - - - - - - - - - - - - - - - - - - - - - - |