/
server.py
54 lines (45 loc) · 1.57 KB
/
server.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
import serial
import eventlet
from eventlet import wsgi
import httplib
import ftplib
import urllib
import SocketServer
import BaseHTTPServer
from vmax import Vmax
class PosPrintServer(object):
def __init__(self):
self.impresora = Vmax()
def bridge(self, env, start_response):
print "atendiendo:",env['PATH_INFO']
comando= env['PATH_INFO'][1:].split("___")
if comando[0] == 'RESET':
print "Enviando comando de RESET"
self.impresora.reset()
if comando[0] == 'ABRIR1':
print "Abriendo comprobante fiscal"
self.impresora.abrir_comprobante_fiscal()
if comando[0] == 'PRODUCTO':
print "Enviando producto"
self.impresora.abrir_comprobante_fiscal()
self.impresora.venta_articulo(comando[1],comando[2])
if comando[0] == 'SUBTOTAL':
print "Enviando Subtotal"
self.impresora.subtotal()
if comando[0] == 'PAGO':
print "Enviando pago"
self.impresora.pago(comando[1],comando[2])
if comando[0] == 'CERRAR1':
print "Cerrando comprobante"
self.impresora.cerrar_comprobante()
if comando[0] == 'GAVETA':
print "Abriendo gaveta"
self.impresora.gaveta()
start_response('200 OK', [('Content-Type', 'text/plain')])
return ['OK\r\n']
def run(self):
wsgi.server(eventlet.listen(('', 8200)), self.bridge)
self.ser.close()
if __name__ == "__main__":
pos_printer_server = PosPrintServer()
pos_printer_server.run()