You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
k4ever/client-barcode/display.py

75 lines
1.7 KiB

import serial
class Display:
def __init__(self,portname="/dev/ttyUSB0"):
self.serialport=None
self.open_port(portname)
def __del__(self):
if (not self.serialport == None):
self.serialport.close()
self.serialport=None
def open_port(self,portname):
self.serialport = serial.Serial(portname,9600,timeout=2,rtscts=True, dsrdtr=True)
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 write(self,text):
self.serialport.write(text)