# HG changeset patch # User drewp@bigasterisk.com # Date 1365652369 25200 # Node ID 4e34fd9aee00fcd5f9dd8110271ada2309f2c387 # Parent cbc557c3512159a074d6676f804ea6fc26832039 refactor barcode part Ignore-this: 4bebdfdf7ab9f514f8eb02a833d2202b diff -r cbc557c35121 -r 4e34fd9aee00 service/starArduino/starArduino.py --- 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):