diff --git a/escpos/printer.py b/escpos/printer.py index dd5aa93..7cdedf3 100644 --- a/escpos/printer.py +++ b/escpos/printer.py @@ -128,9 +128,40 @@ class Network(Escpos): def _raw(self, msg): + """ Print any command sent in raw format """ self.device.send(msg) def __del__(self): """ Close TCP connection """ self.device.close() + + + +class File(Escpos): + """ Define Generic file printer """ + + def __init__(self, devfile="/dev/usb/lp0"): + """ + @param devfile : Device file under dev filesystem + """ + self.devfile = devfile + self.open() + + + def open(self): + """ Open system file """ + self.device = open(self.devfile, "wb") + + if self.device is None: + print "Could not open the specified file %s" % self.devfile + + + def _raw(self, msg): + """ Print any command sent in raw format """ + self.device.write(msg); + + + def __del__(self): + """ Close system file """ + self.device.close()