py3-ecrterm/test_pt.py

47 lines
1.6 KiB
Python
Raw Normal View History

2017-06-14 15:26:03 +02:00
#!/usr/bin/env python
2013-07-29 16:49:55 +02:00
# -*- coding: utf-8 -*-
"""
Example script to demonstrate a payment process.
"""
import time
2018-04-22 02:47:48 +02:00
from ecrterm import ecr, packets, transmission
2013-07-29 16:49:55 +02:00
if __name__ == '__main__':
def printer(lines_of_text):
for line in lines_of_text:
2016-11-15 11:04:14 +01:00
print(line)
2013-07-29 16:49:55 +02:00
e = ecr.ECR(device='/dev/ttyUSB0')
# reenable logging:
e.transport.slog = ecr.ecr_log
2016-11-15 11:04:14 +01:00
print(e.detect_pt())
2013-07-29 16:49:55 +02:00
if e.detect_pt():
2017-06-14 15:26:03 +02:00
e.register(config_byte=packets.base_packets.Registration.generate_config(
ecr_prints_receipt=False,
ecr_prints_admin_receipt=False,
ecr_controls_admin=True,
ecr_controls_payment=True,))
2013-07-29 16:49:55 +02:00
status = e.status()
if status:
2016-11-15 11:04:14 +01:00
print("Status code of PT is %s" % status)
2013-07-29 16:49:55 +02:00
# laut doku sollte 0x9c bedeuten, ein tagesabschluss erfolgt
# bis jetzt unklar ob er es von selbst ausführt.
if status == 0x9c:
2016-11-15 11:04:14 +01:00
print("End Of Day")
2013-07-29 16:49:55 +02:00
e.end_of_day()
# last_printout() would work too:
printer(e.daylog)
else:
2016-11-15 11:04:14 +01:00
print("Unknown Status Code: %s" % status)
2013-07-29 16:49:55 +02:00
# status == 0xDC for ReadCard (06 C0) -> Karte drin. 0x9c karte draussen.
if e.payment(50):
printer(e.last_printout())
e.wait_for_status()
e.show_text(lines=['Auf Wiedersehen!', ' ', 'Zahlung erfolgt'], beeps=0)
else:
e.wait_for_status()
e.show_text(lines=['Auf Wiedersehen!', ' ', 'Vorgang abgebrochen'], beeps=1)