コード例 #1
0
ファイル: main.py プロジェクト: nnscr/pi-timetracker
    def search_scanner(self):
        """ Called from the scanner thread, this will keep searching for a barcode scanner until it is found. """
        self.scanner = None

        while self.scanner is None:
            sleep(1)
            self.scanner = BarcodeScanner.get_scanner()

            if self.quit_event.isSet():
                return

        self.add_event((self.EVENT_DEVICE, "plugged_in"))
コード例 #2
0
ファイル: main.py プロジェクト: nnscr/pi-timetracker
    def __init__(self, settings, lcd):
        self.settings = settings
        self.lcd = lcd
        self.sel = NumberSelector(self.lcd)
        self.sel.callback = self.select_packer_callback
        self.menu = Menu(self.lcd)
        self.menu.callback = self.menu_callback
        self.scanner = BarcodeScanner.get_scanner()
        self.mode = self.MODE_SELECT_PACKER

        self.terminal_id = self.settings.get("terminal")

        self.ws = Webservice(self.settings.get("url"))
        self.ws.token = self.settings.get("token")
        self.ws.username = self.settings.get("username")
        self.ws.password = self.settings.get("password")

        self.scanner_thread = Thread(target=self.scanner_thread, name="scanner_thread")
        self.buttons_thread = Thread(target=self.buttons_thread, name="buttons_thread")
        self.timer_thread = Thread(target=self.timer_thread, name="timer_thread")
        self.scanner_thread.daemon = True
        self.buttons_thread.daemon = True
        self.timer_thread.daemon = True

        self.lock = Lock()
        self.semaphore = Semaphore()
        self.timer_event = Event()
        self.quit_event = Event()

        self.event_stack = list()

        # Tracking status variables
        self.packer_id = None
        self.invoice = None
        self.start_time = None
        self.order_info = None

        # Saved previous modes for special cases
        self.previous_mode_menu = None
コード例 #3
0
def handle_barcode(db, data):
    if data.startswith("@"):
        license_data = decode_pdf417(data)
        db.reg_set('license_data', license_data)
    else:
        db.reg_set('barcode_data', data)
        handle_next_entry(db, data)


#######################################

if __name__ == '__main__':
    logging.warning("start barcode scanner mule")
    db = get_db()
    log = logging.getLogger('barcode_scanner_mule')
    scanner = BarcodeScanner()
    open_state = True
    port = None

    poll_time = 0
    while True:
        if poll_time < time():
            poll_time = time() + DB_POLL_INTERVAL
            port = db.reg_get('serial_port_barcode')

        if scanner.is_open() and scanner.port != port:
            scanner.close()
        elif scanner.is_open():
            barcode_data = scanner.read()
            if barcode_data is not None:
                handle_barcode(db, barcode_data)
コード例 #4
0
def handle_barcode(db, data):
  if data.startswith("@"):
    license_data = decode_pdf417(data)
    db.reg_set('license_data', license_data)
  else:
    db.reg_set('barcode_data', data)
    handle_next_entry(db, data)

#######################################

if __name__ == '__main__':
  logging.warning("start barcode scanner mule")
  db = get_db()
  log = logging.getLogger('barcode_scanner_mule')
  scanner = BarcodeScanner()
  open_state = True
  port = None
  
  poll_time = 0
  while True:
    if poll_time < time():
      poll_time = time() + DB_POLL_INTERVAL
      port = db.reg_get('serial_port_barcode')

    if scanner.is_open() and scanner.port != port:
      scanner.close()
    elif scanner.is_open():
      barcode_data = scanner.read()
      if barcode_data is not None:
        handle_barcode(db, barcode_data)
コード例 #5
0
ファイル: client.py プロジェクト: nnscr/pi-timetracker
#!/usr/bin/python
# coding=utf-8
from CharLCDPlate import NumberSelector, CharLCDPlate
from gaia.webservice.Webservice import Webservice
from gaia.webservice.Settings import Settings
from time import sleep
from barcode_scanner import BarcodeScanner


# Configuration
settings = Settings()
lcd = CharLCDPlate()
sel = NumberSelector(lcd)
scanner = BarcodeScanner.find_scanner()

# Create webservice and set last token from configuration
ws = Webservice(settings.get("url"))
ws.token = settings.get("token")
ws.username = settings.get("username")
ws.password = settings.get("password")


def packer_selected_callback(ws):
    def callback(sel, number):
        result = ws.call("Packaging", "getPackerInfo", {"packerId": number})
        print(result)

        lcd.clear()

        if result["_success"]:
            lcd.message("Hallo,\n%s!" % result["name"].encode("ascii", "replace"))