使用python打印后点阵打印机不会移动到下一个撕纸位置

发布于 2025-01-10 15:40:21 字数 2729 浏览 0 评论 0原文

我正在使用 Epson FX2175 点阵打印机和 win32print python 库向打印机发出命令。打印完成后,纸张不会移动到下一个撕纸位置。

我尝试在最后发送 FF(换页)命令,但它使纸张前进太多,而不是按照我的纸张尺寸(即 15.4 厘米)移动。纸张尺寸已在打印机首选项 > 中配置纸张尺寸>用户定义。

下面是我的Python代码

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)

,我使用本手册作为参考 Epson EscP 手册参考

非常感谢您的帮助,因为我为此苦苦挣扎了近 5 天。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

神经暖 2025-01-17 15:40:21

对于面临同样挑战的人,

我无法找到如何以编程方式完成此操作的答案,但通过更改打印机中的默认设置,我能够完成工作。打印机进行了以下更改:

  1. 自动撕纸模式打开。
  2. 页面尺寸设置为 6 英寸。

可以使用以下命令设置页面大小,但有些不起作用。只是把它放在它可能对其他人有用的地方:

ESC C NUL n

注意:我通过打印机软件进行了所有更改,但这也不起作用。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文