import md5
import openerp.addons.hw_proxy.controllers.main as hw_proxy
import subprocess
-from threading import Thread
+from threading import Thread, Lock
from Queue import Queue, Empty
try:
def __init__(self):
Thread.__init__(self)
self.queue = Queue()
+ self.lock = Lock()
self.status = {'status':'connecting', 'messages':[]}
def connected_usb_devices(self):
if usb.core.find(idVendor=device['vendor'], idProduct=device['product']) != None:
connected.append(device)
return connected
+
+ def lockedstart(self):
+ self.lock.acquire()
+ if not self.isAlive():
+ self.start()
+ self.lock.release()
def get_escpos_printer(self):
try:
_logger.error(e);
def push_task(self,task, data = None):
- if not self.isAlive():
- self.start()
+ self.lockedstart()
self.queue.put((time.time(),task,data))
def print_receipt_body(self,eprint,receipt):
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()
+