spy: fix hexdump layout and some bugs
diff --git a/serial/serialutil.py b/serial/serialutil.py
index 63f8a93..9bd223f 100644
--- a/serial/serialutil.py
+++ b/serial/serialutil.py
@@ -25,6 +25,8 @@
# "for byte in data" fails for python3 as it returns ints instead of bytes
def iterbytes(b):
"""Iterate over bytes, returning bytes instead of ints (python3)"""
+ if isinstance(b, memoryview):
+ b = b.tobytes()
x = 0
while True:
a = b[x:x+1]
diff --git a/serial/urlhandler/protocol_spy.py b/serial/urlhandler/protocol_spy.py
index 0685e3e..bc6db50 100644
--- a/serial/urlhandler/protocol_spy.py
+++ b/serial/urlhandler/protocol_spy.py
@@ -44,13 +44,16 @@
n += 1
if n == 8:
yield (' ', ' ')
- elif n > 16:
+ elif n >= 16:
yield (None, None)
n = 0
- while n < 16:
- yield (' ', ' ')
- n += 1
- yield (None, None)
+ if n > 0:
+ while n < 16:
+ n += 1
+ if n == 8:
+ yield (' ', ' ')
+ yield (' ', ' ')
+ yield (None, None)
def hexdump(data):
@@ -104,9 +107,9 @@
000000.000 FLSH flushInput
000002.469 RTS inactive
000002.773 RTS active
- 000003.106 TX C3 B6 ..
- 000003.107 RX C3 .
- 000003.108 RX B6 .
+ 000003.001 TX 48 45 4C 4C 4F HELLO
+ 000003.102 RX 48 45 4C 4C 4F HELLO
+
"""
def __init__(self, output, color):
@@ -187,7 +190,7 @@
def flushInput(self):
self.formatter.control('FLSH', 'flushInput')
- super(Serial, self).flush()
+ super(Serial, self).flushInput()
def flushOutput(self):
self.formatter.control('FLSH', 'flushOutput')
@@ -225,8 +228,8 @@
return level
def getCD(self):
- self.formatter.control('CD', 'active' if level else 'inactive')
level = super(Serial, self).getCD()
+ self.formatter.control('CD', 'active' if level else 'inactive')
return level
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -