diff options
author | cliechti <cliechti@f19166aa-fa4f-0410-85c2-fa1106f25c8a> | 2004-07-21 19:41:40 +0000 |
---|---|---|
committer | cliechti <cliechti@f19166aa-fa4f-0410-85c2-fa1106f25c8a> | 2004-07-21 19:41:40 +0000 |
commit | c31f8cf1780093fab7de1a8a90fbcac98d8284c6 (patch) | |
tree | c7d5c7cbc5531490f72b049083f7e6b3bf6e9a23 | |
parent | b7466daf4f82c4ddea5947442be2cc17bce59bf9 (diff) | |
download | pyserial-git-c31f8cf1780093fab7de1a8a90fbcac98d8284c6.tar.gz |
added connection debug mode
-rw-r--r-- | pyserial/examples/miniterm.py | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/pyserial/examples/miniterm.py b/pyserial/examples/miniterm.py index 3e2df1c..a4c5646 100644 --- a/pyserial/examples/miniterm.py +++ b/pyserial/examples/miniterm.py @@ -26,7 +26,6 @@ if os.name == 'nt': return z elif os.name == 'posix': - #XXX: Untested code derived from the Python FAQ.... import termios, sys, os fd = sys.stdin.fileno() old = termios.tcgetattr(fd) @@ -52,7 +51,11 @@ else: def reader(): """loop forever and copy serial->console""" while 1: - sys.stdout.write(s.read()) + data = s.read() + if repr_mode: + sys.stdout.write(repr(data)[1:-1]) + else: + sys.stdout.write(data) sys.stdout.flush() def writer(): @@ -77,6 +80,7 @@ def usage(): -x, --xonxoff: enable software flow control (default off) -e, --echo: enable local echo (default off) -c, --cr: disable LF -> CR+LF translation + -D, --debug: debug connection (escape nonprintable chars) """ % (sys.argv[0], )) @@ -84,8 +88,8 @@ if __name__ == '__main__': #parse command line options try: opts, args = getopt.getopt(sys.argv[1:], - "hp:b:rxec", - ["help", "port=", "baud=", "rtscts", "xonxoff", "echo", "cr"] + "hp:b:rxecD", + ["help", "port=", "baud=", "rtscts", "xonxoff", "echo", "cr", "debug"] ) except getopt.GetoptError: # print help information and exit: @@ -98,6 +102,7 @@ if __name__ == '__main__': convert_outgoing_cr = 1 rtscts = 0 xonxoff = 0 + repr_mode = 0 for o, a in opts: if o in ("-h", "--help"): #help text usage() @@ -120,6 +125,8 @@ if __name__ == '__main__': echo = 1 elif o in ("-c", "--cr"): convert_outgoing_cr = 0 + elif o in ("-D", "--debug"): + repr_mode = 1 try: s = serial.Serial(port, baudrate, rtscts=rtscts, xonxoff=xonxoff) |