import time
from os import listdir
from os.path import join
-from threading import Thread
+from threading import Thread, Lock
from select import select
from Queue import Queue, Empty
class Scanner(Thread):
def __init__(self):
Thread.__init__(self)
+ self.lock = Lock()
self.status = {'status':'connecting', 'messages':[]}
self.input_dir = '/dev/input/by-id/'
self.barcodes = Queue()
57:(" "," "),
}
+ def lockedstart(self):
+ self.lock.acquire()
+ if not self.isAlive():
+ self.start()
+ self.lock.release()
+
def set_status(self, status, message = None):
if status == self.status['status']:
if message != None and message != self.status['messages'][-1]:
elif status == 'disconnected' and message:
_logger.warning('Disconnected Barcode Scanner: '+message)
-
-
def get_device(self):
try:
if not evdev:
busy reading another barcode
"""
+ self.lockedstart()
+
while True:
try:
timestamp, barcode = self.barcodes.get(True, 5)
return ''
def get_status(self):
- if not s.isAlive():
- s.start()
+ self.lockedstart()
return self.status
def run(self):
class ScannerDriver(hw_proxy.Proxy):
@http.route('/hw_proxy/scanner', type='json', auth='none', cors='*')
def scanner(self):
- if not s.isAlive():
- s.start()
return s.get_barcode()
+