forked from eighthave/MPOST_Linux_python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmpost.py
More file actions
executable file
·146 lines (118 loc) · 4.43 KB
/
mpost.py
File metadata and controls
executable file
·146 lines (118 loc) · 4.43 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/env python2.6
import time
import sys
from ctypes import *
class MPOST():
'''
class for receiving info from an MEI Bill Acceptor following the MEI Point
of Service Toolkit (MPOST)
'''
instances = 0 # count of instances for referencing C++ CAcceptor struct
# all available event types
(Events_Begin,
ConnectedEvent,
EscrowEvent,
PUPEscrowEvent,
StackedEvent,
ReturnedEvent,
RejectedEvent,
CheatedEvent,
StackerFullEvent,
CalibrateStartEvent,
CalibrateProgressEvent,
CalibrateFinishEvent,
DownloadStartEvent,
DownloadRestartEvent,
DownloadProgressEvent,
DownloadFinishEvent,
PauseDetectedEvent,
PauseClearedEvent,
StallDetectedEvent,
StallClearedEvent,
JamDetectedEvent,
JamClearedEvent,
PowerUpEvent,
InvalidCommandEvent,
CashBoxAttachedEvent,
CashBoxRemovedEvent,
DisconnectedEvent,
Events_End) = map(c_int, xrange(28))
CALLBACK = CFUNCTYPE(None, c_int, c_char_p)
MAX_INSTANCES = 16
cdll.LoadLibrary('./libpympost.so')
clib = CDLL('./libpympost.so')
def __init__(self):
if MPOST.instances < MPOST.MAX_INSTANCES:
self.instance = MPOST.instances
MPOST.clib.mpost_setup(self.instance)
MPOST.instances += 1
else:
raise Exception('No more instances, max: ', str(MPOST.MAX_INSTANCES))
def open(self, tty='/dev/ttyUSB0'):
'''open the connection to the device'''
MPOST.clib.mpost_open(self.instance, tty)
def close(self):
'''close the connection to the device'''
MPOST.clib.mpost_close(self.instance)
def returnbill(self):
'''return the bill currently sitting in escrow'''
MPOST.clib.mpost_return(self.instance)
def acceptbills(self, boolean):
'''set whether the acceptor will take bills or not'''
MPOST.clib.mpost_acceptbills(self.instance, boolean)
def autostack(self, boolean):
'''set whether the acceptor should automatically stack the bills and
skip the escrow'''
MPOST.clib.mpost_autostack(self.instance, boolean)
def setcallback(self, event, callback):
'''attach a callback function to an event type. The callback function
should have two parameters: a int value and a string for data'''
MPOST.clib.mpost_setcallback(self.instance, event, callback)
#------------------------------------------------------------------------------#
# for testing from the command line:
def main(argv):
connectedcallback = MPOST.CALLBACK(connected)
disconnectedcallback = MPOST.CALLBACK(disconnected)
escrowcallback = MPOST.CALLBACK(escrow)
stackedcallback = MPOST.CALLBACK(stacked)
returnedcallback = MPOST.CALLBACK(returned)
stackerfullcallback = MPOST.CALLBACK(stackerfull)
mpost0 = MPOST()
mpost0.open('/dev/loc-bill-ttyUSB0')
mpost0.setcallback(MPOST.ConnectedEvent, connectedcallback)
mpost0.setcallback(MPOST.DisconnectedEvent, disconnectedcallback)
mpost0.setcallback(MPOST.EscrowEvent, escrowcallback)
mpost0.setcallback(MPOST.StackedEvent, stackedcallback)
mpost0.setcallback(MPOST.ReturnedEvent, returnedcallback)
mpost0.setcallback(MPOST.StackerFullEvent, stackerfullcallback)
mpost1 = MPOST()
mpost1.open('/dev/loc-bill-ttyUSB1')
mpost1.setcallback(MPOST.ConnectedEvent, connectedcallback)
mpost1.setcallback(MPOST.DisconnectedEvent, disconnectedcallback)
mpost1.setcallback(MPOST.EscrowEvent, escrowcallback)
mpost1.setcallback(MPOST.StackedEvent, stackedcallback)
mpost1.setcallback(MPOST.ReturnedEvent, returnedcallback)
mpost1.setcallback(MPOST.StackerFullEvent, stackerfullcallback)
mpost0.acceptbills(True)
mpost1.acceptbills(True)
time.sleep(20)
mpost0.returnbill()
mpost1.returnbill()
time.sleep(2)
mpost0.close()
mpost1.close()
if __name__ == "__main__":
# event callbacks, not all events are implemented...
def connected(value, datastr):
print('connected: ' + datastr)
def disconnected(value, datastr):
print('disconnected: ' + datastr)
def escrow(value, datastr):
print('escrow: ' + datastr)
def stacked(value, datastr):
print('stacked: ' + datastr)
def returned(value, datastr):
print('returned: ' + datastr)
def stackerfull(value, datastr):
print('stackerfull: ' + datastr)
main(sys.argv[1:])