Commit e4646076 by Guba Sándor

replace line endings anf fix reading bug

parent 5e32d6a6
......@@ -28,9 +28,8 @@ class SerialPort(abstract.FileDescriptor):
connected = 1
def __init__(self, protocol, deviceNameOrPortNumber, reactor):
#self._serialFactory = VirtioSerial
#self._serial = self._serialFactory(port=deviceNameOrPortNumber)
self.hComPort = win32file.CreateFile(deviceNameOrPortNumber,
self.hComPort = win32file.CreateFile(
deviceNameOrPortNumber,
win32con.GENERIC_READ | win32con.GENERIC_WRITE,
0, # exclusive access
None, # no security
......@@ -80,13 +79,16 @@ class SerialPort(abstract.FileDescriptor):
self._overlappedRead,
0)
except:
import time
time.sleep(10)
n = 0
if n:
first = str(self.read_buf[:n])
# now we should get everything that is already in the buffer
# now we should get everything that is already in the buffer (max
# 4096)
win32event.ResetEvent(self._overlappedRead.hEvent)
rc, buf = win32file.ReadFile(self.hComPort,
win32file.AllocateReadBuffer(n),
win32file.AllocateReadBuffer(4096),
self._overlappedRead)
n = win32file.GetOverlappedResult(
self.hComPort,
......@@ -94,12 +96,11 @@ class SerialPort(abstract.FileDescriptor):
1)
# handle all the received data:
self.protocol.dataReceived(first + str(buf[:n]))
# set up next one
win32event.ResetEvent(self._overlappedRead.hEvent)
# rc, self.read_buf = win32file.ReadFile(self.hComPort,
# win32file.AllocateReadBuffer(1),
# self._overlappedRead)
rc, self.read_buf = win32file.ReadFile(self.hComPort,
win32file.AllocateReadBuffer(1),
self._overlappedRead)
def write(self, data):
if data:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment