3

I am using Epson FX2175 dot matrix printer and win32print python library to give commands to printer. After printing is completed paper doesn't moves to next tear off position.

I tried sending FF(form feed) command at the end but it advances paper too much instead of moving as my paper size i.e. 15.4 cm. Paper size has been configured in printer preferences > paper size > user defined.

Below is my python code

import os, sys
import win32print

def formatData(args):
  cnt = 1;
  decimal_form_feed = 12
  decimal_line_feed = 10
  decimal_carriage_return = 13

  byteArr = bytearray()

  # Reverse feed
  # byteArr.extend(bytes("\u001bj2", "utf-8"))

  # byteArr.extend(bytes("\u001b$0", "utf-8"))

  # ESC J Advance print position vertically
  # param n where 0 <= n <=255
  # Advances vertical position n/216 or n/180 inches

  # Set page size in terms of line numbers
  # byteArr.extend(bytes("\u001bC10", "utf-8"))
  print(len(args))
  while(cnt < len(args)):
    if args[cnt]=="R":
      temp = bytes (args[cnt+1], "utf-8")
      byteArr.extend(temp)
      #print(byteArr)
    elif args[cnt]=="RB":
      temp = bytes ("\u001bE"+args[cnt+1]+"\u001bF", "utf-8")
      byteArr.extend(temp);
      #print(byteArr)
    elif args[cnt]=="D":
      temp = bytes ("\u001b\u000e"+args[cnt+1]+"\u001b\u0012", "utf-8")
      byteArr.extend(temp);
    elif args[cnt]=="DB":
      temp = bytes ("\u001b\u000e"+args[cnt+1]+"\u001b\u0012", "utf-8")
      byteArr.extend(temp);
    elif args[cnt]=="newline":
      temp = bytes ("\n", "utf-8")
      byteArr.extend(temp);
      cnt = cnt+1
      continue
    elif args[cnt]=="lf":
      mCnt = 0
      while mCnt < int(args[cnt+1]):
        mCnt = mCnt+1
        byteArr.extend(bytes("\n", "utf-8"))
        #byteArr.extend(bytes("\u001bJ1", "utf-8"))
    elif args[cnt]=="rf":
      mCnt = 0
      while mCnt < int(args[cnt+1]):
        byteArr.extend(bytes("\u001bj2", "utf-8"))
        mCnt = mCnt+1
      
    cnt = cnt+2;
  byteArr.extend(decimal_carriage_return.to_bytes(2, 'big'))
  byteArr.extend(decimal_form_feed .to_bytes(2, 'big'))
  #byteArr.extend(decimal_carriage_return.to_bytes(2, 'big'))
  #byteArr.extend(decimal_line_feed.to_bytes(2, 'big'))
  print(byteArr)
  mBytes = bytes(byteArr)
  return mBytes
    

printer_name = win32print.GetDefaultPrinter ()

raw_data = formatData(sys.argv);
hPrinter = win32print.OpenPrinter (printer_name)
try:
  hJob = win32print.StartDocPrinter (hPrinter, 1, (raw_data.decode("utf-8"), None, "RAW"))
  try:
    win32print.StartPagePrinter (hPrinter)
    win32print.WritePrinter (hPrinter, raw_data)
    win32print.EndPagePrinter (hPrinter)
  finally:
    win32print.EndDocPrinter (hPrinter)
finally:
  win32print.ClosePrinter (hPrinter)

I am using this manual for reference Epson EscP manual reference

Any help is very much appreciated since I am struglling with this for almost 5 days.

Deep Nishad
  • 181
  • 1
  • 2
  • 7

1 Answers1

0

For people who face same challenge

I was unable to find answer how to do it programatically but by making changes to default settings in printer I was able to get my work done. Followng changes were made in printer:

  1. Auto tear off mode turned on.
  2. Page size set to 6 inches.

Page size can be set using following command but it was some how not working. Just putting it so that it may work for someone else:

ESC C NUL n

Note: I made all changes through printer software but that too was not working.

Deep Nishad
  • 181
  • 1
  • 2
  • 7
  • I don't see why this would not work. Possible culprits: 1. not in ESP/P mode but in ESP/P2 or POS (idk about this model); 2. Init code `ESC @` sent along the way; 3. `decimal_form_feed .to_bytes(2, 'big')` doing something unexpected. Assuming 12" paper, have you tried the sequence `ESC C NUL 12` "as is", `lpr` on Linux and macOS for instance? – youri Mar 06 '23 at 06:38
  • Also, just for sanity, I'd send commands as directly as possible, for instance `b'\x1bC\x00\x06` for instance, to avoid any accidental conversion error – youri Mar 06 '23 at 06:40