From 0aad574f600f37f08faae603952a4f9644aa92a8 Mon Sep 17 00:00:00 2001 From: Florian Streibelt Date: Tue, 18 Oct 2011 19:23:14 +0200 Subject: [PATCH] commands converted from C-program to python, now replacing all calls accordingly --- client-barcode/display.py | 65 +++++++++++++++++++++++++++++---- client-barcode/freitagskasse.py | 2 +- 2 files changed, 58 insertions(+), 9 deletions(-) diff --git a/client-barcode/display.py b/client-barcode/display.py index 6e2702e..59ad56d 100644 --- a/client-barcode/display.py +++ b/client-barcode/display.py @@ -1,8 +1,9 @@ import serial + + class Display: def __init__(self,portname="/dev/ttyUSB0"): - #code here self.serialport=None self.open_port(portname) @@ -13,13 +14,61 @@ class Display: def open_port(self,portname): self.serialport = serial.Serial(portname,9600,timeout=2,rtscts=True, dsrdtr=True) - self.reset_display() - self.send("Hello world") + print ("Initializing display:\n %s\n" % self.serialport ) + self.cmd_reset() + self.write("Hello world") + + def cmd_reset(self): + #reset the display + self.write("\x1b\x40") + + def cmd_cursor_show(self,on=True): + #show or hide the cursor + if (on): + self.write("\x1f\x43\x01") + else: + self.write("\x1f\x43\x00") + + def cmd_blink(self,rate=127): + self.write("\x1f\x45%c" % rate) + + def cmd_display_on(self,on=True): + # blink-command: + # where the last value defines the blink rate, + # with 0=always on, 255=always off + if (on): + self.cmd_blink(0) + else: + self.cmd_blink(255) + + def cmd_curmode_overwrite(self): + cmd_curmode(1) + + def cmd_curmode_vscroll(self): + cmd_curmode(2) + + def cmd_curmode_hscroll(self): + cmd_curmode(3) + + def cmd_curmode(self,val=2): + self.write("\x1f%c" % val) + + def cmd_clear(self): + self.write("\x0c") + + + def cmd_time(self): + # activate timer display in lower right corner. + # actual time has to be set via display_set_timer. + self.write("\x1f\x55") + + def cmd_time_set(self,h,m): + # configures hour and minutes of the internal clock and + # displays the time in the lower right corner. + # turns off when something gets written into the line. + # two bytes have to follow with hour and minute + self.write("\x1F\x54%c%c" % (h,m) ) - def reset_display(self): - print ("Initializing display on port %s\n" % self.serialport ) - #code here - - def send(self,text): + def write(self,text): self.serialport.write(text) diff --git a/client-barcode/freitagskasse.py b/client-barcode/freitagskasse.py index 681cba0..d8ce0ba 100644 --- a/client-barcode/freitagskasse.py +++ b/client-barcode/freitagskasse.py @@ -581,7 +581,7 @@ def main(): global myDisplay myDisplay = Display("/dev/ttyUSB0") - myDisplay.reset_display() + myDisplay.cmd_reset() print_display("\x1b\x40\x1f\x43\x00") start_new_thread(display_thread,(1,))