Commit e4646076 by Guba Sándor

replace line endings anf fix reading bug

parent 5e32d6a6
...@@ -28,9 +28,8 @@ class SerialPort(abstract.FileDescriptor): ...@@ -28,9 +28,8 @@ class SerialPort(abstract.FileDescriptor):
connected = 1 connected = 1
def __init__(self, protocol, deviceNameOrPortNumber, reactor): def __init__(self, protocol, deviceNameOrPortNumber, reactor):
#self._serialFactory = VirtioSerial self.hComPort = win32file.CreateFile(
#self._serial = self._serialFactory(port=deviceNameOrPortNumber) deviceNameOrPortNumber,
self.hComPort = win32file.CreateFile(deviceNameOrPortNumber,
win32con.GENERIC_READ | win32con.GENERIC_WRITE, win32con.GENERIC_READ | win32con.GENERIC_WRITE,
0, # exclusive access 0, # exclusive access
None, # no security None, # no security
...@@ -80,13 +79,16 @@ class SerialPort(abstract.FileDescriptor): ...@@ -80,13 +79,16 @@ class SerialPort(abstract.FileDescriptor):
self._overlappedRead, self._overlappedRead,
0) 0)
except: except:
import time
time.sleep(10)
n = 0 n = 0
if n: if n:
first = str(self.read_buf[: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) win32event.ResetEvent(self._overlappedRead.hEvent)
rc, buf = win32file.ReadFile(self.hComPort, rc, buf = win32file.ReadFile(self.hComPort,
win32file.AllocateReadBuffer(n), win32file.AllocateReadBuffer(4096),
self._overlappedRead) self._overlappedRead)
n = win32file.GetOverlappedResult( n = win32file.GetOverlappedResult(
self.hComPort, self.hComPort,
...@@ -94,12 +96,11 @@ class SerialPort(abstract.FileDescriptor): ...@@ -94,12 +96,11 @@ class SerialPort(abstract.FileDescriptor):
1) 1)
# handle all the received data: # handle all the received data:
self.protocol.dataReceived(first + str(buf[:n])) self.protocol.dataReceived(first + str(buf[:n]))
# set up next one # set up next one
win32event.ResetEvent(self._overlappedRead.hEvent) win32event.ResetEvent(self._overlappedRead.hEvent)
# rc, self.read_buf = win32file.ReadFile(self.hComPort, rc, self.read_buf = win32file.ReadFile(self.hComPort,
# win32file.AllocateReadBuffer(1), win32file.AllocateReadBuffer(1),
# self._overlappedRead) self._overlappedRead)
def write(self, data): def write(self, data):
if 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