From a0268e73a4c1bbb98ee3b780b33851a85de246a5 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Tue, 2 Jul 2013 02:54:36 +0000 Subject: open device and setting it to raw mode some code cleanup git-svn-id: https://svn.spreadspace.org/pic/trunk@16 a09c6847-51d9-44de-8ef2-e725cf50f3c7 --- downloader/downloader.py | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'downloader') diff --git a/downloader/downloader.py b/downloader/downloader.py index 6dc36c3..c9c48a9 100755 --- a/downloader/downloader.py +++ b/downloader/downloader.py @@ -71,15 +71,29 @@ Options: raise getopt.GetoptError('Too many arguments') except getopt.GetoptError, msg: - print("ERROR: %s" % msg) - print(usage) + print "ERROR: %s" % msg + print usage sys.exit(2) + + + + try: + dev = os.open(device, os.O_RDWR | os.O_NOCTTY); + tty.setraw(dev, termios.TCSAFLUSH) + termios.tcflush(dev, termios.TCIFLUSH) + + except OSError, msg: + print "ERROR: opening device: %s" % msg + sys.exit(3) + + + fin = args[0] if fin == '-': fin = sys.stdin elif not os.path.isfile(fin): - print("ERROR: File not found: %s" % fin) + print "ERROR: File not found: %s" % fin sys.exit(1) data = {} @@ -92,7 +106,8 @@ Options: else: data[a/2] += (ih[a] << 8) - addr = data.keys() - addr.sort() - for a in addr: + + addrs = data.keys() + addrs.sort() + for a in addrs: print "%05d: %04X" % (a, data[a]) -- cgit v1.2.3