Browse Source

Read tweaks.

pyserial_fix
Scott Petersen 11 years ago
parent
commit
f528f21998
1 changed files with 13 additions and 13 deletions
  1. +13
    -13
      pyad2usb/devices.py

+ 13
- 13
pyad2usb/devices.py View File

@@ -115,19 +115,21 @@ class USBDevice(Device):
try: try:
while self._running: while self._running:
buf = self._device.read_data(1) buf = self._device.read_data(1)
self._buffer += buf


if buf == "\n":
if len(self._buffer) > 1:
if self._buffer[-2] == "\r":
self._buffer = self._buffer[:-2]
if buf != '':
self._buffer += buf


# ignore if we just got \r\n with nothing else in the buffer.
if len(self._buffer) != 0:
got_line = True
break
else:
self._buffer = self._buffer[:-1]
if buf == "\n":
if len(self._buffer) > 1:
if self._buffer[-2] == "\r":
self._buffer = self._buffer[:-2]

# ignore if we just got \r\n with nothing else in the buffer.
if len(self._buffer) != 0:
got_line = True
break
else:
self._buffer = self._buffer[:-1]


if timeout > 0 and time.time() - start_time > timeout: if timeout > 0 and time.time() - start_time > timeout:
break break
@@ -209,8 +211,6 @@ class SerialDevice(Device):
if buf != '' and buf != "\xff": # WTF is this \xff and why is it in my buffer?! if buf != '' and buf != "\xff": # WTF is this \xff and why is it in my buffer?!
self._buffer += buf self._buffer += buf


#print '{0:x}'.format(ord(buf))

if buf == "\n": if buf == "\n":
if len(self._buffer) > 1: if len(self._buffer) > 1:
if self._buffer[-2] == "\r": if self._buffer[-2] == "\r":


Loading…
Cancel
Save