Mercurial > code > home > repos > homeauto
comparison service/starArduino/starArduino.py @ 66:4e34fd9aee00
refactor barcode part
Ignore-this: 4bebdfdf7ab9f514f8eb02a833d2202b
author | drewp@bigasterisk.com |
---|---|
date | Wed, 10 Apr 2013 20:52:49 -0700 |
parents | 0ab069867c64 |
children | 80efeab5c02f |
comparison
equal
deleted
inserted
replaced
65:cbc557c35121 | 66:4e34fd9aee00 |
---|---|
59 ser = self.settings.arduino.ser | 59 ser = self.settings.arduino.ser |
60 ser.write("\x60\x03") | 60 ser.write("\x60\x03") |
61 self.write(str(ser.readJson())) | 61 self.write(str(ser.readJson())) |
62 | 62 |
63 def barcodeWatch(arduino, postBarcode): | 63 def barcodeWatch(arduino, postBarcode): |
64 try: | 64 arduino.ser.write("\xff\xfb") |
65 arduino.ser.write("\xff\xfb") | 65 ret = arduino.readJson() |
66 ret = arduino.readJson() | 66 if not ret['barcode']: |
67 if ret['barcode']: | 67 return |
68 if ret['barcode'] == "27 80 48 13 ": | 68 if ret['barcode'] == "27 80 48 13 ": |
69 pass # scanner's beep response | 69 return # scanner's beep response |
70 else: | |
71 arduino.ser.write("\xff\xfc") | |
72 arduino.readJson() # my beep response | |
73 s = ''.join(chr(int(x)) for x in ret['barcode'].split()) | |
74 for code in s.split('\x02'): | |
75 if not code: | |
76 continue | |
77 if not code.endswith('\x03'): | |
78 print "couldn't read %r" % code | |
79 return | |
80 codeType = {'A':'UPC-A', | |
81 'B':'JAN-8', | |
82 'E':'UPC-E', | |
83 'N':'NW-7', | |
84 'C':'CODE39', | |
85 'I':'ITF', | |
86 'K':'CODE128', | |
87 }[code[0]] | |
88 code = code[1:-1] | |
89 postBarcode.post(payload=json.dumps( | |
90 {'barcodeType':codeType, 'code':code}), | |
91 headers={"content-type" : | |
92 "application/json"}) | |
93 | 70 |
94 except ValueError, e: | 71 arduino.ser.write("\xff\xfc") |
95 print "err", e | 72 arduino.readJson() # my beep response |
73 s = ''.join(chr(int(x)) for x in ret['barcode'].split()) | |
74 for code in s.split('\x02'): | |
75 if not code: | |
76 continue | |
77 if not code.endswith('\x03'): | |
78 print "couldn't read %r" % code | |
79 return | |
80 codeType = {'A':'UPC-A', | |
81 'B':'JAN-8', | |
82 'E':'UPC-E', | |
83 'N':'NW-7', | |
84 'C':'CODE39', | |
85 'I':'ITF', | |
86 'K':'CODE128', | |
87 }[code[0]] | |
88 code = code[1:-1] | |
89 try: | |
90 postBarcode.post(payload=json.dumps( | |
91 {'barcodeType':codeType, 'code':code}), | |
92 headers={"content-type" : | |
93 "application/json"}) | |
94 except Exception, e: | |
95 print "post err", e | |
96 | 96 |
97 | 97 |
98 class Graph(PrettyErrorHandler, cyclone.web.RequestHandler): | 98 class Graph(PrettyErrorHandler, cyclone.web.RequestHandler): |
99 def get(self): | 99 def get(self): |
100 raise NotImplementedError | 100 raise NotImplementedError |