Subscribe to the RSS feed by copy/paste the link below
RSS

Wasp Scanner Simplified

Posted by Admin on 11. March, 2022
MyBlog ยป

Using my Wasp barcode scanner in Python3.

Originally the code at https://github.com/EvansMike/librarian used a very convoluted method to find and use the scanner. This week I simplified the code to use the hid module and imporved the

I've made it even better.  Uses evdev instead of hid to the import has to be changed.

All this is a great deal simpler than the original and the updated code. See the changelog for why.

def real_scanner(self):
        '''
        This will run when a real scanner is attached
        '''
        barcode = ""
        print ("Reading barcodes from device")
        while True:
            try:
                event = self.scanner.read_one()
            except:
                return
            if event != None:
                if event.type == evdev.ecodes.EV_KEY and event.value == 1:
                    keycode = categorize(event).keycode
                    #DEBUG(keycode)
                    if keycode == 'KEY_ENTER':
                        #DEBUG(barcode)
                        #DEBUG(barcodenumber.check_code_upc(barcode))
                        #DEBUG(barcodenumber.check_code_isbn(barcode))
                        #DEBUG(barcodenumber.check_code_ean13(barcode))
                        if barcodenumber.check_code_isbn(barcode):
                            self.add_book(None, barcode)
                            break
                        elif barcodenumber.check_code_ean13(barcode):
                            self.add_dvd(None, barcode)
                            INFO("Not an ISBN, a DVD or CD perhaps")
                            break
                    else:
                        barcode += keycode[4:]
        return
 

Last changed: 11. March, 2022 at 13:18

Back to Overview