-
Notifications
You must be signed in to change notification settings - Fork 10
/
scanner.py
54 lines (41 loc) · 1.41 KB
/
scanner.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# Wrapper for LS2208 Barcode Scanner HID device, gently modified from Wiimode interface code
# --> http://code.google.com/p/pywiimote/
# MIT license
import HID
import sys
#from hid import AccessDeniedError, PathNotFoundError
# The scanner VID/PID change if neessary
VENDORID = 0x05e0
PRODUCTID = 0x1300
class Scanner(object):
""" this library is platform-independent but depends on the backend HID.py"""
def __init__(self, handle):
"""handle is an HIDDevice object """
self.handle = handle
#self.overlapped = overlapped
def read(self):
return self.handle.read(80)
def getBarcode(self):
readresult = self.read()
#print readresult
length = readresult[0]
if (length == 0):
return
reportdata = readresult[1]
reporttype = reportdata[0]
#print "Number of bytes read: ", length
#print "Buffer: "
#for x in range(length):
# print(reportdata[x]),
#print('\n')
barcode = ""
for x in range(5,length):
if (reportdata[x] == 0):
break
barcode += chr(reportdata[x])
return barcode
#self.printStatus()
def get_scanners():
"""Returns a collection of barcode scanner objects."""
targets = HID.OpenDevices(VENDORID,PRODUCTID)
return [Scanner(scanner) for scanner in targets ]