summaryrefslogtreecommitdiff
path: root/pyserial
diff options
context:
space:
mode:
authorcliechti <cliechti@f19166aa-fa4f-0410-85c2-fa1106f25c8a>2008-06-18 23:27:30 +0000
committercliechti <cliechti@f19166aa-fa4f-0410-85c2-fa1106f25c8a>2008-06-18 23:27:30 +0000
commitf19610b5ff79e620bf578b82db9decfa3cb356d7 (patch)
treed1013fd28473a843d7ed9eab24a7b399037cd8e5 /pyserial
parent8bce8204d4e177bd6a36701d1ba1f64a1df15808 (diff)
downloadpyserial-git-f19610b5ff79e620bf578b82db9decfa3cb356d7.tar.gz
com port name trasnlation for the special windows feature
Diffstat (limited to 'pyserial')
-rw-r--r--pyserial/CHANGES.txt3
-rw-r--r--pyserial/serial/serialwin32.py21
2 files changed, 13 insertions, 11 deletions
diff --git a/pyserial/CHANGES.txt b/pyserial/CHANGES.txt
index 0d2eeb9..7daa819 100644
--- a/pyserial/CHANGES.txt
+++ b/pyserial/CHANGES.txt
@@ -244,6 +244,9 @@ New Features:
- ``sendBreak()`` accepts a ``duration`` argument. Default duration increased.
+- win32 handles \\.\COMx format automatically for com ports of higher number
+ (COM10 is internally translated to \\.\COM10 etc.)
+
- update wxSerialConfigDialog.py and wxTerminal.py compatibility with
wxPythoon 2.8 (Peleg)
diff --git a/pyserial/serial/serialwin32.py b/pyserial/serial/serialwin32.py
index 004c3d1..b44331c 100644
--- a/pyserial/serial/serialwin32.py
+++ b/pyserial/serial/serialwin32.py
@@ -11,7 +11,7 @@ import win32event # We use events and the WaitFor[Single|Multiple]Objects functi
import win32con # constants.
from serialutil import *
-VERSION = "$Revision: 1.36 $".split()[1] #extract CVS version
+VERSION = "$Revision: 1.37 $".split()[1] #extract CVS version
#from winbase.h. these should realy be in win32con
MS_CTS_ON = 16
@@ -21,13 +21,7 @@ MS_RLSD_ON = 128
def device(portnum):
"""Turn a port number into a device name"""
- #the "//./COMx" format is required for devices >= 9
- #not all versions of windows seem to support this propperly
- #so that the first few ports are used with the DOS device name
- if portnum < 9:
- return 'COM%d' % (portnum+1) #numbers are transformed to a string
- else:
- return r'\\.\COM%d' % (portnum+1)
+ return 'COM%d' % (portnum+1) #numbers are transformed to a string
class Serial(SerialBase):
"""Serial port implemenation for Win32. This implemenatation requires a
@@ -43,7 +37,7 @@ class Serial(SerialBase):
raise SerialException("Port must be configured before it can be used.")
self.hComPort = None
try:
- self.hComPort = win32file.CreateFile(self.portstr,
+ self.hComPort = win32file.CreateFile(self.makeDeviceName(self.portstr),
win32con.GENERIC_READ | win32con.GENERIC_WRITE,
0, # exclusive access
None, # no security
@@ -52,7 +46,7 @@ class Serial(SerialBase):
None)
except Exception, msg:
self.hComPort = None #'cause __del__ is called anyway
- raise SerialException("could not open port %s: %s" % (self._port, msg))
+ raise SerialException("could not open port %s: %s" % (self._portstr, msg))
# Setup a 4k buffer
win32file.SetupComm(self.hComPort, 4096, 4096)
@@ -180,7 +174,12 @@ class Serial(SerialBase):
self._isOpen = False
def makeDeviceName(self, port):
- return device(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
# - - - - - - - - - - - - - - - - - - - - - - - -