import time
import serial
import os
import requests
from zebrafy import ZebrafyImage

def printLabel():
    # Configuration for RS232
    serial_port = 'COM2' # '/dev/tty.usbserial-1110'  
    baud_rate = 57600     
    parity = serial.PARITY_NONE
    data_bits = serial.EIGHTBITS
    stop_bits = serial.STOPBITS_ONE
    timeout = 1         

    print_data = f"""
    ^XA

    ^FWR
    ^CF0,60
    ^FO505,20^FDSOME PLU SAMPLE^FS

    ^CF0,30
    ^FO340,20^FDLot/Batch #: lot number goes here^FS

    ^XZ
    """

    # ^CW1,E:SIMSUN.TTF
    # ^FWN
    # ^A1R,50,50
    # ^CI28
    # ^CFJ,45
    # ^FO650,20^FD{name_en}^FS

    try:
        # Open the serial connection
        with serial.Serial(
            port=serial_port,
            baudrate=baud_rate,
            parity=parity,
            bytesize=data_bits,
            stopbits=stop_bits,
            timeout=timeout,
        ) as ser:
            # Send data to the printer
            ser.write(print_data.encode('utf-8'))
            time.sleep(2)  # Wait for 2 seconds to allow the printer to process the command
            ser.close()
            print("Data sent to the printer successfully.")

    except serial.SerialException as e:
        print(f"Error communicating with the printer: {e}")