summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorcliechti <cliechti@f19166aa-fa4f-0410-85c2-fa1106f25c8a>2010-01-02 03:01:21 +0000
committercliechti <cliechti@f19166aa-fa4f-0410-85c2-fa1106f25c8a>2010-01-02 03:01:21 +0000
commita3488d2ef1c1c9e7945ef46f48ec914155349a97 (patch)
treeebec21c6e1b389085612d86a3e4532211f29b023 /examples
parent854061b225f5f90eb275e238e554e14cc930aae7 (diff)
downloadpyserial-a3488d2ef1c1c9e7945ef46f48ec914155349a97.tar.gz
output pySerial version inhelp text
git-svn-id: http://svn.code.sf.net/p/pyserial/code/trunk/pyserial@352 f19166aa-fa4f-0410-85c2-fa1106f25c8a
Diffstat (limited to 'examples')
-rw-r--r--examples/miniterm.py66
1 files changed, 36 insertions, 30 deletions
diff --git a/examples/miniterm.py b/examples/miniterm.py
index aaef8e4..672fe69 100644
--- a/examples/miniterm.py
+++ b/examples/miniterm.py
@@ -26,7 +26,7 @@ def key_description(character):
# for the shortcut keys is used and not the value at program start
def get_help_text():
return """
---- pySerial - miniterm - help
+--- pySerial (%(version)s) - miniterm - help
---
--- %(exit)-8s Exit program
--- %(menu)-8s Menu escape key, followed by:
@@ -48,6 +48,7 @@ def get_help_text():
--- x X disable/enable software flow control
--- r R disable/enable hardware flow control
""" % {
+ 'version': getattr(serial, 'VERSION', 'unkown'),
'exit': key_description(EXITCHARCTER),
'menu': key_description(MENUCHARACTER),
'rts': key_description('\x12'),
@@ -80,7 +81,7 @@ if os.name == 'nt':
def getkey(self):
while 1:
z = msvcrt.getch()
- if z == '\0' or z == '\xe0': #functions keys
+ if z == '\0' or z == '\xe0': # functions keys
msvcrt.getch()
else:
if z == '\r':
@@ -102,7 +103,6 @@ elif os.name == 'posix':
new[6][termios.VMIN] = 1
new[6][termios.VTIME] = 0
termios.tcsetattr(self.fd, termios.TCSANOW, new)
- #s = '' # We'll save the characters typed and add them to the pool.
def getkey(self):
c = os.read(self.fd, 1)
@@ -195,36 +195,42 @@ class Miniterm:
def reader(self):
"""loop and copy serial->console"""
- while self.alive:
- data = self.serial.read(1)
+ try:
+ while self.alive:
+ data = self.serial.read(1)
- if self.repr_mode == 0:
- # direct output, just have to care about newline setting
- if data == '\r' and self.convert_outgoing == CONVERT_CR:
- sys.stdout.write('\n')
- else:
- sys.stdout.write(data)
- elif self.repr_mode == 1:
- # escape non-printable, let pass newlines
- if self.convert_outgoing == CONVERT_CRLF and data in '\r\n':
- if data == '\n':
+ if self.repr_mode == 0:
+ # direct output, just have to care about newline setting
+ if data == '\r' and self.convert_outgoing == CONVERT_CR:
sys.stdout.write('\n')
- elif data == '\r':
- pass
- elif data == '\n' and self.convert_outgoing == CONVERT_LF:
- sys.stdout.write('\n')
- elif data == '\r' and self.convert_outgoing == CONVERT_CR:
- sys.stdout.write('\n')
- else:
+ else:
+ sys.stdout.write(data)
+ elif self.repr_mode == 1:
+ # escape non-printable, let pass newlines
+ if self.convert_outgoing == CONVERT_CRLF and data in '\r\n':
+ if data == '\n':
+ sys.stdout.write('\n')
+ elif data == '\r':
+ pass
+ elif data == '\n' and self.convert_outgoing == CONVERT_LF:
+ sys.stdout.write('\n')
+ elif data == '\r' and self.convert_outgoing == CONVERT_CR:
+ sys.stdout.write('\n')
+ else:
+ sys.stdout.write(repr(data)[1:-1])
+ elif self.repr_mode == 2:
+ # escape all non-printable, including newline
sys.stdout.write(repr(data)[1:-1])
- elif self.repr_mode == 2:
- # escape all non-printable, including newline
- sys.stdout.write(repr(data)[1:-1])
- elif self.repr_mode == 3:
- # escape everything (hexdump)
- for character in data:
- sys.stdout.write("%s " % character.encode('hex'))
- sys.stdout.flush()
+ elif self.repr_mode == 3:
+ # escape everything (hexdump)
+ for character in data:
+ sys.stdout.write("%s " % character.encode('hex'))
+ sys.stdout.flush()
+ except serial.SerialException, e:
+ self.alive = False
+ # would be nice if the console reader could be interruptted at this
+ # point...
+ raise
def writer(self):