2010-02-26 08:54:46 +00:00
|
|
|
""" ESC/POS Exceptions classes """
|
|
|
|
|
|
|
|
|
|
|
|
class Error(Exception):
|
|
|
|
""" Base class for ESC/POS errors """
|
|
|
|
def __init__(self, msg, status=None):
|
|
|
|
Exception.__init__(self)
|
|
|
|
self.msg = msg
|
|
|
|
self.resultcode = 1
|
|
|
|
if status is not None:
|
|
|
|
self.resultcode = status
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.msg
|
|
|
|
|
|
|
|
# Result/Exit codes
|
|
|
|
# 0 = success
|
|
|
|
# 10 = No Barcode type defined
|
|
|
|
# 20 = Barcode size values are out of range
|
|
|
|
# 30 = Barcode text not supplied
|
|
|
|
# 40 = Image height is too large
|
|
|
|
# 50 = No string supplied to be printed
|
|
|
|
# 60 = Invalid pin to send Cash Drawer pulse
|
2014-05-21 05:15:54 +00:00
|
|
|
# 70 = Invalid number of tab positions
|
|
|
|
# 80 = Invalid char code
|
2010-02-26 08:54:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
class BarcodeTypeError(Error):
|
2015-11-27 22:10:20 +00:00
|
|
|
"""No Barcode type defined """
|
2010-02-26 08:54:46 +00:00
|
|
|
def __init__(self, msg=""):
|
|
|
|
Error.__init__(self, msg)
|
|
|
|
self.msg = msg
|
|
|
|
self.resultcode = 10
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return "No Barcode type is defined"
|
|
|
|
|
2015-11-27 20:20:12 +00:00
|
|
|
|
2010-02-26 08:54:46 +00:00
|
|
|
class BarcodeSizeError(Error):
|
2015-11-27 22:10:20 +00:00
|
|
|
""" Barcode size is out of range """
|
2010-02-26 08:54:46 +00:00
|
|
|
def __init__(self, msg=""):
|
|
|
|
Error.__init__(self, msg)
|
|
|
|
self.msg = msg
|
|
|
|
self.resultcode = 20
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return "Barcode size is out of range"
|
|
|
|
|
2015-11-27 20:20:12 +00:00
|
|
|
|
2010-02-26 08:54:46 +00:00
|
|
|
class BarcodeCodeError(Error):
|
2015-11-27 22:10:20 +00:00
|
|
|
""" No Barcode code was supplied """
|
2010-02-26 08:54:46 +00:00
|
|
|
def __init__(self, msg=""):
|
|
|
|
Error.__init__(self, msg)
|
|
|
|
self.msg = msg
|
|
|
|
self.resultcode = 30
|
|
|
|
|
|
|
|
def __str__(self):
|
2015-11-27 22:10:20 +00:00
|
|
|
return "No Barcode code was supplied"
|
2010-02-26 08:54:46 +00:00
|
|
|
|
2015-11-27 20:20:12 +00:00
|
|
|
|
2010-02-26 08:54:46 +00:00
|
|
|
class ImageSizeError(Error):
|
2015-11-27 22:10:20 +00:00
|
|
|
""" Image height is longer than 255px and can't be printed """
|
2010-02-26 08:54:46 +00:00
|
|
|
def __init__(self, msg=""):
|
|
|
|
Error.__init__(self, msg)
|
|
|
|
self.msg = msg
|
|
|
|
self.resultcode = 40
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return "Image height is longer than 255px and can't be printed"
|
|
|
|
|
2015-11-27 20:20:12 +00:00
|
|
|
|
2010-02-26 08:54:46 +00:00
|
|
|
class TextError(Error):
|
2015-11-27 22:10:20 +00:00
|
|
|
""" Test sting must be supplied to the text() method """
|
2010-02-26 08:54:46 +00:00
|
|
|
def __init__(self, msg=""):
|
|
|
|
Error.__init__(self, msg)
|
|
|
|
self.msg = msg
|
|
|
|
self.resultcode = 50
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return "Text string must be supplied to the text() method"
|
|
|
|
|
|
|
|
|
|
|
|
class CashDrawerError(Error):
|
2015-11-27 22:10:20 +00:00
|
|
|
""" Valid pin must be set to send pulse """
|
2010-02-26 08:54:46 +00:00
|
|
|
def __init__(self, msg=""):
|
|
|
|
Error.__init__(self, msg)
|
|
|
|
self.msg = msg
|
|
|
|
self.resultcode = 60
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return "Valid pin must be set to send pulse"
|
2014-05-21 05:15:54 +00:00
|
|
|
|
|
|
|
|
2015-11-27 20:38:59 +00:00
|
|
|
class TabPosError(Error):
|
2015-11-27 22:10:20 +00:00
|
|
|
""" Valid tab positions must be in the range 0 to 16 """
|
2014-05-21 05:15:54 +00:00
|
|
|
def __init__(self, msg=""):
|
|
|
|
Error.__init__(self, msg)
|
|
|
|
self.msg = msg
|
|
|
|
self.resultcode = 70
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return "Valid tab positions must be in the range 0 to 16"
|
|
|
|
|
|
|
|
|
|
|
|
class CharCodeError(Error):
|
2015-11-27 22:10:20 +00:00
|
|
|
""" Valid char code must be set """
|
2014-05-21 05:15:54 +00:00
|
|
|
def __init__(self, msg=""):
|
|
|
|
Error.__init__(self, msg)
|
|
|
|
self.msg = msg
|
|
|
|
self.resultcode = 70
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return "Valid char code must be set"
|