~ubuntu-branches/ubuntu/quantal/pyserial/quantal

« back to all changes in this revision

Viewing changes to serial/serialwin32.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2004-08-29 14:49:57 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040829144957-moa3k4yx4qte5qth
Tags: 2.1-1
New upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
import win32con   # constants.
12
12
from serialutil import *
13
13
 
14
 
VERSION = "$Revision: 1.27 $".split()[1]     #extract CVS version
 
14
VERSION = "$Revision: 1.29 $".split()[1]     #extract CVS version
15
15
 
16
16
#from winbase.h. these should realy be in win32con
17
17
MS_CTS_ON  = 16
70
70
        self._overlappedRead = win32file.OVERLAPPED()
71
71
        self._overlappedRead.hEvent = win32event.CreateEvent(None, 1, 0, None)
72
72
        self._overlappedWrite = win32file.OVERLAPPED()
 
73
        #~ self._overlappedWrite.hEvent = win32event.CreateEvent(None, 1, 0, None)
73
74
        self._overlappedWrite.hEvent = win32event.CreateEvent(None, 0, 0, None)
74
75
        self._isOpen = True
75
76
 
89
90
            timeouts = (win32con.MAXDWORD, 0, 0, 0, 0)
90
91
        else:
91
92
            timeouts = (0, 0, int(self._timeout*1000), 0, 0)
 
93
        if self._writeTimeout is None:
 
94
            pass
 
95
        elif self._writeTimeout == 0:
 
96
            timeouts = timeouts[:-2] + (0, win32con.MAXDWORD)
 
97
        else:
 
98
            timeouts = timeouts[:-2] + (0, int(self._writeTimeout*1000))
92
99
        win32file.SetCommTimeouts(self.hComPort, timeouts)
93
100
 
94
101
        win32file.SetCommMask(self.hComPort, win32file.EV_ERR)
143
150
        comDCB.fNull            = 0
144
151
        comDCB.fErrorChar       = 0
145
152
        comDCB.fAbortOnError    = 0
 
153
        comDCB.XonChar          = XON
 
154
        comDCB.XoffChar         = XOFF
146
155
 
147
 
        win32file.SetCommState(self.hComPort, comDCB)
 
156
        try:
 
157
            win32file.SetCommState(self.hComPort, comDCB)
 
158
        except win32file.error, e:
 
159
            raise ValueError("Cannot configure port, some setting was wrong. Original message: %s" % e)
148
160
 
149
161
    #~ def __del__(self):
150
162
        #~ self.close()
199
211
        if not self.hComPort: raise portNotOpenError
200
212
        #print repr(s),
201
213
        if s:
 
214
            #~ win32event.ResetEvent(self._overlappedWrite.hEvent)
202
215
            err, n = win32file.WriteFile(self.hComPort, s, self._overlappedWrite)
203
216
            if err: #will be ERROR_IO_PENDING:
204
217
                # Wait for the write to complete.
205
 
                win32event.WaitForSingleObject(self._overlappedWrite.hEvent, win32event.INFINITE)
 
218
                #~ win32event.WaitForSingleObject(self._overlappedWrite.hEvent, win32event.INFINITE)
 
219
                n = win32file.GetOverlappedResult(self.hComPort, self._overlappedWrite, 1)
 
220
                if n != len(s):
 
221
                    raise writeTimeoutError
 
222
                
206
223
 
207
224
    def flushInput(self):
208
225
        """Clear input buffer, discarding all that is in the buffer."""