diff --git a/tools/printfile.py b/tools/printfile.py new file mode 100644 index 0000000..d6c4ffc --- /dev/null +++ b/tools/printfile.py @@ -0,0 +1,76 @@ +#! /usr/bin/env python3 +import serial +import codecs + +import argparse + + +serialdevice='/dev/ttyUSB0' + + + +chars=" qwertzuiopü+asdfghjklöä#yxcvbnm,.-QWERTZUIOPÜ*ASDFGHJKLÖÄ'YXCVBNM;:_1234567890ß!\"§$%&/()=?" + + + +''' +Teilung 10: 65 +Teilung 12: 78 +Teilung 15: 97 +''' + +def main(): + parser = argparse.ArgumentParser(description='Send Textfile over serial') + parser.add_argument('filename', help="file to print") + parser.add_argument('-d', '--device', nargs='?', help="serial device name") + parser.add_argument('-l', '--length', nargs='?', type=int, help="maximum line length") + parser.add_argument('-x','--dryrun', action="store_true", help="do not send anything to printer") + + args = parser.parse_args() + + charsperline=65 + if args.length is not None: + charsperline=int(args.length) + print("args.length: "+str(args.length)) + print("Checking for maximum line length: "+str(charsperline)) + + + filename=args.filename + if args.device is not None: + serialdevice=args.device + + lines=[] + + with codecs.open(filename, encoding='utf-8') as file: + lines=file.readlines() + + lines=[x.rstrip() for x in lines] # remove whitespaces and linebreaks + + for iline,line in enumerate(lines): + if not set(line).issubset(chars): + print(str(iline)+":"+str(line)) + print("Contains non printable characters") + exit() + if len(line)>charsperline: + print(str(iline)+":"+str(line)) + print("Line is too long." +str(len(line))+">"+str(charsperline)) + exit() + + if (args.dryrun): + print("Dry Run enabled. Exiting") + exit() + + with serial.Serial(serialdevice, 9600, timeout=1) as ser: + + for line in lines: + print(line) + ser.write(line.encode()) + ser.write(b'\n') + + + + + + +if __name__ == "__main__": + main() diff --git a/tools/test_keyboard.py b/tools/test_keyboard.py index 91682ae..ef07c94 100644 --- a/tools/test_keyboard.py +++ b/tools/test_keyboard.py @@ -1,10 +1,13 @@ #! /usr/bin/env python3 import serial +#serialdevice='/dev/ttyUSB0' +serialdevice='COM3' + chars=" qwertzuiopü+asdfghjklöä#yxcvbnm,.-QWERTZUIOPÜ*ASDFGHJKLÖÄ'YXCVBNM;:_1234567890ß!\"§$%&/()=?" def main(): - with serial.Serial('/dev/ttyUSB0', 9600, timeout=1) as ser: + with serial.Serial(serialdevice, 9600, timeout=1) as ser: print("ZWÖLF BOXKÄMPFER JAGEN VIKTOR QUER ÜBER DEN GROßEN SYLTER DEICH.")