Skip to content

Commit

Permalink
Merge pull request #13 from BoboTiG/feat-check-status
Browse files Browse the repository at this point in the history
Add has_paper() to check paper availability
  • Loading branch information
luopio committed Feb 3, 2016
2 parents 96f5a97 + 6878273 commit 3e08735
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion printer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
#coding=utf-8

import serial, time
import serial, struct, time

#===========================================================#
# RASPBERRY PI (tested with Raspbian Jan 2012):
Expand Down Expand Up @@ -120,6 +120,7 @@ def sleep_after(self, seconds):
# Put the printer into a low-energy state after the given number
# of seconds.
if seconds:
time.sleep(seconds)
self.printer.write(self._ESC)
self.printer.write(chr(56))
self.printer.write(chr(seconds))
Expand All @@ -134,6 +135,19 @@ def wake(self):
self.printer.write(chr(0))
self.printer.write(chr(0))

def has_paper(self):
# Check the status of the paper using the printer's self reporting
# ability. SerialTX _must_ be connected!
self.printer.write(self._ESC)
self.printer.write(chr(118))
self.printer.write(chr(0))
status = -1
if self.printer.inWaiting() > 0:
ret = self.printer.read()
if ret:
status = struct.unpack('b', ret)[0]
return bool(status & 0b00000100)

def reset(self):
self.printer.write(self._ESC)
self.printer.write(chr(64))
Expand Down

0 comments on commit 3e08735

Please sign in to comment.