From 5422dc2b011a68ae6c0144025376c466f79b6f10 Mon Sep 17 00:00:00 2001 From: longuyen Date: Fri, 17 Apr 2026 10:51:52 -0700 Subject: [PATCH 01/20] Update reliance connection setup --- Printer/reliance_printer.py | 23 +++++++++++++++++++---- commands.py | 10 ++++++---- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/Printer/reliance_printer.py b/Printer/reliance_printer.py index 4398b79..f309024 100644 --- a/Printer/reliance_printer.py +++ b/Printer/reliance_printer.py @@ -1,11 +1,26 @@ from Printer import base_printer import time +from commands import RelianceCommands + class ReliancePrinter(base_printer.BasePrinter): def __init__(self, port): - super().__init__(port, 9600) - self.ser.dtr = True - self.ser.rts = True + super().__init__(port, 19200) time.sleep(1) - self.ser.reset_input_buffer() \ No newline at end of file + self.ser.reset_input_buffer() + + def verify_logic_link(self): + self.ser.reset_input_buffer() + self.ser.write(RelianceCommands.REAL_TIME_STATUS + RelianceCommands.RT_OFFLINE) + time.sleep(0.25) + + print(f"Bytes waiting: {self.ser.in_waiting}") + if self.ser.in_waiting > 0: + res = self.ser.read(1)[0] + if res == 0xAC: + return "CONNECTED_BUT_MANGLED (Check Parity/Stop Bits)" + + is_online = res == 0x08 + return "ONLINE" if is_online else "OFFLINE" + return "NO_RESPONSE" \ No newline at end of file diff --git a/commands.py b/commands.py index 12a6d19..e651431 100644 --- a/commands.py +++ b/commands.py @@ -23,6 +23,11 @@ class Commands: CENTER = b'\x01' RIGHT = b'\x02' + RT_PRINTER = b'\x01' + RT_OFFLINE = b'\x02' + RT_ERROR = b'\x03' + RT_PAPER = b'\x04' + class PhoenixCommands(Commands): SELECT_FONT_A = b'\x1b\x50' SELECT_FONT_B = b'\x1b\x54' @@ -37,10 +42,7 @@ class PhoenixCommands(Commands): TOGGLE_AUTO_CUT = b'\x1c\x7d\x60' DYNAMIC_2D_BARCODE = b'\x1d\x28\x6b' PRINT_REAL_TIME_CLOCK = b'\x1c\x7d\x70' - RT_PRINTER = b'\x01' - RT_OFFLINE = b'\x02' - RT_ERROR = b'\x03' - RT_PAPER = b'\x04' + # Actions TEST_COIN_IN = b'\x60' From 54d4fd73efd267c4427737c27a3dc09a3d6a72ed Mon Sep 17 00:00:00 2001 From: longuyen Date: Fri, 17 Apr 2026 11:55:14 -0700 Subject: [PATCH 02/20] Add printer identifier --- Menu/main_menu.py | 7 +++++-- Printer/base_printer.py | 2 +- Printer/phoenix_printer.py | 3 ++- Printer/reliance_printer.py | 4 ++-- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Menu/main_menu.py b/Menu/main_menu.py index 04bd129..6899525 100644 --- a/Menu/main_menu.py +++ b/Menu/main_menu.py @@ -53,6 +53,9 @@ def run(self): console.print("[bold red]Failed to connect to printer. Exiting.[/bold red]") return + self.phoenix_menu() + + def phoenix_menu(self): while True: menu_text = ( "1. [bold cyan]Print Menu[/bold cyan] (Text, Font, Style)\n" @@ -69,9 +72,9 @@ def run(self): self.printer.close() break - self.handle_choice(choice) + self.phoenix_handle_choice(choice) - def handle_choice(self, choice): + def phoenix_handle_choice(self, choice): if choice == "1": PrintMenu(self.printer) elif choice == "2": diff --git a/Printer/base_printer.py b/Printer/base_printer.py index 1caeb51..29fa45d 100644 --- a/Printer/base_printer.py +++ b/Printer/base_printer.py @@ -10,7 +10,7 @@ def __init__(self, port, baudrate): parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, ) - + self.printer_type = "BasePrinter" time.sleep(1) self.ser.reset_input_buffer() self.ser.reset_output_buffer() diff --git a/Printer/phoenix_printer.py b/Printer/phoenix_printer.py index ecb1dad..376d0c7 100644 --- a/Printer/phoenix_printer.py +++ b/Printer/phoenix_printer.py @@ -1,6 +1,6 @@ from Printer import base_printer -import time from commands import PhoenixCommands +import time ## @class PhoenixPrinter # @brief Implementation for the Pyramid Phoenix Thermal Printer. @@ -9,6 +9,7 @@ class PhoenixPrinter(base_printer.BasePrinter): def __init__(self, port): super().__init__(port, 9600) + self.printer_type = "PhoenixPrinter" time.sleep(1) self.ser.reset_input_buffer() diff --git a/Printer/reliance_printer.py b/Printer/reliance_printer.py index f309024..ee24e4f 100644 --- a/Printer/reliance_printer.py +++ b/Printer/reliance_printer.py @@ -1,11 +1,11 @@ from Printer import base_printer -import time - from commands import RelianceCommands +import time class ReliancePrinter(base_printer.BasePrinter): def __init__(self, port): super().__init__(port, 19200) + self.printer_type = "ReliancePrinter" time.sleep(1) self.ser.reset_input_buffer() From 9e6cd028c46e622cae347d90a9f86c19a263075d Mon Sep 17 00:00:00 2001 From: longuyen Date: Mon, 20 Apr 2026 15:26:58 -0700 Subject: [PATCH 03/20] Add a switch on send command for specific printer --- Menu/main_menu.py | 16 +++++++------- Printer/base_printer.py | 5 ++++- Sample_Codes/Phoenix/1_sample_connection.py | 7 ++++-- .../Phoenix/2_sample_print_command.py | 10 ++++----- Sample_Codes/Phoenix/3_sample_font_control.py | 22 ++++++------------- Sample_Codes/Phoenix/4_sample_positioning.py | 15 ++----------- 6 files changed, 30 insertions(+), 45 deletions(-) diff --git a/Menu/main_menu.py b/Menu/main_menu.py index 6899525..1bb8a6c 100644 --- a/Menu/main_menu.py +++ b/Menu/main_menu.py @@ -53,9 +53,9 @@ def run(self): console.print("[bold red]Failed to connect to printer. Exiting.[/bold red]") return - self.phoenix_menu() + self.menu() - def phoenix_menu(self): + def menu(self): while True: menu_text = ( "1. [bold cyan]Print Menu[/bold cyan] (Text, Font, Style)\n" @@ -72,9 +72,9 @@ def phoenix_menu(self): self.printer.close() break - self.phoenix_handle_choice(choice) + self.handle_choice(choice) - def phoenix_handle_choice(self, choice): + def handle_choice(self, choice): if choice == "1": PrintMenu(self.printer) elif choice == "2": @@ -107,14 +107,14 @@ def handle_raw_input(self): console.print(f"Printer response: [green]00[/green]") def display_commands(self): - is_phoenix = "Phoenix" in str(type(self.printer)) - phoenix_cmds = PhoenixCommands if is_phoenix else RelianceCommands + is_phoenix = self.printer.get_type() == "PhoenixPrinter" + cmds = PhoenixCommands if is_phoenix else RelianceCommands - table = Table(title=f"{phoenix_cmds.__name__} List", show_header=True, header_style="bold magenta") + table = Table(title=f"{cmds.__name__} List", show_header=True, header_style="bold magenta") table.add_column("Command Name", style="cyan") table.add_column("Hex Value", style="green", justify="right") - commands_to_show = {cmds_name: cmds_bytes for cmds_name, cmds_bytes in phoenix_cmds.__dict__.items() if cmds_name.isupper()} + commands_to_show = {cmds_name: cmds_bytes for cmds_name, cmds_bytes in cmds.__dict__.items() if cmds_name.isupper()} commands_to_show.update({cmds_name: cmds_bytes for cmds_name, cmds_bytes in Commands.__dict__.items() if cmds_name.isupper()}) for name, value in sorted(commands_to_show.items()): diff --git a/Printer/base_printer.py b/Printer/base_printer.py index 29fa45d..f886db0 100644 --- a/Printer/base_printer.py +++ b/Printer/base_printer.py @@ -31,4 +31,7 @@ def close(self): def read_response(self, timeout=1.0): self.ser.timeout = timeout response = self.ser.read_all() - return response \ No newline at end of file + return response + + def get_type(self): + return self.printer_type \ No newline at end of file diff --git a/Sample_Codes/Phoenix/1_sample_connection.py b/Sample_Codes/Phoenix/1_sample_connection.py index b2b05d4..36f0ca1 100644 --- a/Sample_Codes/Phoenix/1_sample_connection.py +++ b/Sample_Codes/Phoenix/1_sample_connection.py @@ -8,9 +8,12 @@ def simple_connect(): ports = find_port() if ports: # Initialize printer on the first found port - printer = PhoenixPrinter(ports[0].device) + printer = PhoenixPrinter(ports[1].device) # verify_logic_link is the 'handshake' status = printer.verify_logic_link() print(f"Printer Status: {status}") - return printer \ No newline at end of file + return printer + +if __name__ == "__main__": + simple_connect() \ No newline at end of file diff --git a/Sample_Codes/Phoenix/2_sample_print_command.py b/Sample_Codes/Phoenix/2_sample_print_command.py index b3ff297..821b883 100644 --- a/Sample_Codes/Phoenix/2_sample_print_command.py +++ b/Sample_Codes/Phoenix/2_sample_print_command.py @@ -7,27 +7,25 @@ ## Illustrates the standard "Initialize -> Action -> Cut" workflow. # @see [Phoenix Paper Movement Commands](https://escpos.readthedocs.io/en/latest/paper_movement.html) def run_basic_print(): - # 1. Setup Connection ports = find_port() if not ports: print("No printer found.") return + # Use the correct port index based on your setup. Here we use ports[1] as in previous samples. printer = PhoenixPrinter(ports[1].device) try: - # 2. Initialize (ESC @) - # Always good practice to clear the buffer and reset settings - print("Initializing printer...") + # Initialize printer.send_command(PhoenixCommands.INIT) - # 3. Send Text Data + # Send Text Data print("Sending text...") printer.send_command(b"Phoenix Sample Print\n") printer.send_command(b"--------------------\n") printer.send_command(b"SWT-189: Command Sample\n\n") - # 4. Feed and Cut (GS V) + # Feed and Cut (GS V) # We feed a bit of paper so the text clears the cutter blade print("Cutting paper...") printer.send_command(PhoenixCommands.FULL_CUT) diff --git a/Sample_Codes/Phoenix/3_sample_font_control.py b/Sample_Codes/Phoenix/3_sample_font_control.py index f14ad70..0b0b320 100644 --- a/Sample_Codes/Phoenix/3_sample_font_control.py +++ b/Sample_Codes/Phoenix/3_sample_font_control.py @@ -1,48 +1,41 @@ # @brief Demonstrates font styling and selection on Phoenix printers. # @details This sample covers bold, underline, and switching between Font A (12x24) and Font B (9x17). # @see [Font Controlling Commands](https://escpos.readthedocs.io/en/latest/font_cmds.html) - -import sys -import os - -# Ensure project root is in path for Printer and commands modules -sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))) - from Printer.phoenix_printer import PhoenixPrinter from commands import PhoenixCommands from Menu.util import find_port - def run_font_sample(): ports = find_port() if not ports: print("No printer found.") return + # Use the correct port index based on your setup. Here we use ports[1] as in previous samples. printer = PhoenixPrinter(ports[1].device) try: # Initialize printer.send_command(PhoenixCommands.INIT) - # 1. Emphasis (Bold) Mode - # @see https://escpos.readthedocs.io/en/latest/font_cmds.html#emphasis-mode-1b-45 + # Emphasis (Bold) Mode + # @see [Phoenix Emphasis Command] (https://escpos.readthedocs.io/en/latest/font_cmds.html#emphasis-mode-1b-45) printer.send_command(b"Standard Text") printer.send_command(PhoenixCommands.EMPHASIS_MODE + PhoenixCommands.ON) printer.send_command(b"Emphasized (Bold) Text") printer.send_command(PhoenixCommands.LINE_FEED) printer.send_command(PhoenixCommands.EMPHASIS_MODE + PhoenixCommands.OFF) - # 2. Underline Mode - # @see https://escpos.readthedocs.io/en/latest/font_cmds.html#underline-mode-1b-2d + # Underline Mode + # @see [Phoenix Underline Command] (https://escpos.readthedocs.io/en/latest/font_cmds.html#underline-mode-1b-2d) printer.send_command(PhoenixCommands.UNDERLINE_MODE + PhoenixCommands.ON) printer.send_command(b"Underlined Text") printer.send_command(PhoenixCommands.LINE_FEED) printer.send_command(PhoenixCommands.UNDERLINE_MODE + PhoenixCommands.OFF) - # 3. Font Selection + # Font Selection # Font A is standard (12w x 24h), Font B is condensed (9w x 17h) - # @see https://escpos.readthedocs.io/en/latest/font_cmds.html#select-character-font-1b-4d + # @see [Phoenix Font A Command] (https://escpos.readthedocs.io/en/latest/font_cmds.html#select-character-font-1b-4d) printer.send_command(b"This is Font A") printer.send_command(PhoenixCommands.LINE_FEED) printer.send_command(PhoenixCommands.SELECT_FONT_B) @@ -53,7 +46,6 @@ def run_font_sample(): # Feed and Cut printer.send_command(PhoenixCommands.LINE_FEED * 2) # Feed some lines to clear the cutter printer.send_command(PhoenixCommands.FULL_CUT) - print("Font sample sent successfully.") except Exception as e: print(f"Error: {e}") diff --git a/Sample_Codes/Phoenix/4_sample_positioning.py b/Sample_Codes/Phoenix/4_sample_positioning.py index a5f5b74..c90f6f5 100644 --- a/Sample_Codes/Phoenix/4_sample_positioning.py +++ b/Sample_Codes/Phoenix/4_sample_positioning.py @@ -2,34 +2,24 @@ # @details Focuses on Justification (Left/Center/Right) and Line Spacing, # as Phoenix uses these for layout over coordinate-based positioning. # @see [Layout Commands](https://escpos.readthedocs.io/en/latest/layout_cmds.html) - -import sys -import os - -# Ensure project root is in path -sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))) - from Printer.phoenix_printer import PhoenixPrinter from commands import PhoenixCommands from Menu.util import find_port - def run_phoenix_positioning(): ports = find_port() if not ports: print("No printer found.") return + # Use the correct port index based on your setup. Here we use ports[1] as in previous samples. printer = PhoenixPrinter(ports[1].device) try: printer.send_command(PhoenixCommands.INIT) - # 1. Justification (ESC a n) - # @see https://escpos.readthedocs.io/en/latest/layout_cmds.html#select-justification-1b-61 - print("Testing Justification...") - # Left (Default) + # @see [Phoenix Justification Commands] (https://escpos.readthedocs.io/en/latest/layout.html#b61) printer.send_command(PhoenixCommands.SELECT_JUSTIFICATION + PhoenixCommands.LEFT) printer.send_command(b"Left Aligned Text\n") @@ -51,7 +41,6 @@ def run_phoenix_positioning(): # Final Cut printer.send_command(PhoenixCommands.FULL_CUT) - print("Phoenix positioning sample sent.") except Exception as e: print(f"Error: {e}") From a0ee01a41d51df51b7abd4689e4da97d7509c9fe Mon Sep 17 00:00:00 2001 From: longuyen Date: Mon, 20 Apr 2026 15:27:18 -0700 Subject: [PATCH 04/20] Add Initial Reliance samples --- Printer/reliance_printer.py | 2 +- Sample_Codes/reliance/1_sample_connection.py | 19 ++++ .../reliance/2_sample_print_command.py | 40 ++++++++ .../reliance/3_sample_font_control.py | 85 +++++++++++++++++ .../reliance/4_sample_layout_control.py | 92 +++++++++++++++++++ 5 files changed, 237 insertions(+), 1 deletion(-) create mode 100644 Sample_Codes/reliance/1_sample_connection.py create mode 100644 Sample_Codes/reliance/2_sample_print_command.py create mode 100644 Sample_Codes/reliance/3_sample_font_control.py create mode 100644 Sample_Codes/reliance/4_sample_layout_control.py diff --git a/Printer/reliance_printer.py b/Printer/reliance_printer.py index ee24e4f..9c2579e 100644 --- a/Printer/reliance_printer.py +++ b/Printer/reliance_printer.py @@ -4,7 +4,7 @@ class ReliancePrinter(base_printer.BasePrinter): def __init__(self, port): - super().__init__(port, 19200) + super().__init__(port, 9600) self.printer_type = "ReliancePrinter" time.sleep(1) diff --git a/Sample_Codes/reliance/1_sample_connection.py b/Sample_Codes/reliance/1_sample_connection.py new file mode 100644 index 0000000..17f921d --- /dev/null +++ b/Sample_Codes/reliance/1_sample_connection.py @@ -0,0 +1,19 @@ +# @brief This sample demonstrates how to establish a link with the Reliance printer. +from Printer.reliance_printer import ReliancePrinter +from Menu.util import find_port + +## Connects to the first available printer and checks status. +# @returns A ReliancePrinter instance if successful. +def simple_connect(): + ports = find_port() + if ports: + # Initialize printer on the first found port + printer = ReliancePrinter(ports[0].device) + + # verify_logic_link is the 'handshake' + status = printer.verify_logic_link() + print(f"Printer Status: {status}") + return printer + +if __name__ == "__main__": + simple_connect() \ No newline at end of file diff --git a/Sample_Codes/reliance/2_sample_print_command.py b/Sample_Codes/reliance/2_sample_print_command.py new file mode 100644 index 0000000..809a69e --- /dev/null +++ b/Sample_Codes/reliance/2_sample_print_command.py @@ -0,0 +1,40 @@ +# @brief Basic Command Execution for Reliance printers. +# @details This sample demonstrates how to initialize the printer, print text, and trigger a full cut using ESC/POS constants. +from Printer.reliance_printer import ReliancePrinter +from commands import RelianceCommands +from Menu.util import find_port + +## Illustrates the standard "Initialize -> Action -> Cut" workflow. +# @see [Phoenix Paper Movement Commands](https://escpos.readthedocs.io/en/latest/paper_movement.html) +def run_basic_print(): + ports = find_port() + if not ports: + print("No printer found.") + return + + # Use the correct port index based on your setup. Here we use ports[0] as in previous samples. + printer = ReliancePrinter(ports[0].device) + + try: + # Initialize + printer.send_command(RelianceCommands.INIT) + + # Send Text Data + print("Sending text...") + printer.send_command(b"Reliance Sample Print\n") + printer.send_command(b"--------------------\n\n\n\n\n") + printer.send_command(b"SWT-189: Command Sample\n\n") + + # Cut and Eject Paper + # @see [Reliance Ejector Commands](https://escpos.readthedocs.io/en/latest/paper_movement.html#ejector-1d-65-rel) + print("Cutting paper...") + printer.send_command(RelianceCommands.EJECTOR +b'\x05') + + + except Exception as e: + print(f"Failed to send command: {e}") + finally: + printer.close() + +if __name__ == "__main__": + run_basic_print() \ No newline at end of file diff --git a/Sample_Codes/reliance/3_sample_font_control.py b/Sample_Codes/reliance/3_sample_font_control.py new file mode 100644 index 0000000..d20afbb --- /dev/null +++ b/Sample_Codes/reliance/3_sample_font_control.py @@ -0,0 +1,85 @@ +## @brief Demonstrates font styling and orientation for Reliance printers. +# @details Focuses on text rotation (90° and 180°), reverse printing, and style combinations. +# @see Font Controlling Commands +from Menu.util import find_port +from Printer.reliance_printer import ReliancePrinter +from commands import RelianceCommands + +def run_font_orientation_sample(): + ports = find_port() + if not ports: + print("No printer found.") + return + + printer = ReliancePrinter(ports[0].device) + + try: + # Initialize + printer.send_command(RelianceCommands.INIT) + + # --- NORMAL ORIENTATION & STYLES --- + printer.send_command(b"NORMAL ORIENTATION:\n") + printer.send_command(b"Standard Text\n") + + # Bold (Emphasis) + # @see [Reliance Emphasis Commands] (https://escpos.readthedocs.io/en/latest/font_cmds.html#emphasis-mode-1b-45-rel-phx) + printer.send_command(RelianceCommands.EMPHASIS_MODE + b'\x01') + printer.send_command(b"Bold Text\n") + printer.send_command(RelianceCommands.EMPHASIS_MODE + b'\x00') + + # Underline + # @see [Reliance Underline Commands] (https://escpos.readthedocs.io/en/latest/font_cmds.html#underline-mode-1b-2d-rel-phx) + printer.send_command(RelianceCommands.UNDERLINE_MODE + b'\x01') + printer.send_command(b"Underlined Text\n") + printer.send_command(RelianceCommands.UNDERLINE_MODE + b'\x00') + + # --- 90 DEGREE ROTATION --- + # @see [Reliance Rotation Commands](https://escpos.readthedocs.io/en/latest/font_cmds.html#rotation-1b-56-rel) + printer.send_command(b"\nROTATION SAMPLES:\n") + + # Turn 90° Clockwise ON + # @see [Reliance Rotate 90° Commands](https://escpos.readthedocs.io/en/latest/font_cmds.html#rotation-1b-56-rel) + printer.send_command(RelianceCommands.ROTATE_90_DEGREES + b'\x01') + printer.send_command(b"Rotated 90 Degrees\n") + # Turn 90° Clockwise OFF + printer.send_command(RelianceCommands.ROTATE_90_DEGREES + b'\x00') + + # --- UPSIDE DOWN MODE (180°) ---\ + # @see [Reliance Upside Down Commands](https://escpos.readthedocs.io/en/latest/font_cmds.html#upside-down-mode-1b-7b-rel) + printer.send_command(b"\nUPSIDE DOWN SAMPLE:\n") + + # Turn Upside Down ON (Effective at the start of a line) + printer.send_command(RelianceCommands.UPSIDE_DOWN_MODE + b'\x01') + printer.send_command(b"This is Upside Down\n") + # Turn Upside Down OFF + printer.send_command(RelianceCommands.UPSIDE_DOWN_MODE + b'\x00') + + # --- REVERSE PRINT (WHITE ON BLACK) --- + # @see [Reliance Reverse Print Commands](https://escpos.readthedocs.io/en/latest/font_cmds.html#reverse-print-mode-1d-42-rel-phx) + printer.send_command(b"\nREVERSE MODE:\n") + printer.send_command(RelianceCommands.REVERSE_PRINT_MODE + b'\x01') + printer.send_command(b" WHITE ON BLACK \n") + printer.send_command(RelianceCommands.REVERSE_PRINT_MODE + b'\x00') + + # --- COMBINING SIZE & ROTATION --- + printer.send_command(b"\nLARGE ROTATED:\n") + # Double Width + Double Height + printer.send_command(RelianceCommands.SELECT_CHAR_SIZE + b'\x11') + printer.send_command(RelianceCommands.ROTATE_90_DEGREES + b'\x01') + printer.send_command(b"BIG ROT\n") + + # Reset to Default + printer.send_command(RelianceCommands.INIT) + + # Eject and Cut + printer.send_command(b"\n\nFont Orientation Complete\n\n") + printer.send_command(RelianceCommands.EJECTOR + b'\x05') + + except Exception as e: + print(f"Font sample failed: {e}") + finally: + printer.close() + + +if __name__ == "__main__": + run_font_orientation_sample() \ No newline at end of file diff --git a/Sample_Codes/reliance/4_sample_layout_control.py b/Sample_Codes/reliance/4_sample_layout_control.py new file mode 100644 index 0000000..8d25893 --- /dev/null +++ b/Sample_Codes/reliance/4_sample_layout_control.py @@ -0,0 +1,92 @@ +## @brief Demonstrates layout and positioning for Reliance printers. +# @details Focuses on Justification, Line Spacing, Margins, and Character Spacing. +# Reliance printers support advanced layout control via motion units. +# @see [Layout Commands](https://escpos.readthedocs.io/en/latest/layout.html) +from Menu.util import find_port +from Printer.reliance_printer import ReliancePrinter +from commands import RelianceCommands + +def run_layout_sample(): + ports = find_port() + if not ports: + print("No printer found.") + return + + printer = ReliancePrinter(ports[0].device) + + try: + # Initialize + printer.send_command(RelianceCommands.INIT) + + # --- JUSTIFICATION SAMPLES --- + # @see [Reliance Justification Commands](https://escpos.readthedocs.io/en/latest/layout.html#select-justification-1b-61-rel-phx) + printer.send_command(b"JUSTIFICATION:\n") + + # Left (Default) + printer.send_command(RelianceCommands.SELECT_JUSTIFICATION + RelianceCommands.LEFT) + printer.send_command(b"This is Left Aligned\n") + + # Center + printer.send_command(RelianceCommands.SELECT_JUSTIFICATION + RelianceCommands.CENTER) + printer.send_command(b"This is Centered\n") + + # Right + printer.send_command(RelianceCommands.SELECT_JUSTIFICATION + RelianceCommands.RIGHT) + printer.send_command(b"This is Right Aligned\n\n") + + # Reset to Left for further tests + printer.send_command(RelianceCommands.SELECT_JUSTIFICATION + RelianceCommands.LEFT) + + # --- LINE SPACING SAMPLES --- + printer.send_command(b"LINE SPACING:\n") + + # Tight Spacing (1/8 inch) + # @see [Reliance Line Spacing Commands](https://escpos.readthedocs.io/en/latest/layout.html#select-1-8-inch-line-spacing-1b-30-rel) + printer.send_command(RelianceCommands.SELECT_1_8_INCH_LINE_SPACING) + printer.send_command(b"Line 1: 1/8 inch spacing\n") + printer.send_command(b"Line 2: 1/8 inch spacing\n") + + # Standard Spacing (1/6 inch) + # @see [Reliance Line Spacing Commands](https://escpos.readthedocs.io/en/latest/layout.html#select-1-6-inch-line-spacing-1b-32-rel) + printer.send_command(RelianceCommands.SELECT_1_6_INCH_LINE_SPACING) + printer.send_command(b"Line 3: 1/6 inch spacing\n") + + # Custom Large Spacing (ESC 3 n) - Let's set n=100 + # @see [Reliance Line Spacing Commands](https://escpos.readthedocs.io/en/latest/layout.html#line-spacing-1b-33-rel) + printer.send_command(RelianceCommands.LINE_SPACING + b'\x64') + printer.send_command(b"Line 4: Custom Large Spacing\n") + + # Back to default + printer.send_command(RelianceCommands.SELECT_1_6_INCH_LINE_SPACING) + printer.send_command(b"\n") + + # --- MARGINS & CHARACTER SPACING --- + printer.send_command(b"MARGINS & SPACING:\n") + + # Right Side Character Spacing (ESC SP n) - Adds space between characters + # Setting n=4 + # @see [Reliance Character Spacing Commands](https://escpos.readthedocs.io/en/latest/layout.html#right-side-character-spacing-1b-20-rel) + printer.send_command(RelianceCommands.RIGHT_SIDE_CHAR_SPACING + b'\x04') + printer.send_command(b"Widened Character Spacing\n") + printer.send_command(RelianceCommands.RIGHT_SIDE_CHAR_SPACING + b'\x00') # Reset + + # Left Margin (GS L nL nH) + # To set a ~1-inch margin (depending on motion units), we use nL=80, nH=0 + # @see [Reliance Left Margin Commands](https://escpos.readthedocs.io/en/latest/layout.html#left-margin-1d-4c-rel) + printer.send_command(RelianceCommands.LEFT_MARGIN + b'\x50\x00') + printer.send_command(b"This text has a left margin.\n") + + # Reset to Default + printer.send_command(RelianceCommands.INIT) + + # Eject and Cut + printer.send_command(b"\n\nLayout Sample Complete\n\n") + printer.send_command(RelianceCommands.EJECTOR + b'\x05') + + except Exception as e: + print(f"Layout command failed: {e}") + finally: + printer.close() + +if __name__ == "__main__": + run_layout_sample() \ No newline at end of file From 02fd971e40aa1d24faba36e2eb58de2ffe97b748 Mon Sep 17 00:00:00 2001 From: longuyen Date: Mon, 20 Apr 2026 15:42:00 -0700 Subject: [PATCH 05/20] Add image sample --- .../reliance/5_sample_image_barcode.py | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 Sample_Codes/reliance/5_sample_image_barcode.py diff --git a/Sample_Codes/reliance/5_sample_image_barcode.py b/Sample_Codes/reliance/5_sample_image_barcode.py new file mode 100644 index 0000000..153306b --- /dev/null +++ b/Sample_Codes/reliance/5_sample_image_barcode.py @@ -0,0 +1,81 @@ +## @brief Demonstrates image and barcode generation for Reliance printers. +# @details Covers 1D Barcodes, 2D Barcodes (QR Codes), and Raster Image printing. +# @see [Images and Barcode Commands](https://escpos.readthedocs.io/en/latest/imaging.html#) +from Menu.util import find_port, get_raster_blob +from Printer.reliance_printer import ReliancePrinter +from commands import RelianceCommands + +IMAGE_PATH = r"sample_image.png" # Replace with your image path + +def run_imaging_sample(): + ports = find_port() + if not ports: + print("No printer found.") + return + + # Use the correct port index based on your setup. + printer = ReliancePrinter(ports[0].device) + + try: + # 2. Initialize + print("Initializing printer...") + printer.send_command(RelianceCommands.INIT) + + # --- 1D BARCODE SAMPLES --- + # @see [Barcode Generator](https://escpos.readthedocs.io/en/latest/imaging.html#barcode-generator-1-1d-6b-m-d1-dk-00-rel) + printer.send_command(b"1D BARCODE (CODE 39):\n") + + # Set Barcode Height to 100 dots and Width Multiplier to 2 + printer.send_command(RelianceCommands.SET_1D_BARCODE_HEIGHT + b'\x64') + printer.send_command(RelianceCommands.SET_1d_BARCODE_WIDTH_MULT + b'\x02') + + # Set HRI (Human Readable Interpretation) to print below the barcode + printer.send_command(RelianceCommands.SET_HRI_PRINTING_POSITION + b'\x02') + + # Print Code 39 Barcode (System m=4, ends with NULL) + printer.send_command(RelianceCommands.BARCODE_GENERATOR + b'\x04' + b"RELIANCE123" + b'\x00') + printer.send_command(b"\n\n") + + # --- 2D BARCODE (QR CODE) SAMPLES --- + # @see [2D Barcode Generator](https://escpos.readthedocs.io/en/latest/imaging.html#d-barcode-generator-1c-7d-25-k-d1-dk-rel) + printer.send_command(b"2D BARCODE (QR CODE):\n") + + # Set QR Code size (3 to 8 dots per cell) + # @see [Set 2D Barcode Size](https://escpos.readthedocs.io/en/latest/imaging.html#set-2d-barcode-size-1c-7d-74-k-rel) + printer.send_command(RelianceCommands.SET_2D_BARCODE_SIZE + b'\x06') + + # Command must be enclosed by Line Feeds + qr_data = b"https://pyramidacceptors.com" + qr_len = len(qr_data).to_bytes(1, 'little') + + printer.send_command(RelianceCommands.LINE_FEED) + printer.send_command(RelianceCommands.BARCODE_GENERATOR_2D + qr_len + qr_data) + printer.send_command(RelianceCommands.LINE_FEED) + printer.send_command(b"\n") + + # --- RASTER IMAGE SAMPLES --- + # @see [Raster Image](https://escpos.readthedocs.io/en/latest/imaging.html#raster-image-1d-76-30-m-xl-xh-yl-yh-d1-dk-rel-phx) + printer.send_command(b"IMAGE FROM FILE:\n") + try: + # Generate the blob using the helper function + image_blob = get_raster_blob(IMAGE_PATH, printer_width_pixels=384) + printer.send_command(image_blob) + except Exception as img_err: + print(f"Image processing failed: {img_err}") + printer.send_command(b"[Image Load Error]\n") + + # 3. Finalization + # Reset to Default + printer.send_command(RelianceCommands.INIT) + + # 4. Cut and Eject Paper + printer.send_command(b"\n\nImaging Sample Complete\n\n") + printer.send_command(RelianceCommands.EJECTOR + b'\x05') + + except Exception as e: + print(f"Imaging command failed: {e}") + finally: + printer.close() + +if __name__ == "__main__": + run_imaging_sample() \ No newline at end of file From 8948d6fc0da15e7d13123e249110b3d68998f17c Mon Sep 17 00:00:00 2001 From: longuyen Date: Mon, 20 Apr 2026 16:10:05 -0700 Subject: [PATCH 06/20] Add copilot suggestion --- Menu/main_menu.py | 14 +++++++++++--- Printer/reliance_printer.py | 3 +-- Sample_Codes/Phoenix/1_sample_connection.py | 7 ++++++- Sample_Codes/Phoenix/2_sample_print_command.py | 9 +++++++-- Sample_Codes/Phoenix/3_sample_font_control.py | 9 +++++++-- Sample_Codes/Phoenix/4_sample_positioning.py | 9 +++++++-- Sample_Codes/reliance/1_sample_connection.py | 5 +++++ Sample_Codes/reliance/2_sample_print_command.py | 7 ++++++- Sample_Codes/reliance/3_sample_font_control.py | 7 ++++++- Sample_Codes/reliance/4_sample_layout_control.py | 5 +++++ Sample_Codes/reliance/5_sample_image_barcode.py | 5 +++++ 11 files changed, 66 insertions(+), 14 deletions(-) diff --git a/Menu/main_menu.py b/Menu/main_menu.py index 1bb8a6c..34832cb 100644 --- a/Menu/main_menu.py +++ b/Menu/main_menu.py @@ -88,9 +88,17 @@ def handle_print_image(self): path = Prompt.ask("Enter image path") try: raster_blob = get_raster_blob(path) - self.printer.send_command(PhoenixCommands.INIT) - self.printer.send_command(raster_blob) - self.printer.send_command(PhoenixCommands.FULL_CUT) + if self.printer.get_type() == "PhoenixPrinter": + self.printer.send_command(PhoenixCommands.INIT) + self.printer.send_command(raster_blob) + self.printer.send_command(PhoenixCommands.FULL_CUT) + elif self.printer.get_type() == "ReliancePrinter": + self.printer.send_command(RelianceCommands.INIT) + self.printer.send_command(raster_blob) + self.printer.send_command(RelianceCommands.EJECTOR + b'\x05') + else: + console.print("[bold red]Unsupported printer type for image printing.[/bold red]") + return console.print("[bold green]Image sent successfully![/bold green]") except Exception as e: console.print(f"[bold red]Error:[/bold red] {e}") diff --git a/Printer/reliance_printer.py b/Printer/reliance_printer.py index 9c2579e..58d3985 100644 --- a/Printer/reliance_printer.py +++ b/Printer/reliance_printer.py @@ -15,12 +15,11 @@ def verify_logic_link(self): self.ser.write(RelianceCommands.REAL_TIME_STATUS + RelianceCommands.RT_OFFLINE) time.sleep(0.25) - print(f"Bytes waiting: {self.ser.in_waiting}") if self.ser.in_waiting > 0: res = self.ser.read(1)[0] if res == 0xAC: return "CONNECTED_BUT_MANGLED (Check Parity/Stop Bits)" - is_online = res == 0x08 + is_online = (res & 0x08) == 0x08 return "ONLINE" if is_online else "OFFLINE" return "NO_RESPONSE" \ No newline at end of file diff --git a/Sample_Codes/Phoenix/1_sample_connection.py b/Sample_Codes/Phoenix/1_sample_connection.py index 36f0ca1..bd52985 100644 --- a/Sample_Codes/Phoenix/1_sample_connection.py +++ b/Sample_Codes/Phoenix/1_sample_connection.py @@ -1,6 +1,11 @@ # @brief This sample demonstrates how to establish a link with the Phoenix printer. from Printer.phoenix_printer import PhoenixPrinter from Menu.util import find_port +import sys +import os + +# Ensure project root is in path +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))) ## Connects to the first available printer and checks status. # @returns A PhoenixPrinter instance if successful. @@ -8,7 +13,7 @@ def simple_connect(): ports = find_port() if ports: # Initialize printer on the first found port - printer = PhoenixPrinter(ports[1].device) + printer = PhoenixPrinter(ports[0].device) # verify_logic_link is the 'handshake' status = printer.verify_logic_link() diff --git a/Sample_Codes/Phoenix/2_sample_print_command.py b/Sample_Codes/Phoenix/2_sample_print_command.py index 821b883..a8d1f27 100644 --- a/Sample_Codes/Phoenix/2_sample_print_command.py +++ b/Sample_Codes/Phoenix/2_sample_print_command.py @@ -3,6 +3,11 @@ from Printer.phoenix_printer import PhoenixPrinter from commands import PhoenixCommands from Menu.util import find_port +import sys +import os + +# Ensure project root is in path +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))) ## Illustrates the standard "Initialize -> Action -> Cut" workflow. # @see [Phoenix Paper Movement Commands](https://escpos.readthedocs.io/en/latest/paper_movement.html) @@ -12,8 +17,8 @@ def run_basic_print(): print("No printer found.") return - # Use the correct port index based on your setup. Here we use ports[1] as in previous samples. - printer = PhoenixPrinter(ports[1].device) + # Use the first detected printer port by default. + printer = PhoenixPrinter(ports[0].device) try: # Initialize diff --git a/Sample_Codes/Phoenix/3_sample_font_control.py b/Sample_Codes/Phoenix/3_sample_font_control.py index 0b0b320..a10756d 100644 --- a/Sample_Codes/Phoenix/3_sample_font_control.py +++ b/Sample_Codes/Phoenix/3_sample_font_control.py @@ -4,6 +4,11 @@ from Printer.phoenix_printer import PhoenixPrinter from commands import PhoenixCommands from Menu.util import find_port +import sys +import os + +# Ensure project root is in path +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))) def run_font_sample(): ports = find_port() @@ -11,8 +16,8 @@ def run_font_sample(): print("No printer found.") return - # Use the correct port index based on your setup. Here we use ports[1] as in previous samples. - printer = PhoenixPrinter(ports[1].device) + # Use the first detected printer port by default. + printer = PhoenixPrinter(ports[0].device) try: # Initialize diff --git a/Sample_Codes/Phoenix/4_sample_positioning.py b/Sample_Codes/Phoenix/4_sample_positioning.py index c90f6f5..386ee8c 100644 --- a/Sample_Codes/Phoenix/4_sample_positioning.py +++ b/Sample_Codes/Phoenix/4_sample_positioning.py @@ -5,6 +5,11 @@ from Printer.phoenix_printer import PhoenixPrinter from commands import PhoenixCommands from Menu.util import find_port +import sys +import os + +# Ensure project root is in path +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))) def run_phoenix_positioning(): ports = find_port() @@ -12,8 +17,8 @@ def run_phoenix_positioning(): print("No printer found.") return - # Use the correct port index based on your setup. Here we use ports[1] as in previous samples. - printer = PhoenixPrinter(ports[1].device) + # Use the first detected port by default so the sample works when only one printer port is available. + printer = PhoenixPrinter(ports[0].device) try: printer.send_command(PhoenixCommands.INIT) diff --git a/Sample_Codes/reliance/1_sample_connection.py b/Sample_Codes/reliance/1_sample_connection.py index 17f921d..b61b995 100644 --- a/Sample_Codes/reliance/1_sample_connection.py +++ b/Sample_Codes/reliance/1_sample_connection.py @@ -1,6 +1,11 @@ # @brief This sample demonstrates how to establish a link with the Reliance printer. from Printer.reliance_printer import ReliancePrinter from Menu.util import find_port +import sys +import os + +# Ensure project root is in path +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))) ## Connects to the first available printer and checks status. # @returns A ReliancePrinter instance if successful. diff --git a/Sample_Codes/reliance/2_sample_print_command.py b/Sample_Codes/reliance/2_sample_print_command.py index 809a69e..52ce975 100644 --- a/Sample_Codes/reliance/2_sample_print_command.py +++ b/Sample_Codes/reliance/2_sample_print_command.py @@ -3,6 +3,11 @@ from Printer.reliance_printer import ReliancePrinter from commands import RelianceCommands from Menu.util import find_port +import sys +import os + +# Ensure project root is in path +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))) ## Illustrates the standard "Initialize -> Action -> Cut" workflow. # @see [Phoenix Paper Movement Commands](https://escpos.readthedocs.io/en/latest/paper_movement.html) @@ -23,7 +28,7 @@ def run_basic_print(): print("Sending text...") printer.send_command(b"Reliance Sample Print\n") printer.send_command(b"--------------------\n\n\n\n\n") - printer.send_command(b"SWT-189: Command Sample\n\n") + printer.send_command(b"Command Sample\n\n") # Cut and Eject Paper # @see [Reliance Ejector Commands](https://escpos.readthedocs.io/en/latest/paper_movement.html#ejector-1d-65-rel) diff --git a/Sample_Codes/reliance/3_sample_font_control.py b/Sample_Codes/reliance/3_sample_font_control.py index d20afbb..8e96bfa 100644 --- a/Sample_Codes/reliance/3_sample_font_control.py +++ b/Sample_Codes/reliance/3_sample_font_control.py @@ -4,6 +4,11 @@ from Menu.util import find_port from Printer.reliance_printer import ReliancePrinter from commands import RelianceCommands +import sys +import os + +# Ensure project root is in path +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))) def run_font_orientation_sample(): ports = find_port() @@ -44,7 +49,7 @@ def run_font_orientation_sample(): # Turn 90° Clockwise OFF printer.send_command(RelianceCommands.ROTATE_90_DEGREES + b'\x00') - # --- UPSIDE DOWN MODE (180°) ---\ + # --- UPSIDE DOWN MODE (180°) --- # @see [Reliance Upside Down Commands](https://escpos.readthedocs.io/en/latest/font_cmds.html#upside-down-mode-1b-7b-rel) printer.send_command(b"\nUPSIDE DOWN SAMPLE:\n") diff --git a/Sample_Codes/reliance/4_sample_layout_control.py b/Sample_Codes/reliance/4_sample_layout_control.py index 8d25893..f4f16ef 100644 --- a/Sample_Codes/reliance/4_sample_layout_control.py +++ b/Sample_Codes/reliance/4_sample_layout_control.py @@ -5,6 +5,11 @@ from Menu.util import find_port from Printer.reliance_printer import ReliancePrinter from commands import RelianceCommands +import sys +import os + +# Ensure project root is in path +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))) def run_layout_sample(): ports = find_port() diff --git a/Sample_Codes/reliance/5_sample_image_barcode.py b/Sample_Codes/reliance/5_sample_image_barcode.py index 153306b..a5d3fa0 100644 --- a/Sample_Codes/reliance/5_sample_image_barcode.py +++ b/Sample_Codes/reliance/5_sample_image_barcode.py @@ -4,6 +4,11 @@ from Menu.util import find_port, get_raster_blob from Printer.reliance_printer import ReliancePrinter from commands import RelianceCommands +import sys +import os + +# Ensure project root is in path +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))) IMAGE_PATH = r"sample_image.png" # Replace with your image path From f8add828795dc0cfa34c72e796848e8e33764021 Mon Sep 17 00:00:00 2001 From: ltn-PTI Date: Tue, 21 Apr 2026 07:03:25 -0700 Subject: [PATCH 07/20] Update Sample_Codes/reliance/2_sample_print_command.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- Sample_Codes/reliance/2_sample_print_command.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sample_Codes/reliance/2_sample_print_command.py b/Sample_Codes/reliance/2_sample_print_command.py index 52ce975..f00008f 100644 --- a/Sample_Codes/reliance/2_sample_print_command.py +++ b/Sample_Codes/reliance/2_sample_print_command.py @@ -1,14 +1,14 @@ # @brief Basic Command Execution for Reliance printers. # @details This sample demonstrates how to initialize the printer, print text, and trigger a full cut using ESC/POS constants. -from Printer.reliance_printer import ReliancePrinter -from commands import RelianceCommands -from Menu.util import find_port import sys import os # Ensure project root is in path sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))) +from Printer.reliance_printer import ReliancePrinter +from commands import RelianceCommands +from Menu.util import find_port ## Illustrates the standard "Initialize -> Action -> Cut" workflow. # @see [Phoenix Paper Movement Commands](https://escpos.readthedocs.io/en/latest/paper_movement.html) def run_basic_print(): From d4db7c06d41d1c2140839b7c72545aa9fbfdec64 Mon Sep 17 00:00:00 2001 From: ltn-PTI Date: Tue, 21 Apr 2026 07:03:37 -0700 Subject: [PATCH 08/20] Update Sample_Codes/Phoenix/4_sample_positioning.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- Sample_Codes/Phoenix/4_sample_positioning.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sample_Codes/Phoenix/4_sample_positioning.py b/Sample_Codes/Phoenix/4_sample_positioning.py index 386ee8c..5bdd379 100644 --- a/Sample_Codes/Phoenix/4_sample_positioning.py +++ b/Sample_Codes/Phoenix/4_sample_positioning.py @@ -2,15 +2,15 @@ # @details Focuses on Justification (Left/Center/Right) and Line Spacing, # as Phoenix uses these for layout over coordinate-based positioning. # @see [Layout Commands](https://escpos.readthedocs.io/en/latest/layout_cmds.html) -from Printer.phoenix_printer import PhoenixPrinter -from commands import PhoenixCommands -from Menu.util import find_port import sys import os # Ensure project root is in path sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))) +from Printer.phoenix_printer import PhoenixPrinter +from commands import PhoenixCommands +from Menu.util import find_port def run_phoenix_positioning(): ports = find_port() if not ports: From 897e0091a33b9c6c408f57dffc464e0a2e564a1d Mon Sep 17 00:00:00 2001 From: ltn-PTI Date: Tue, 21 Apr 2026 07:03:47 -0700 Subject: [PATCH 09/20] Update Sample_Codes/Phoenix/2_sample_print_command.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- Sample_Codes/Phoenix/2_sample_print_command.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sample_Codes/Phoenix/2_sample_print_command.py b/Sample_Codes/Phoenix/2_sample_print_command.py index a8d1f27..19f4189 100644 --- a/Sample_Codes/Phoenix/2_sample_print_command.py +++ b/Sample_Codes/Phoenix/2_sample_print_command.py @@ -1,14 +1,14 @@ # @brief Basic Command Execution for Phoenix Printers. # @details This sample demonstrates how to initialize the printer, print text, and trigger a full cut using ESC/POS constants. -from Printer.phoenix_printer import PhoenixPrinter -from commands import PhoenixCommands -from Menu.util import find_port import sys import os # Ensure project root is in path sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))) +from Printer.phoenix_printer import PhoenixPrinter +from commands import PhoenixCommands +from Menu.util import find_port ## Illustrates the standard "Initialize -> Action -> Cut" workflow. # @see [Phoenix Paper Movement Commands](https://escpos.readthedocs.io/en/latest/paper_movement.html) def run_basic_print(): From 3b1e9b87b9c8aac542a6764fc4d2d2e3e3596a60 Mon Sep 17 00:00:00 2001 From: ltn-PTI Date: Tue, 21 Apr 2026 07:04:02 -0700 Subject: [PATCH 10/20] Update Sample_Codes/Phoenix/1_sample_connection.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- Sample_Codes/Phoenix/1_sample_connection.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sample_Codes/Phoenix/1_sample_connection.py b/Sample_Codes/Phoenix/1_sample_connection.py index bd52985..a8689ed 100644 --- a/Sample_Codes/Phoenix/1_sample_connection.py +++ b/Sample_Codes/Phoenix/1_sample_connection.py @@ -1,12 +1,12 @@ # @brief This sample demonstrates how to establish a link with the Phoenix printer. -from Printer.phoenix_printer import PhoenixPrinter -from Menu.util import find_port import sys import os # Ensure project root is in path sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))) +from Printer.phoenix_printer import PhoenixPrinter +from Menu.util import find_port ## Connects to the first available printer and checks status. # @returns A PhoenixPrinter instance if successful. def simple_connect(): From 440c7170b348b85d9610a6347e1427d962ba4caf Mon Sep 17 00:00:00 2001 From: ltn-PTI Date: Tue, 21 Apr 2026 07:04:12 -0700 Subject: [PATCH 11/20] Update Sample_Codes/reliance/2_sample_print_command.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- Sample_Codes/reliance/2_sample_print_command.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sample_Codes/reliance/2_sample_print_command.py b/Sample_Codes/reliance/2_sample_print_command.py index f00008f..d680435 100644 --- a/Sample_Codes/reliance/2_sample_print_command.py +++ b/Sample_Codes/reliance/2_sample_print_command.py @@ -10,7 +10,7 @@ from commands import RelianceCommands from Menu.util import find_port ## Illustrates the standard "Initialize -> Action -> Cut" workflow. -# @see [Phoenix Paper Movement Commands](https://escpos.readthedocs.io/en/latest/paper_movement.html) +# @see [Reliance Paper Movement Commands](https://escpos.readthedocs.io/en/latest/paper_movement.html) def run_basic_print(): ports = find_port() if not ports: From 8a3efcd2ec2bea120e4186cdbe7fa4618f3c3127 Mon Sep 17 00:00:00 2001 From: ltn-PTI Date: Tue, 21 Apr 2026 07:04:25 -0700 Subject: [PATCH 12/20] Update Sample_Codes/reliance/1_sample_connection.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- Sample_Codes/reliance/1_sample_connection.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sample_Codes/reliance/1_sample_connection.py b/Sample_Codes/reliance/1_sample_connection.py index b61b995..2c02097 100644 --- a/Sample_Codes/reliance/1_sample_connection.py +++ b/Sample_Codes/reliance/1_sample_connection.py @@ -1,12 +1,12 @@ # @brief This sample demonstrates how to establish a link with the Reliance printer. -from Printer.reliance_printer import ReliancePrinter -from Menu.util import find_port import sys import os # Ensure project root is in path sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))) +from Printer.reliance_printer import ReliancePrinter +from Menu.util import find_port ## Connects to the first available printer and checks status. # @returns A ReliancePrinter instance if successful. def simple_connect(): From 14df8a371143b39c5d00a1978b2bc37e4a430f26 Mon Sep 17 00:00:00 2001 From: ltn-PTI Date: Tue, 21 Apr 2026 07:04:42 -0700 Subject: [PATCH 13/20] Update Sample_Codes/reliance/3_sample_font_control.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- Sample_Codes/reliance/3_sample_font_control.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sample_Codes/reliance/3_sample_font_control.py b/Sample_Codes/reliance/3_sample_font_control.py index 8e96bfa..41a0c36 100644 --- a/Sample_Codes/reliance/3_sample_font_control.py +++ b/Sample_Codes/reliance/3_sample_font_control.py @@ -1,15 +1,15 @@ ## @brief Demonstrates font styling and orientation for Reliance printers. # @details Focuses on text rotation (90° and 180°), reverse printing, and style combinations. # @see Font Controlling Commands -from Menu.util import find_port -from Printer.reliance_printer import ReliancePrinter -from commands import RelianceCommands import sys import os # Ensure project root is in path sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))) +from Menu.util import find_port +from Printer.reliance_printer import ReliancePrinter +from commands import RelianceCommands def run_font_orientation_sample(): ports = find_port() if not ports: From c6151eeceb72a42173d13439acf25ca3a4d27409 Mon Sep 17 00:00:00 2001 From: ltn-PTI Date: Tue, 21 Apr 2026 07:04:51 -0700 Subject: [PATCH 14/20] Update Sample_Codes/reliance/4_sample_layout_control.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- Sample_Codes/reliance/4_sample_layout_control.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sample_Codes/reliance/4_sample_layout_control.py b/Sample_Codes/reliance/4_sample_layout_control.py index f4f16ef..3f94c84 100644 --- a/Sample_Codes/reliance/4_sample_layout_control.py +++ b/Sample_Codes/reliance/4_sample_layout_control.py @@ -2,15 +2,15 @@ # @details Focuses on Justification, Line Spacing, Margins, and Character Spacing. # Reliance printers support advanced layout control via motion units. # @see [Layout Commands](https://escpos.readthedocs.io/en/latest/layout.html) -from Menu.util import find_port -from Printer.reliance_printer import ReliancePrinter -from commands import RelianceCommands import sys import os # Ensure project root is in path sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))) +from Menu.util import find_port +from Printer.reliance_printer import ReliancePrinter +from commands import RelianceCommands def run_layout_sample(): ports = find_port() if not ports: From 9c08be9426893ee538833d8789da945af7fdecaa Mon Sep 17 00:00:00 2001 From: longuyen Date: Tue, 21 Apr 2026 07:05:37 -0700 Subject: [PATCH 15/20] Remove Extra text --- Sample_Codes/Phoenix/2_sample_print_command.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sample_Codes/Phoenix/2_sample_print_command.py b/Sample_Codes/Phoenix/2_sample_print_command.py index a8d1f27..932cb68 100644 --- a/Sample_Codes/Phoenix/2_sample_print_command.py +++ b/Sample_Codes/Phoenix/2_sample_print_command.py @@ -28,7 +28,7 @@ def run_basic_print(): print("Sending text...") printer.send_command(b"Phoenix Sample Print\n") printer.send_command(b"--------------------\n") - printer.send_command(b"SWT-189: Command Sample\n\n") + printer.send_command(b"Command Sample\n\n") # Feed and Cut (GS V) # We feed a bit of paper so the text clears the cutter blade From e2a1f723a41dbc6dced07a518acd434eab54fe27 Mon Sep 17 00:00:00 2001 From: ltn-PTI Date: Tue, 21 Apr 2026 07:06:15 -0700 Subject: [PATCH 16/20] Update Sample_Codes/reliance/5_sample_image_barcode.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- Sample_Codes/reliance/5_sample_image_barcode.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sample_Codes/reliance/5_sample_image_barcode.py b/Sample_Codes/reliance/5_sample_image_barcode.py index a5d3fa0..4cd9eef 100644 --- a/Sample_Codes/reliance/5_sample_image_barcode.py +++ b/Sample_Codes/reliance/5_sample_image_barcode.py @@ -1,15 +1,15 @@ ## @brief Demonstrates image and barcode generation for Reliance printers. # @details Covers 1D Barcodes, 2D Barcodes (QR Codes), and Raster Image printing. # @see [Images and Barcode Commands](https://escpos.readthedocs.io/en/latest/imaging.html#) -from Menu.util import find_port, get_raster_blob -from Printer.reliance_printer import ReliancePrinter -from commands import RelianceCommands import sys import os # Ensure project root is in path sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))) +from Menu.util import find_port, get_raster_blob +from Printer.reliance_printer import ReliancePrinter +from commands import RelianceCommands IMAGE_PATH = r"sample_image.png" # Replace with your image path def run_imaging_sample(): From 91b6fd7389b4be1ecf2a298625d23e2b45596bfa Mon Sep 17 00:00:00 2001 From: longuyen Date: Tue, 21 Apr 2026 10:00:34 -0700 Subject: [PATCH 17/20] Setup project as package --- py_esc_pos/__init__.py | 0 commands.py => py_esc_pos/commands.py | 6 ++-- main.py => py_esc_pos/main.py | 2 +- {Menu => py_esc_pos/menu}/main_menu.py | 22 +++++++------ {Menu => py_esc_pos/menu}/print_menu.py | 6 ++-- {Menu => py_esc_pos/menu}/util.py | 2 +- .../printer}/base_printer.py | 0 .../printer}/phoenix_printer.py | 10 +++--- .../printer}/reliance_printer.py | 4 +-- .../phoenix}/1_sample_connection.py | 10 ++---- .../phoenix}/2_sample_print_command.py | 17 ++++------ .../phoenix}/3_sample_font_control.py | 32 +++++++++---------- .../phoenix}/4_sample_positioning.py | 17 ++++------ .../reliance/1_sample_connection.py | 9 ++---- .../reliance/2_sample_print_command.py | 11 ++----- .../reliance/3_sample_font_control.py | 11 ++----- .../reliance/4_sample_layout_control.py | 11 ++----- .../reliance/5_sample_image_barcode.py | 12 +++---- 18 files changed, 73 insertions(+), 109 deletions(-) create mode 100644 py_esc_pos/__init__.py rename commands.py => py_esc_pos/commands.py (95%) rename main.py => py_esc_pos/main.py (56%) rename {Menu => py_esc_pos/menu}/main_menu.py (89%) rename {Menu => py_esc_pos/menu}/print_menu.py (94%) rename {Menu => py_esc_pos/menu}/util.py (94%) rename {Printer => py_esc_pos/printer}/base_printer.py (100%) rename {Printer => py_esc_pos/printer}/phoenix_printer.py (82%) rename {Printer => py_esc_pos/printer}/reliance_printer.py (88%) rename {Sample_Codes/Phoenix => sample_codes/phoenix}/1_sample_connection.py (69%) rename {Sample_Codes/Phoenix => sample_codes/phoenix}/2_sample_print_command.py (70%) rename {Sample_Codes/Phoenix => sample_codes/phoenix}/3_sample_font_control.py (67%) rename {Sample_Codes/Phoenix => sample_codes/phoenix}/4_sample_positioning.py (78%) rename {Sample_Codes => sample_codes}/reliance/1_sample_connection.py (71%) rename {Sample_Codes => sample_codes}/reliance/2_sample_print_command.py (83%) rename {Sample_Codes => sample_codes}/reliance/3_sample_font_control.py (93%) rename {Sample_Codes => sample_codes}/reliance/4_sample_layout_control.py (93%) rename {Sample_Codes => sample_codes}/reliance/5_sample_image_barcode.py (90%) diff --git a/py_esc_pos/__init__.py b/py_esc_pos/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/commands.py b/py_esc_pos/commands.py similarity index 95% rename from commands.py rename to py_esc_pos/commands.py index e651431..e904c34 100644 --- a/commands.py +++ b/py_esc_pos/commands.py @@ -30,8 +30,8 @@ class Commands: class PhoenixCommands(Commands): SELECT_FONT_A = b'\x1b\x50' - SELECT_FONT_B = b'\x1b\x54' - SELECT_FONT_C = b'\x1b\x55' + SELECT_FONT_C = b'\x1b\x54' + SELECT_FONT_D = b'\x1b\x55' PAPER_STATUS = b'\x1b\x76' PRINT_N_FEED_PAPER_N_LINES = b'\x1b\x64' PRINT_N_FEED_PAPER = b'\x1b\x4a' @@ -74,7 +74,7 @@ class RelianceCommands(Commands): BARCODE_GENERATOR_2D = b'\x1c\x7d\x25' SET_2D_BARCODE_SIZE = b'\x1c\x7d\x74' BARCODE_GENERATOR = b'\x1d\x6b' - SET_1d_BARCODE_WIDTH_MULT = b'\x1d\x77' + SET_1D_BARCODE_WIDTH_MULT = b'\x1d\x77' SET_1D_BARCODE_HEIGHT = b'\x1d\x68' SET_HRI_PRINTING_POSITION = b'\x1d\x48' SET_HRI_FONT = b'\x1d\x66' diff --git a/main.py b/py_esc_pos/main.py similarity index 56% rename from main.py rename to py_esc_pos/main.py index 63d4d5b..414cf69 100644 --- a/main.py +++ b/py_esc_pos/main.py @@ -1,4 +1,4 @@ -from Menu.main_menu import MainMenu +from py_esc_pos.menu.main_menu import MainMenu if __name__ == "__main__": app = MainMenu() diff --git a/Menu/main_menu.py b/py_esc_pos/menu/main_menu.py similarity index 89% rename from Menu/main_menu.py rename to py_esc_pos/menu/main_menu.py index 34832cb..1055f5c 100644 --- a/Menu/main_menu.py +++ b/py_esc_pos/menu/main_menu.py @@ -2,10 +2,12 @@ from rich.prompt import Prompt from rich.panel import Panel from rich.table import Table -from Menu.print_menu import PrintMenu -from Menu.util import get_raster_blob, find_port, verify_printer_connection -from commands import PhoenixCommands, RelianceCommands, Commands -from Printer import phoenix_printer, reliance_printer + +from py_esc_pos.commands import PhoenixCommands, RelianceCommands, Commands +from py_esc_pos.printer import phoenix_printer, reliance_printer + +from print_menu import PrintMenu +from util import get_raster_blob, find_port, verify_printer_connection console = Console() @@ -34,7 +36,7 @@ def connect(self): if not port: return False printer_type = Prompt.ask( - "\nSelect Printer Type", + "\nSelect printer Type", choices=["phoenix", "reliance"] ).lower() @@ -58,14 +60,14 @@ def run(self): def menu(self): while True: menu_text = ( - "1. [bold cyan]Print Menu[/bold cyan] (Text, Font, Style)\n" + "1. [bold cyan]Print menu[/bold cyan] (Text, Font, Style)\n" "2. [bold cyan]Print image[/bold cyan] \n" "3. [bold magenta]Send Raw Input[/bold magenta]\n" "4. [bold green]View Command List[/bold green]\n" "0. Exit" ) - console.print(Panel(menu_text, title="Main Menu", expand=False)) + console.print(Panel(menu_text, title="Main menu", expand=False)) choice = Prompt.ask("Action", choices=["0", "1", "2", "3", "4"], default="0") if choice == "0": @@ -111,8 +113,8 @@ def handle_raw_input(self): response = self.printer.read_response(timeout=2.0) hex_response = " ".join(f"{b:02X}" for b in response) if hex_response: - console.print(f"Printer response (hex): [green]{hex_response}[/green]") - console.print(f"Printer response: [green]00[/green]") + console.print(f"printer response (hex): [green]{hex_response}[/green]") + console.print(f"printer response: [green]00[/green]") def display_commands(self): is_phoenix = self.printer.get_type() == "PhoenixPrinter" @@ -130,4 +132,4 @@ def display_commands(self): table.add_row(name, hex_val) console.print(table) - Prompt.ask("\nPress [bold]Enter[/bold] to return to Main Menu") + Prompt.ask("\nPress [bold]Enter[/bold] to return to Main menu") diff --git a/Menu/print_menu.py b/py_esc_pos/menu/print_menu.py similarity index 94% rename from Menu/print_menu.py rename to py_esc_pos/menu/print_menu.py index 82d5d03..13e08db 100644 --- a/Menu/print_menu.py +++ b/py_esc_pos/menu/print_menu.py @@ -3,7 +3,7 @@ from rich.panel import Panel from rich.prompt import Prompt from rich.table import Table -from commands import PhoenixCommands, RelianceCommands, Commands +from py_esc_pos.commands import PhoenixCommands console = Console() @@ -11,7 +11,7 @@ def add_font_type(print_buffer, font_type): if not print_buffer: console.print("[bold red]No lines to set font for![/bold red]") return - type_map = {"A": PhoenixCommands.SELECT_FONT_A, "B": PhoenixCommands.SELECT_FONT_B, "C": PhoenixCommands.SELECT_FONT_C} + type_map = {"A": PhoenixCommands.SELECT_FONT_A, "C": PhoenixCommands.SELECT_FONT_C, "D": PhoenixCommands.SELECT_FONT_D} print_buffer[-1]["type"] = type_map[font_type] def add_font_style(print_buffer, style): @@ -66,7 +66,7 @@ def menu_print_settings(self): "3. [bold cyan]Set Font Style[/bold cyan] (Last Line)\n" "4. [red]Remove Last Line[/red]\n" "5. [bold magenta]PROCESS PRINT JOB[/bold magenta]\n" - "6. [yellow]Back to Main Menu[/yellow]\n" + "6. [yellow]Back to Main menu[/yellow]\n" "0. Exit" ) menu_panel = Panel(menu_text, title="Print Settings", expand=False) diff --git a/Menu/util.py b/py_esc_pos/menu/util.py similarity index 94% rename from Menu/util.py rename to py_esc_pos/menu/util.py index f54e3e9..7096629 100644 --- a/Menu/util.py +++ b/py_esc_pos/menu/util.py @@ -1,7 +1,7 @@ from PIL import Image, ImageOps import serial.tools.list_ports as port_list -from commands import PhoenixCommands +from py_esc_pos.commands import PhoenixCommands def find_port(): return list(port_list.comports()) diff --git a/Printer/base_printer.py b/py_esc_pos/printer/base_printer.py similarity index 100% rename from Printer/base_printer.py rename to py_esc_pos/printer/base_printer.py diff --git a/Printer/phoenix_printer.py b/py_esc_pos/printer/phoenix_printer.py similarity index 82% rename from Printer/phoenix_printer.py rename to py_esc_pos/printer/phoenix_printer.py index 376d0c7..2d1366e 100644 --- a/Printer/phoenix_printer.py +++ b/py_esc_pos/printer/phoenix_printer.py @@ -1,11 +1,11 @@ -from Printer import base_printer -from commands import PhoenixCommands +from py_esc_pos.printer import base_printer +from py_esc_pos.commands import PhoenixCommands import time ## @class PhoenixPrinter -# @brief Implementation for the Pyramid Phoenix Thermal Printer. +# @brief Implementation for the Pyramid phoenix Thermal printer. # @details This class handles hardware-specific handshaking and status parsing. -# @see [Phoenix Status Documentation](https://escpos.readthedocs.io/en/latest/phoenix_status.html) +# @see [phoenix Status Documentation](https://escpos.readthedocs.io/en/latest/phoenix_status.html) class PhoenixPrinter(base_printer.BasePrinter): def __init__(self, port): super().__init__(port, 9600) @@ -17,7 +17,7 @@ def __init__(self, port): ## @brief Verifies the logic link between the printer and host. # @details Sends a DLE EOT (Real Time Status) command to check if the printer is responsive and online. # @return String description of connection status. - # @see [Phoenix Real Time Status Documentation](https://escpos.readthedocs.io/en/latest/phoenix_status.html#p1004) + # @see [phoenix Real Time Status Documentation](https://escpos.readthedocs.io/en/latest/phoenix_status.html#p1004) # @note A response of 0xAC typically indicates a hardware communication error such as incorrect parity or a wiring fault. def verify_logic_link(self): self.ser.reset_input_buffer() diff --git a/Printer/reliance_printer.py b/py_esc_pos/printer/reliance_printer.py similarity index 88% rename from Printer/reliance_printer.py rename to py_esc_pos/printer/reliance_printer.py index 58d3985..ba5dead 100644 --- a/Printer/reliance_printer.py +++ b/py_esc_pos/printer/reliance_printer.py @@ -1,5 +1,5 @@ -from Printer import base_printer -from commands import RelianceCommands +from py_esc_pos.printer import base_printer +from py_esc_pos.commands import RelianceCommands import time class ReliancePrinter(base_printer.BasePrinter): diff --git a/Sample_Codes/Phoenix/1_sample_connection.py b/sample_codes/phoenix/1_sample_connection.py similarity index 69% rename from Sample_Codes/Phoenix/1_sample_connection.py rename to sample_codes/phoenix/1_sample_connection.py index a8689ed..4e7e56d 100644 --- a/Sample_Codes/Phoenix/1_sample_connection.py +++ b/sample_codes/phoenix/1_sample_connection.py @@ -1,12 +1,8 @@ -# @brief This sample demonstrates how to establish a link with the Phoenix printer. -import sys -import os +# @brief This sample demonstrates how to establish a link with the phoenix printer. -# Ensure project root is in path -sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))) +from py_esc_pos.printer.phoenix_printer import PhoenixPrinter +from py_esc_pos.menu.util import find_port -from Printer.phoenix_printer import PhoenixPrinter -from Menu.util import find_port ## Connects to the first available printer and checks status. # @returns A PhoenixPrinter instance if successful. def simple_connect(): diff --git a/Sample_Codes/Phoenix/2_sample_print_command.py b/sample_codes/phoenix/2_sample_print_command.py similarity index 70% rename from Sample_Codes/Phoenix/2_sample_print_command.py rename to sample_codes/phoenix/2_sample_print_command.py index e4652b0..998f43a 100644 --- a/Sample_Codes/Phoenix/2_sample_print_command.py +++ b/sample_codes/phoenix/2_sample_print_command.py @@ -1,16 +1,11 @@ -# @brief Basic Command Execution for Phoenix Printers. +# @brief Basic Command Execution for phoenix Printers. # @details This sample demonstrates how to initialize the printer, print text, and trigger a full cut using ESC/POS constants. -import sys -import os -# Ensure project root is in path -sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))) - -from Printer.phoenix_printer import PhoenixPrinter -from commands import PhoenixCommands -from Menu.util import find_port +from py_esc_pos.printer.phoenix_printer import PhoenixPrinter +from py_esc_pos.commands import PhoenixCommands +from py_esc_pos.menu.util import find_port ## Illustrates the standard "Initialize -> Action -> Cut" workflow. -# @see [Phoenix Paper Movement Commands](https://escpos.readthedocs.io/en/latest/paper_movement.html) +# @see [phoenix Paper Movement Commands](https://escpos.readthedocs.io/en/latest/paper_movement.html) def run_basic_print(): ports = find_port() if not ports: @@ -26,7 +21,7 @@ def run_basic_print(): # Send Text Data print("Sending text...") - printer.send_command(b"Phoenix Sample Print\n") + printer.send_command(b"phoenix Sample Print\n") printer.send_command(b"--------------------\n") printer.send_command(b"Command Sample\n\n") diff --git a/Sample_Codes/Phoenix/3_sample_font_control.py b/sample_codes/phoenix/3_sample_font_control.py similarity index 67% rename from Sample_Codes/Phoenix/3_sample_font_control.py rename to sample_codes/phoenix/3_sample_font_control.py index a10756d..d00c772 100644 --- a/Sample_Codes/Phoenix/3_sample_font_control.py +++ b/sample_codes/phoenix/3_sample_font_control.py @@ -1,14 +1,9 @@ -# @brief Demonstrates font styling and selection on Phoenix printers. -# @details This sample covers bold, underline, and switching between Font A (12x24) and Font B (9x17). +# @brief Demonstrates font styling and selection on phoenix printers. +# @details This sample covers bold, underline, and switching between Font A (12x24) and Font C (24x48). # @see [Font Controlling Commands](https://escpos.readthedocs.io/en/latest/font_cmds.html) -from Printer.phoenix_printer import PhoenixPrinter -from commands import PhoenixCommands -from Menu.util import find_port -import sys -import os - -# Ensure project root is in path -sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))) +from py_esc_pos.printer.phoenix_printer import PhoenixPrinter +from py_esc_pos.commands import PhoenixCommands +from py_esc_pos.menu.util import find_port def run_font_sample(): ports = find_port() @@ -17,14 +12,14 @@ def run_font_sample(): return # Use the first detected printer port by default. - printer = PhoenixPrinter(ports[0].device) + printer = PhoenixPrinter(ports[1].device) try: # Initialize printer.send_command(PhoenixCommands.INIT) # Emphasis (Bold) Mode - # @see [Phoenix Emphasis Command] (https://escpos.readthedocs.io/en/latest/font_cmds.html#emphasis-mode-1b-45) + # @see [phoenix Emphasis Command] (https://escpos.readthedocs.io/en/latest/font_cmds.html#emphasis-mode-1b-45) printer.send_command(b"Standard Text") printer.send_command(PhoenixCommands.EMPHASIS_MODE + PhoenixCommands.ON) printer.send_command(b"Emphasized (Bold) Text") @@ -32,7 +27,7 @@ def run_font_sample(): printer.send_command(PhoenixCommands.EMPHASIS_MODE + PhoenixCommands.OFF) # Underline Mode - # @see [Phoenix Underline Command] (https://escpos.readthedocs.io/en/latest/font_cmds.html#underline-mode-1b-2d) + # @see [phoenix Underline Command] (https://escpos.readthedocs.io/en/latest/font_cmds.html#underline-mode-1b-2d) printer.send_command(PhoenixCommands.UNDERLINE_MODE + PhoenixCommands.ON) printer.send_command(b"Underlined Text") printer.send_command(PhoenixCommands.LINE_FEED) @@ -40,13 +35,18 @@ def run_font_sample(): # Font Selection # Font A is standard (12w x 24h), Font B is condensed (9w x 17h) - # @see [Phoenix Font A Command] (https://escpos.readthedocs.io/en/latest/font_cmds.html#select-character-font-1b-4d) + # @see [phoenix Font A Command] (https://escpos.readthedocs.io/en/latest/font_cmds.html#select-character-font-1b-4d) printer.send_command(b"This is Font A") printer.send_command(PhoenixCommands.LINE_FEED) - printer.send_command(PhoenixCommands.SELECT_FONT_B) - printer.send_command(b"This is Font B (Condensed)") + printer.send_command(PhoenixCommands.SELECT_FONT_C) + printer.send_command(b"This is Font B (Expanded)") + printer.send_command(PhoenixCommands.LINE_FEED) + printer.send_command(PhoenixCommands.SELECT_FONT_D) + printer.send_command(b"This is Font C (Wider)") printer.send_command(PhoenixCommands.LINE_FEED) printer.send_command(PhoenixCommands.SELECT_FONT_A) + printer.send_command(b"Back to Font A") + printer.send_command(PhoenixCommands.LINE_FEED) # Feed and Cut printer.send_command(PhoenixCommands.LINE_FEED * 2) # Feed some lines to clear the cutter diff --git a/Sample_Codes/Phoenix/4_sample_positioning.py b/sample_codes/phoenix/4_sample_positioning.py similarity index 78% rename from Sample_Codes/Phoenix/4_sample_positioning.py rename to sample_codes/phoenix/4_sample_positioning.py index 5bdd379..78cdf8b 100644 --- a/Sample_Codes/Phoenix/4_sample_positioning.py +++ b/sample_codes/phoenix/4_sample_positioning.py @@ -1,16 +1,11 @@ -# @brief Demonstrates supported positioning and alignment for Phoenix printers. +# @brief Demonstrates supported positioning and alignment for phoenix printers. # @details Focuses on Justification (Left/Center/Right) and Line Spacing, -# as Phoenix uses these for layout over coordinate-based positioning. +# as phoenix uses these for layout over coordinate-based positioning. # @see [Layout Commands](https://escpos.readthedocs.io/en/latest/layout_cmds.html) -import sys -import os -# Ensure project root is in path -sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))) - -from Printer.phoenix_printer import PhoenixPrinter -from commands import PhoenixCommands -from Menu.util import find_port +from py_esc_pos.printer.phoenix_printer import PhoenixPrinter +from py_esc_pos.commands import PhoenixCommands +from py_esc_pos.menu.util import find_port def run_phoenix_positioning(): ports = find_port() if not ports: @@ -24,7 +19,7 @@ def run_phoenix_positioning(): printer.send_command(PhoenixCommands.INIT) # Left (Default) - # @see [Phoenix Justification Commands] (https://escpos.readthedocs.io/en/latest/layout.html#b61) + # @see [phoenix Justification Commands] (https://escpos.readthedocs.io/en/latest/layout.html#b61) printer.send_command(PhoenixCommands.SELECT_JUSTIFICATION + PhoenixCommands.LEFT) printer.send_command(b"Left Aligned Text\n") diff --git a/Sample_Codes/reliance/1_sample_connection.py b/sample_codes/reliance/1_sample_connection.py similarity index 71% rename from Sample_Codes/reliance/1_sample_connection.py rename to sample_codes/reliance/1_sample_connection.py index 2c02097..122b9f4 100644 --- a/Sample_Codes/reliance/1_sample_connection.py +++ b/sample_codes/reliance/1_sample_connection.py @@ -1,12 +1,7 @@ # @brief This sample demonstrates how to establish a link with the Reliance printer. -import sys -import os -# Ensure project root is in path -sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))) - -from Printer.reliance_printer import ReliancePrinter -from Menu.util import find_port +from py_esc_pos.printer.reliance_printer import ReliancePrinter +from py_esc_pos.menu.util import find_port ## Connects to the first available printer and checks status. # @returns A ReliancePrinter instance if successful. def simple_connect(): diff --git a/Sample_Codes/reliance/2_sample_print_command.py b/sample_codes/reliance/2_sample_print_command.py similarity index 83% rename from Sample_Codes/reliance/2_sample_print_command.py rename to sample_codes/reliance/2_sample_print_command.py index d680435..25e35bf 100644 --- a/Sample_Codes/reliance/2_sample_print_command.py +++ b/sample_codes/reliance/2_sample_print_command.py @@ -1,14 +1,9 @@ # @brief Basic Command Execution for Reliance printers. # @details This sample demonstrates how to initialize the printer, print text, and trigger a full cut using ESC/POS constants. -import sys -import os -# Ensure project root is in path -sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))) - -from Printer.reliance_printer import ReliancePrinter -from commands import RelianceCommands -from Menu.util import find_port +from py_esc_pos.printer.reliance_printer import ReliancePrinter +from py_esc_pos.commands import RelianceCommands +from py_esc_pos.menu.util import find_port ## Illustrates the standard "Initialize -> Action -> Cut" workflow. # @see [Reliance Paper Movement Commands](https://escpos.readthedocs.io/en/latest/paper_movement.html) def run_basic_print(): diff --git a/Sample_Codes/reliance/3_sample_font_control.py b/sample_codes/reliance/3_sample_font_control.py similarity index 93% rename from Sample_Codes/reliance/3_sample_font_control.py rename to sample_codes/reliance/3_sample_font_control.py index 41a0c36..52433ad 100644 --- a/Sample_Codes/reliance/3_sample_font_control.py +++ b/sample_codes/reliance/3_sample_font_control.py @@ -1,15 +1,10 @@ ## @brief Demonstrates font styling and orientation for Reliance printers. # @details Focuses on text rotation (90° and 180°), reverse printing, and style combinations. # @see Font Controlling Commands -import sys -import os -# Ensure project root is in path -sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))) - -from Menu.util import find_port -from Printer.reliance_printer import ReliancePrinter -from commands import RelianceCommands +from py_esc_pos.menu.util import find_port +from py_esc_pos.printer.reliance_printer import ReliancePrinter +from py_esc_pos.commands import RelianceCommands def run_font_orientation_sample(): ports = find_port() if not ports: diff --git a/Sample_Codes/reliance/4_sample_layout_control.py b/sample_codes/reliance/4_sample_layout_control.py similarity index 93% rename from Sample_Codes/reliance/4_sample_layout_control.py rename to sample_codes/reliance/4_sample_layout_control.py index 3f94c84..cfe2396 100644 --- a/Sample_Codes/reliance/4_sample_layout_control.py +++ b/sample_codes/reliance/4_sample_layout_control.py @@ -2,15 +2,10 @@ # @details Focuses on Justification, Line Spacing, Margins, and Character Spacing. # Reliance printers support advanced layout control via motion units. # @see [Layout Commands](https://escpos.readthedocs.io/en/latest/layout.html) -import sys -import os -# Ensure project root is in path -sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))) - -from Menu.util import find_port -from Printer.reliance_printer import ReliancePrinter -from commands import RelianceCommands +from py_esc_pos.menu.util import find_port +from py_esc_pos.printer.reliance_printer import ReliancePrinter +from py_esc_pos.commands import RelianceCommands def run_layout_sample(): ports = find_port() if not ports: diff --git a/Sample_Codes/reliance/5_sample_image_barcode.py b/sample_codes/reliance/5_sample_image_barcode.py similarity index 90% rename from Sample_Codes/reliance/5_sample_image_barcode.py rename to sample_codes/reliance/5_sample_image_barcode.py index 4cd9eef..36d4cbc 100644 --- a/Sample_Codes/reliance/5_sample_image_barcode.py +++ b/sample_codes/reliance/5_sample_image_barcode.py @@ -1,15 +1,11 @@ ## @brief Demonstrates image and barcode generation for Reliance printers. # @details Covers 1D Barcodes, 2D Barcodes (QR Codes), and Raster Image printing. # @see [Images and Barcode Commands](https://escpos.readthedocs.io/en/latest/imaging.html#) -import sys -import os -# Ensure project root is in path -sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))) +from py_esc_pos.menu.util import find_port, get_raster_blob +from py_esc_pos.printer.reliance_printer import ReliancePrinter +from py_esc_pos.commands import RelianceCommands -from Menu.util import find_port, get_raster_blob -from Printer.reliance_printer import ReliancePrinter -from commands import RelianceCommands IMAGE_PATH = r"sample_image.png" # Replace with your image path def run_imaging_sample(): @@ -32,7 +28,7 @@ def run_imaging_sample(): # Set Barcode Height to 100 dots and Width Multiplier to 2 printer.send_command(RelianceCommands.SET_1D_BARCODE_HEIGHT + b'\x64') - printer.send_command(RelianceCommands.SET_1d_BARCODE_WIDTH_MULT + b'\x02') + printer.send_command(RelianceCommands.SET_1D_BARCODE_WIDTH_MULT + b'\x02') # Set HRI (Human Readable Interpretation) to print below the barcode printer.send_command(RelianceCommands.SET_HRI_PRINTING_POSITION + b'\x02') From f29806a3594a11d0e0ac34ee195c75b5da29842e Mon Sep 17 00:00:00 2001 From: longuyen Date: Tue, 21 Apr 2026 14:22:59 -0700 Subject: [PATCH 18/20] Add Sample and QR sample code --- sample_codes/phoenix/3_sample_font_control.py | 7 +- .../phoenix/5_sample_image_barcode.py | 69 +++++++++++++++++++ 2 files changed, 72 insertions(+), 4 deletions(-) create mode 100644 sample_codes/phoenix/5_sample_image_barcode.py diff --git a/sample_codes/phoenix/3_sample_font_control.py b/sample_codes/phoenix/3_sample_font_control.py index d00c772..e4e0dcf 100644 --- a/sample_codes/phoenix/3_sample_font_control.py +++ b/sample_codes/phoenix/3_sample_font_control.py @@ -1,5 +1,5 @@ # @brief Demonstrates font styling and selection on phoenix printers. -# @details This sample covers bold, underline, and switching between Font A (12x24) and Font C (24x48). +# @details This sample covers bold, underline, and switching between Font A (12x24), Font C (24x48), and (16x24). # @see [Font Controlling Commands](https://escpos.readthedocs.io/en/latest/font_cmds.html) from py_esc_pos.printer.phoenix_printer import PhoenixPrinter from py_esc_pos.commands import PhoenixCommands @@ -12,7 +12,7 @@ def run_font_sample(): return # Use the first detected printer port by default. - printer = PhoenixPrinter(ports[1].device) + printer = PhoenixPrinter(ports[0].device) try: # Initialize @@ -34,7 +34,7 @@ def run_font_sample(): printer.send_command(PhoenixCommands.UNDERLINE_MODE + PhoenixCommands.OFF) # Font Selection - # Font A is standard (12w x 24h), Font B is condensed (9w x 17h) + # Font A is standard (12w x 24h), Font B is expanded (24w x 48h), Font C is wider (16w x 24h) # @see [phoenix Font A Command] (https://escpos.readthedocs.io/en/latest/font_cmds.html#select-character-font-1b-4d) printer.send_command(b"This is Font A") printer.send_command(PhoenixCommands.LINE_FEED) @@ -57,6 +57,5 @@ def run_font_sample(): finally: printer.close() - if __name__ == "__main__": run_font_sample() \ No newline at end of file diff --git a/sample_codes/phoenix/5_sample_image_barcode.py b/sample_codes/phoenix/5_sample_image_barcode.py new file mode 100644 index 0000000..4dddb42 --- /dev/null +++ b/sample_codes/phoenix/5_sample_image_barcode.py @@ -0,0 +1,69 @@ +# @brief Demonstrates image and barcode generation for phoenix printers. +# @details Covers 2D Barcodes (QR Codes) and Raster Image printing. +# @see [Layout Commands](https://escpos.readthedocs.io/en/latest/imaging.html) + +from py_esc_pos.printer.phoenix_printer import PhoenixPrinter +from py_esc_pos.commands import PhoenixCommands +from py_esc_pos.menu.util import find_port, get_raster_blob + +IMAGE_PATH = r"C:\Users\longuyen\Downloads\test_penguin.jpg" # Replace with your image path + +def run_image_barcode_sample(): + ports = find_port() + if not ports: + print("No printer found.") + return + + # Use the first detected port by default so the sample works when only one printer port is available. + printer = PhoenixPrinter(ports[1].device) + + try: + raster_blob = get_raster_blob(IMAGE_PATH) + qr_data = "https://pyramidacceptors.com" + # pL calculation: Data length (28) + 3 overhead bytes (cn, fn, m) = 31 (0x1F) + pL = bytes([len(qr_data) + 3]) + pH = b"\x00" + pL2 = b"\03" + pH2 = b"\x00" + + # Store the data (Function 180) + # cn=49 (0x31), fn=80 (0x50), m=48 (0x31) + function180 = b"\x31\x50\x31" + # Print the stored data (Function 181) + # cn=49 (0x31), fn=81 (0x51), m=48 (0x31) + function181 = b"\x31\x51\x31" + + # --- RASTER IMAGE SAMPLES --- + # @see [Raster Image](https://escpos.readthedocs.io/en/latest/imaging.html#raster-image-1d-76-30-m-xl-xh-yl-yh-d1-dk-rel-phx) + printer.send_command(b"PRINTING RASTER IMAGE:\n") + printer.send_command(PhoenixCommands.LINE_FEED) + printer.send_command(raster_blob) + printer.send_command(PhoenixCommands.LINE_FEED) + printer.send_command(b"Raster image printed successfully.\n") + printer.send_command(PhoenixCommands.LINE_FEED) + + # --- 2D BARCODE (QR CODE) SAMPLES --- + # @see [Dynamic 2D Barcode](https://escpos.readthedocs.io/en/latest/imaging.html#dynamic-2d-barcode-1d-28-6b-phx) + printer.send_command(PhoenixCommands.INIT) + printer.send_command(b"2D BARCODE (QR CODE):\n") + + # Send the commands to store and print the QR code + printer.send_command(PhoenixCommands.DYNAMIC_2D_BARCODE) + printer.send_command(pL + pH) + printer.send_command(function180) + printer.send_command(qr_data.encode('utf-8')) + + # The printer will print the stored QR code when it receives the print command. + printer.send_command(PhoenixCommands.DYNAMIC_2D_BARCODE) + printer.send_command(pL2 + pH2) + printer.send_command(function181) + printer.send_command(PhoenixCommands.LINE_FEED) + printer.send_command(b"Complete QR code sample\n") + printer.send_command(PhoenixCommands.LINE_FEED * 2) # Feed some lines to clear the cutter + printer.send_command(PhoenixCommands.FULL_CUT) + + except Exception as e: + print(f"Error: {e}") + +if __name__ == "__main__": + run_image_barcode_sample() \ No newline at end of file From a1899baee1165aa379ba4bb561dfe3f6287ea96d Mon Sep 17 00:00:00 2001 From: longuyen Date: Tue, 21 Apr 2026 14:44:35 -0700 Subject: [PATCH 19/20] Add sample code for Reliance logo --- py_esc_pos/commands.py | 6 --- sample_codes/reliance/6_sample_print_logo.py | 55 ++++++++++++++++++++ 2 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 sample_codes/reliance/6_sample_print_logo.py diff --git a/py_esc_pos/commands.py b/py_esc_pos/commands.py index e904c34..5561a73 100644 --- a/py_esc_pos/commands.py +++ b/py_esc_pos/commands.py @@ -43,12 +43,6 @@ class PhoenixCommands(Commands): DYNAMIC_2D_BARCODE = b'\x1d\x28\x6b' PRINT_REAL_TIME_CLOCK = b'\x1c\x7d\x70' - - # Actions - TEST_COIN_IN = b'\x60' - TEST_NOTE_IN = b'\x61' - PRINT_RTC = b'\x1c\x7d\x70' - class RelianceCommands(Commands): HORIZONTAL_TAB = b'\x09' FORM_FEED = b'\x0c' diff --git a/sample_codes/reliance/6_sample_print_logo.py b/sample_codes/reliance/6_sample_print_logo.py new file mode 100644 index 0000000..aac946f --- /dev/null +++ b/sample_codes/reliance/6_sample_print_logo.py @@ -0,0 +1,55 @@ +## @brief Demonstrates both Standard and Simplified logo printing for Reliance. +# @details Standard allows for partial logo printing, while Simplified uses flash dimensions. +# @see [Images and Barcode](https://escpos.readthedocs.io/en/latest/imaging.html#images-and-barcode) + +from py_esc_pos.printer.reliance_printer import ReliancePrinter +from py_esc_pos.commands import RelianceCommands +from py_esc_pos.menu.util import find_port + +def run_logo_print(): + ports = find_port() + if not ports: + print("No printer found.") + return + + printer = ReliancePrinter(ports[0].device) + + try: + # Initialize + printer.send_command(RelianceCommands.INIT) + + # --- METHOD 1: PRINT LOGO (SIMPLIFIED) --- + # Prints logo 'n' using the dimensions already stored in flash. + # @see [Print Graphic Bank/Logo (Simplified)](https://escpos.readthedocs.io/en/latest/imaging.html#print-graphic-bank-logo-simplified-1c-79-rel) + logo_index = b'\x01' + reserved = b'\x00' # Must be zero + + printer.send_command(b"Logo (Simplified):\n") + printer.send_command(RelianceCommands.PRINT_GRAPHIC_BANK_LOGO_SIMPLIFIED + logo_index + reserved) + printer.send_command(b"End of Logo (Simplified)\n") + printer.send_command(RelianceCommands.LINE_FEED * 2) + + # --- METHOD 2: PRINT LOGO (STANDARD) --- + # Format: n + xH + xL + yH + yL + # xH/xL: Starting dotline (0 in this case) + # yH/yL: Number of dotlines to print (200 in this case, hex 0xC8) + # @see [Print Graphic Bank/Logo](https://escpos.readthedocs.io/en/latest/imaging.html#print-graphic-bank-logo-1b-fa) + start_line = b'\x00\x00' # xH, xL + line_count = b'\x00\xc8' # yH, yL (200 dots) + + printer.send_command(b"Logo (Standard):\n") + printer.send_command(RelianceCommands.PRINT_GRAPHIC_BANK_LOGO + logo_index + start_line + line_count) + printer.send_command(b"End of Logo (Standard)\n") + + # Cut and Eject Paper + printer.send_command(RelianceCommands.LINE_FEED * 4) + printer.send_command(RelianceCommands.EJECTOR + b'\x05') + print("Logo samples sent successfully.") + + except Exception as e: + print(f"Failed to send command: {e}") + finally: + printer.close() + +if __name__ == "__main__": + run_logo_print() \ No newline at end of file From 14597e76ddbb8a6ed59d600097b3ff7cad8b32be Mon Sep 17 00:00:00 2001 From: longuyen Date: Tue, 21 Apr 2026 14:52:46 -0700 Subject: [PATCH 20/20] Fix syntax error --- sample_codes/phoenix/1_sample_connection.py | 2 +- sample_codes/phoenix/2_sample_print_command.py | 6 +++--- sample_codes/phoenix/3_sample_font_control.py | 9 +++++---- sample_codes/phoenix/4_sample_positioning.py | 6 +++--- sample_codes/phoenix/5_sample_image_barcode.py | 8 ++++---- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/sample_codes/phoenix/1_sample_connection.py b/sample_codes/phoenix/1_sample_connection.py index 4e7e56d..1741301 100644 --- a/sample_codes/phoenix/1_sample_connection.py +++ b/sample_codes/phoenix/1_sample_connection.py @@ -1,4 +1,4 @@ -# @brief This sample demonstrates how to establish a link with the phoenix printer. +# @brief This sample demonstrates how to establish a link with the Phoenix printer. from py_esc_pos.printer.phoenix_printer import PhoenixPrinter from py_esc_pos.menu.util import find_port diff --git a/sample_codes/phoenix/2_sample_print_command.py b/sample_codes/phoenix/2_sample_print_command.py index 998f43a..b018e8b 100644 --- a/sample_codes/phoenix/2_sample_print_command.py +++ b/sample_codes/phoenix/2_sample_print_command.py @@ -1,11 +1,11 @@ -# @brief Basic Command Execution for phoenix Printers. +# @brief Basic Command Execution for Phoenix Printers. # @details This sample demonstrates how to initialize the printer, print text, and trigger a full cut using ESC/POS constants. from py_esc_pos.printer.phoenix_printer import PhoenixPrinter from py_esc_pos.commands import PhoenixCommands from py_esc_pos.menu.util import find_port ## Illustrates the standard "Initialize -> Action -> Cut" workflow. -# @see [phoenix Paper Movement Commands](https://escpos.readthedocs.io/en/latest/paper_movement.html) +# @see [Phoenix Paper Movement Commands](https://escpos.readthedocs.io/en/latest/paper_movement.html) def run_basic_print(): ports = find_port() if not ports: @@ -21,7 +21,7 @@ def run_basic_print(): # Send Text Data print("Sending text...") - printer.send_command(b"phoenix Sample Print\n") + printer.send_command(b"Phoenix Sample Print\n") printer.send_command(b"--------------------\n") printer.send_command(b"Command Sample\n\n") diff --git a/sample_codes/phoenix/3_sample_font_control.py b/sample_codes/phoenix/3_sample_font_control.py index e4e0dcf..049e428 100644 --- a/sample_codes/phoenix/3_sample_font_control.py +++ b/sample_codes/phoenix/3_sample_font_control.py @@ -1,6 +1,7 @@ -# @brief Demonstrates font styling and selection on phoenix printers. +# @brief Demonstrates font styling and selection on Phoenix printers. # @details This sample covers bold, underline, and switching between Font A (12x24), Font C (24x48), and (16x24). # @see [Font Controlling Commands](https://escpos.readthedocs.io/en/latest/font_cmds.html) + from py_esc_pos.printer.phoenix_printer import PhoenixPrinter from py_esc_pos.commands import PhoenixCommands from py_esc_pos.menu.util import find_port @@ -19,7 +20,7 @@ def run_font_sample(): printer.send_command(PhoenixCommands.INIT) # Emphasis (Bold) Mode - # @see [phoenix Emphasis Command] (https://escpos.readthedocs.io/en/latest/font_cmds.html#emphasis-mode-1b-45) + # @see [Phoenix Emphasis Command] (https://escpos.readthedocs.io/en/latest/font_cmds.html#emphasis-mode-1b-45) printer.send_command(b"Standard Text") printer.send_command(PhoenixCommands.EMPHASIS_MODE + PhoenixCommands.ON) printer.send_command(b"Emphasized (Bold) Text") @@ -27,7 +28,7 @@ def run_font_sample(): printer.send_command(PhoenixCommands.EMPHASIS_MODE + PhoenixCommands.OFF) # Underline Mode - # @see [phoenix Underline Command] (https://escpos.readthedocs.io/en/latest/font_cmds.html#underline-mode-1b-2d) + # @see [Phoenix Underline Command] (https://escpos.readthedocs.io/en/latest/font_cmds.html#underline-mode-1b-2d) printer.send_command(PhoenixCommands.UNDERLINE_MODE + PhoenixCommands.ON) printer.send_command(b"Underlined Text") printer.send_command(PhoenixCommands.LINE_FEED) @@ -35,7 +36,7 @@ def run_font_sample(): # Font Selection # Font A is standard (12w x 24h), Font B is expanded (24w x 48h), Font C is wider (16w x 24h) - # @see [phoenix Font A Command] (https://escpos.readthedocs.io/en/latest/font_cmds.html#select-character-font-1b-4d) + # @see [Phoenix Font A Command] (https://escpos.readthedocs.io/en/latest/font_cmds.html#select-character-font-1b-4d) printer.send_command(b"This is Font A") printer.send_command(PhoenixCommands.LINE_FEED) printer.send_command(PhoenixCommands.SELECT_FONT_C) diff --git a/sample_codes/phoenix/4_sample_positioning.py b/sample_codes/phoenix/4_sample_positioning.py index 78cdf8b..e446ba1 100644 --- a/sample_codes/phoenix/4_sample_positioning.py +++ b/sample_codes/phoenix/4_sample_positioning.py @@ -1,7 +1,7 @@ -# @brief Demonstrates supported positioning and alignment for phoenix printers. +# @brief Demonstrates supported positioning and alignment for Phoenix printers. # @details Focuses on Justification (Left/Center/Right) and Line Spacing, # as phoenix uses these for layout over coordinate-based positioning. -# @see [Layout Commands](https://escpos.readthedocs.io/en/latest/layout_cmds.html) +# @see [Images and Barcode Commands](https://escpos.readthedocs.io/en/latest/layout_cmds.html) from py_esc_pos.printer.phoenix_printer import PhoenixPrinter from py_esc_pos.commands import PhoenixCommands @@ -19,7 +19,7 @@ def run_phoenix_positioning(): printer.send_command(PhoenixCommands.INIT) # Left (Default) - # @see [phoenix Justification Commands] (https://escpos.readthedocs.io/en/latest/layout.html#b61) + # @see [Phoenix Justification Commands] (https://escpos.readthedocs.io/en/latest/layout.html#b61) printer.send_command(PhoenixCommands.SELECT_JUSTIFICATION + PhoenixCommands.LEFT) printer.send_command(b"Left Aligned Text\n") diff --git a/sample_codes/phoenix/5_sample_image_barcode.py b/sample_codes/phoenix/5_sample_image_barcode.py index 4dddb42..8cd45e2 100644 --- a/sample_codes/phoenix/5_sample_image_barcode.py +++ b/sample_codes/phoenix/5_sample_image_barcode.py @@ -1,12 +1,12 @@ -# @brief Demonstrates image and barcode generation for phoenix printers. +# @brief Demonstrates image and barcode generation for Phoenix printers. # @details Covers 2D Barcodes (QR Codes) and Raster Image printing. -# @see [Layout Commands](https://escpos.readthedocs.io/en/latest/imaging.html) +# @see [Images and Barcode Commands](https://escpos.readthedocs.io/en/latest/imaging.html) from py_esc_pos.printer.phoenix_printer import PhoenixPrinter from py_esc_pos.commands import PhoenixCommands from py_esc_pos.menu.util import find_port, get_raster_blob -IMAGE_PATH = r"C:\Users\longuyen\Downloads\test_penguin.jpg" # Replace with your image path +IMAGE_PATH = r"sample_image.png" # Replace with your image path def run_image_barcode_sample(): ports = find_port() @@ -15,7 +15,7 @@ def run_image_barcode_sample(): return # Use the first detected port by default so the sample works when only one printer port is available. - printer = PhoenixPrinter(ports[1].device) + printer = PhoenixPrinter(ports[0].device) try: raster_blob = get_raster_blob(IMAGE_PATH)