-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup-magtek-reader.py
executable file
·57 lines (45 loc) · 1.47 KB
/
setup-magtek-reader.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
55
56
57
#!/usr/bin/python
# The readers come from the factory in KB emulation mode, and will
# read all tracks if present. The factory omegas want them to only
# send track 2.
import magtek
import sys
if len(sys.argv) < 2:
print >>sys.stderr, "Usage: %s command"
sys.exit(1)
def info(r):
print "Reader mode: %s\nSoftware ID: %s\n" % (r.getMode(),
r.getSoftwareID())
def switchToKB(r):
r.setInterfaceType(magtek.MagTek.INTERFACE_TYPE_KB)
r.resetDevice()
def switchToHID(r):
r.setInterfaceType(magtek.MagTek.INTERFACE_TYPE_HID)
r.resetDevice()
def getTrackFormat(r):
print "Track Format:\n", r.getTrackFormat()
def enableTrack(r):
n = int(sys.argv.pop())
trackformat = reader.getTrackFormat()
trackformat.enableTrack(n)
reader.setTrackFormat(trackformat)
r.resetDevice()
def disableTrack(r):
n = int(sys.argv.pop())
trackformat = reader.getTrackFormat()
trackformat.disableTrack(n)
reader.setTrackFormat(trackformat)
r.resetDevice()
_cmdTable = { 'show': info,
'kbmode': switchToKB,
'hidmode': switchToHID,
'show-tracks': getTrackFormat,
'enable-track': enableTrack,
'disable-track': disableTrack }
if sys.argv[1] not in _cmdTable:
print >>sys.stderr, "Invalid command: %s" % sys.argv[0]
sys.exit(1)
print "Connecting to reader..."
reader = magtek.MagTek()
_cmdTable[sys.argv[1]](reader)
sys.exit(0)