本文整理汇总了Python中win32event.ResetEvent方法的典型用法代码示例。如果您正苦于以下问题:Python win32event.ResetEvent方法的具体用法?Python win32event.ResetEvent怎么用?Python win32event.ResetEvent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类win32event
的用法示例。
在下文中一共展示了win32event.ResetEvent方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: serialReadEvent
# 需要导入模块: import win32event [as 别名]
# 或者: from win32event import ResetEvent [as 别名]
def serialReadEvent(self):
#get that character we set up
n = win32file.GetOverlappedResult(self._serial.hComPort, self._overlappedRead, 0)
if n:
first = str(self.read_buf[:n])
#now we should get everything that is already in the buffer
flags, comstat = win32file.ClearCommError(self._serial.hComPort)
if comstat.cbInQue:
win32event.ResetEvent(self._overlappedRead.hEvent)
rc, buf = win32file.ReadFile(self._serial.hComPort,
win32file.AllocateReadBuffer(comstat.cbInQue),
self._overlappedRead)
n = win32file.GetOverlappedResult(self._serial.hComPort, self._overlappedRead, 1)
#handle all the received data:
self.protocol.dataReceived(first + str(buf[:n]))
else:
#handle all the received data:
self.protocol.dataReceived(first)
#set up next one
win32event.ResetEvent(self._overlappedRead.hEvent)
rc, self.read_buf = win32file.ReadFile(self._serial.hComPort,
win32file.AllocateReadBuffer(1),
self._overlappedRead)
示例2: serialReadEvent
# 需要导入模块: import win32event [as 别名]
# 或者: from win32event import ResetEvent [as 别名]
def serialReadEvent(self):
#get that character we set up
n = win32file.GetOverlappedResult(self._serial._port_handle, self._overlappedRead, 0)
first = to_bytes(self.read_buf[:n])
#now we should get everything that is already in the buffer
flags, comstat = self._clearCommError()
if comstat.cbInQue:
win32event.ResetEvent(self._overlappedRead.hEvent)
rc, buf = win32file.ReadFile(self._serial._port_handle,
win32file.AllocateReadBuffer(comstat.cbInQue),
self._overlappedRead)
n = win32file.GetOverlappedResult(self._serial._port_handle, self._overlappedRead, 1)
#handle all the received data:
self.protocol.dataReceived(first + to_bytes(buf[:n]))
else:
#handle all the received data:
self.protocol.dataReceived(first)
#set up next one
win32event.ResetEvent(self._overlappedRead.hEvent)
rc, self.read_buf = win32file.ReadFile(self._serial._port_handle,
win32file.AllocateReadBuffer(1),
self._overlappedRead)
示例3: Connect
# 需要导入模块: import win32event [as 别名]
# 或者: from win32event import ResetEvent [as 别名]
def Connect(entryName, bUseCallback):
if bUseCallback:
theCallback = Callback
win32event.ResetEvent(callbackEvent)
else:
theCallback = None
# in order to *use* the username/password of a particular dun entry, one must
# explicitly get those params under win95....
try:
dp, b = win32ras.GetEntryDialParams( None, entryName )
except:
print "Couldn't find DUN entry: %s" % entryName
else:
hras, rc = win32ras.Dial(None, None, (entryName, "", "", dp[ 3 ], dp[ 4 ], ""),theCallback)
# hras, rc = win32ras.Dial(None, None, (entryName, ),theCallback)
# print hras, rc
if not bUseCallback and rc != 0:
print "Could not dial the RAS connection:", win32ras.GetErrorString(rc)
hras = HangUp( hras )
# don't wait here if there's no need to....
elif bUseCallback and win32event.WaitForSingleObject(callbackEvent, 60000)!=win32event.WAIT_OBJECT_0:
print "Gave up waiting for the process to complete!"
# sdk docs state one must explcitly hangup, even if there's an error....
try:
cs = win32ras.GetConnectStatus( hras )
except:
# on error, attempt a hang up anyway....
hras = HangUp( hras )
else:
if int( cs[ 0 ] ) == win32ras.RASCS_Disconnected:
hras = HangUp( hras )
return hras, rc
示例4: Write
# 需要导入模块: import win32event [as 别名]
# 或者: from win32event import ResetEvent [as 别名]
def Write(self, data, timeout):
if self.handle:
try:
self.lockObject.acquire()
if eg.debugLevel:
print "writing " + str(len(data)) + " bytes to " + self.getName()
if not self._overlappedWrite:
self._overlappedWrite = win32file.OVERLAPPED()
err, n = win32file.WriteFile(self.handle, data, self._overlappedWrite)
if err: #will be ERROR_IO_PENDING:
# Wait for the write to complete.
n = win32file.GetOverlappedResult(self.handle, self._overlappedWrite, 1)
if n != len(data):
raise Exception("could not write full data")
elif n != len(data):
raise Exception("could not write full data")
if timeout: #waits for response from device
win32event.ResetEvent(self._overlappedRead.hEvent)
res = win32event.WaitForSingleObject(self._overlappedRead.hEvent, timeout)
if res == win32event.WAIT_TIMEOUT:
raise Exception("no response from device within timeout")
finally:
self.lockObject.release()
else:
raise Exception("invalid handle")
return