make sleep configurable
This commit is contained in:
parent
88b7e48186
commit
c613a78634
@ -213,6 +213,14 @@ If something is wrong, an ``CharCodeError`` will be raised.
|
|||||||
After you have manually set the codepage the printer won't change it anymore.
|
After you have manually set the codepage the printer won't change it anymore.
|
||||||
You can revert to normal behavior by setting charcode to ``AUTO``.
|
You can revert to normal behavior by setting charcode to ``AUTO``.
|
||||||
|
|
||||||
|
Resolving bus timeout issues during printing images
|
||||||
|
---------------------------------------------------
|
||||||
|
|
||||||
|
If an error message such as "USBTimeoutError: [Errno 110] Operation timed out" occurs,
|
||||||
|
setting a sleep time between printing fragments can help.
|
||||||
|
|
||||||
|
This can be done with the :meth:`.set_sleep_in_fragment()` method.
|
||||||
|
|
||||||
Advanced Usage: Print from binary blob
|
Advanced Usage: Print from binary blob
|
||||||
--------------------------------------
|
--------------------------------------
|
||||||
|
|
||||||
|
@ -124,6 +124,9 @@ class Escpos(object, metaclass=ABCMeta):
|
|||||||
# object -> The connection object (Usb(), Serial(), Network(), etc.)
|
# object -> The connection object (Usb(), Serial(), Network(), etc.)
|
||||||
_device: Union[Literal[False], Literal[None], object] = False
|
_device: Union[Literal[False], Literal[None], object] = False
|
||||||
|
|
||||||
|
# sleep time in fragments:
|
||||||
|
_sleep_in_fragment_ms: int = 0
|
||||||
|
|
||||||
def __init__(self, profile=None, magic_encode_args=None, **kwargs) -> None:
|
def __init__(self, profile=None, magic_encode_args=None, **kwargs) -> None:
|
||||||
"""Initialize ESCPOS Printer.
|
"""Initialize ESCPOS Printer.
|
||||||
|
|
||||||
@ -179,6 +182,21 @@ class Escpos(object, metaclass=ABCMeta):
|
|||||||
"""
|
"""
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
def set_sleep_in_fragment(self, sleep_time_ms: int) -> None:
|
||||||
|
"""Configures the currently active sleep time after sending a fragment.
|
||||||
|
|
||||||
|
If during printing an image an issue like "USBTimeoutError: [Errno 110]
|
||||||
|
Operation timed out" occurs, setting this value to roughly 300
|
||||||
|
milliseconds can help resolve the issue.
|
||||||
|
|
||||||
|
:param sleep_time_ms: sleep time in milliseconds
|
||||||
|
"""
|
||||||
|
self._sleep_in_fragment_ms = sleep_time_ms
|
||||||
|
|
||||||
|
def _sleep_in_fragment(self) -> None:
|
||||||
|
"""Sleeps the preconfigured time after sending a fragment."""
|
||||||
|
time.sleep(self._sleep_in_fragment_ms / 1000)
|
||||||
|
|
||||||
def image(
|
def image(
|
||||||
self,
|
self,
|
||||||
img_source,
|
img_source,
|
||||||
@ -247,7 +265,7 @@ class Escpos(object, metaclass=ABCMeta):
|
|||||||
impl=impl,
|
impl=impl,
|
||||||
fragment_height=fragment_height,
|
fragment_height=fragment_height,
|
||||||
)
|
)
|
||||||
time.sleep(0.3)
|
self._sleep_in_fragment()
|
||||||
return
|
return
|
||||||
|
|
||||||
if impl == "bitImageRaster":
|
if impl == "bitImageRaster":
|
||||||
|
Loading…
x
Reference in New Issue
Block a user