Mercurial > code > home > repos > homeauto
changeset 66:4e34fd9aee00
refactor barcode part
Ignore-this: 4bebdfdf7ab9f514f8eb02a833d2202b
author | drewp@bigasterisk.com |
---|---|
date | Wed, 10 Apr 2013 20:52:49 -0700 |
parents | cbc557c35121 |
children | b0f9eef8bb5d |
files | service/starArduino/starArduino.py |
diffstat | 1 files changed, 31 insertions(+), 31 deletions(-) [+] |
line wrap: on
line diff
--- a/service/starArduino/starArduino.py Wed Apr 10 20:51:44 2013 -0700 +++ b/service/starArduino/starArduino.py Wed Apr 10 20:52:49 2013 -0700 @@ -61,38 +61,38 @@ self.write(str(ser.readJson())) def barcodeWatch(arduino, postBarcode): - try: - arduino.ser.write("\xff\xfb") - ret = arduino.readJson() - if ret['barcode']: - if ret['barcode'] == "27 80 48 13 ": - pass # scanner's beep response - else: - arduino.ser.write("\xff\xfc") - arduino.readJson() # my beep response - s = ''.join(chr(int(x)) for x in ret['barcode'].split()) - for code in s.split('\x02'): - if not code: - continue - if not code.endswith('\x03'): - print "couldn't read %r" % code - return - codeType = {'A':'UPC-A', - 'B':'JAN-8', - 'E':'UPC-E', - 'N':'NW-7', - 'C':'CODE39', - 'I':'ITF', - 'K':'CODE128', - }[code[0]] - code = code[1:-1] - postBarcode.post(payload=json.dumps( - {'barcodeType':codeType, 'code':code}), - headers={"content-type" : - "application/json"}) + arduino.ser.write("\xff\xfb") + ret = arduino.readJson() + if not ret['barcode']: + return + if ret['barcode'] == "27 80 48 13 ": + return # scanner's beep response - except ValueError, e: - print "err", e + arduino.ser.write("\xff\xfc") + arduino.readJson() # my beep response + s = ''.join(chr(int(x)) for x in ret['barcode'].split()) + for code in s.split('\x02'): + if not code: + continue + if not code.endswith('\x03'): + print "couldn't read %r" % code + return + codeType = {'A':'UPC-A', + 'B':'JAN-8', + 'E':'UPC-E', + 'N':'NW-7', + 'C':'CODE39', + 'I':'ITF', + 'K':'CODE128', + }[code[0]] + code = code[1:-1] + try: + postBarcode.post(payload=json.dumps( + {'barcodeType':codeType, 'code':code}), + headers={"content-type" : + "application/json"}) + except Exception, e: + print "post err", e class Graph(PrettyErrorHandler, cyclone.web.RequestHandler):