import re # noqa: F401 import socket # noqa: F401 import sys # noqa: F401 async def sent_to_printer(ctx: dict, data: str, address: str, cut_code: str): print(ctx, data, address, cut_code) try: with open(address, "w") as printer: printer.write(data) printer.write("\n") print(cut_code) printer.write(cut_code) except LookupError as e: print("Lookup error:", e) except: # noqa: E722 print("Unexpected error:", sys.exc_info()[0]) # GS = "\x1d" # PAPER_CUT = GS + "V" # # For the printer ESC/POS Reference # # https://reference.epson-biz.com/modules/ref_escpos/index.php?content_id=87 # # The m codes are in decimal and can be converted using the following table # # https://www.eso.org/~ndelmott/ascii.html # # The \x03 in all the following is to feed 3 lines before cut it can be increased or reduced # FUNCTION_B_FULL_CUT = "\x41\x03" # FUNCTION_B_PARTIAL_CUT = "\x42\x03"