ESC/P设定绝对水平打印位置 [英] ESC/P Set Absolute Horizontal Print Position

查看:585
本文介绍了ESC/P设定绝对水平打印位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在设置Epson LX-300 II点矩阵打印机中的水平打印位置时遇到麻烦.设置水平打印位置的命令有时不起作用.

I am having trouble with setting the horizontal print position in an Epson LX-300 II dot matrix printer. The command to set the horizontal print position does not work sometimes.

我需要这样做,以将可打印数据与预打印纸质表格中的相应列对齐.

I need this to align the printable data to the appropriate column in the pre-printed paper form.

给出以下代码:

        // row 1
        escp.setAbsoluteHorizontalPosition(1);
        escp.print("Equipment");
        escp.setAbsoluteHorizontalPosition(10);
        escp.print("Serial");
        escp.setAbsoluteHorizontalPosition(13);
        escp.print("Remarks");

        // row 2
        escp.lineFeed();
        escp.setAbsoluteHorizontalPosition(1);
        escp.print("Equipment");
        escp.setAbsoluteHorizontalPosition(10);
        escp.print("Serial");
        escp.setAbsoluteHorizontalPosition(13);
        escp.print("Remarks");

这是预期的输出:

Equipment                  Serial     Remarks
Equipment                  Serial     Remarks

但是,这是实际的打印输出:

However, this is the actual printed output:

EquipmentSerial                        Remarks
EquipmentSerial                        Remarks

我无法弄清楚为什么"Serial"没有打印在正确的位置.

I cannot figure out why "Serial" is not printed on the correct position.

为了弄清楚这一点,我制作了一个测试程序,该程序在一行中以1cm的距离打印'x'.

To try to figure this out, I made a test program which prints 'x' 1cm apart in a single line.

这是测试程序中的示例代码:

Here is a sample code from the test program:

    ESCPrinter escp = new ESCPrinter(sharedPrinterName, false);
    if((escp.initialize()) == false) {
        return;
    }
    escp.select10CPI();
    escp.set8LPI();
    escp.setCharacterSet(ESCPrinter.USA);                
    for(int x = 1; x < 15; x++) {
        escp.setAbsoluteHorizontalPosition(x);
        escp.print("x");
    }
    escp.formFeed();
    escp.close();

预期输出:

x    x    x    x    x    x    x    x    x    x    x    x    x    x

实际输出:

x    x    x    x    xxxxxx                    x    x    x    x

这是《 Epson ESC/P参考手册》 ,以及 这是第三-方代码我正在用来发送打印机命令,为了实现set8LPI()方法,我对其进行了一些修改.

This is the Epson ESC/P Reference Manual, and this is the third-party code I am using to send printer commands, which I have slightly modified to implement the set8LPI() method.

在参考手册中,用于设置绝对水平打印位置的命令在C-31中.

In the reference manual, the command to set the absolute horizontal print position is in C-31.

我已经尝试了好几天了,但是我离找到解决方案还很近.

I have tried to figure this out myself for several days now but I am no closer to finding the solution.

我制作了另一个测试程序,该程序打印从0.0cm到19.8cm位置的测试数据,以0.2cm的增量打印,并且每个之间都有换行符.

I made another test program that prints test data from positions 0.0cm to 19.8cm, with increments of 0.2cm and line feeds in between each.

我打印的测试数据也是我指定的绝对水平位置(以便于识别).

The test data I have printed is also the absolute horizontal position I have specified (for easier identification).

向您展示确切的打印输出是不切实际的,因此我将尽力描述它们.

It would be impractical to show you the exact printed output, so I will just describe them as best as I can.

将水平位置设置为0.0直到5.4似乎可行,输出看起来像这样:

Setting the horizontal position to 0.0 until 5.4 seems to work, with the output looking like this:

0.0
 0.2
  0.3
   0.4
   .
   .
   .
   -------->  5.4

之后,将绝对水平位置设置为5.6cm,直到忽略10.8cm. 打印机仅在纸张的最左侧打印.

After that, setting the absolute horizontal position to 5.6cm until 10.8cm is ignored. The printer just prints on the left-most part of the paper.

设置绝对水平位置"命令再次工作11.0厘米,直到16.2厘米. 再次忽略了16.4厘米直到19.8厘米.

The "set absolute horizontal position" command is working again for 11.0cm until 16.2cm. Ignored again for 16.4cm until 19.8cm.

据我了解,我已经链接到上面的ESC/P参考手册,当指定位置超出右边距时,打印机将忽略此命令.没有其他规定.

As I understand the ESC/P reference manual I have linked above, the printer ignores this command when the specified position is beyond the right margin. Nothing else is specified.

很显然,我的价值观都在空白之内.

Obviously, my values are all within the margins.

那么,这可能是打印机的硬件问题吗?

->不是硬件问题.使用其他打印机可​​获得相同的结果.

--> Not a hardware problem. I got same results using a different printer.

给出命令以设置绝对水平位置: ESC $ nl nh

Given the command to set absolute horizontal position: ESC $ nl nh

我制作了另一个测试程序,直接输入nh和nl参数.

I have made another test program where I directly input the nh and nl parameters.

我已经意识到,只要nl值超过127,就会忽略此命令.

I have realized that this command is ignored whenever nl value exceeds 127.

我发现这很令人惊讶,因为参考手册指出nl的最大值为255.

I find this to be surprising since the reference manual indicates that max value for nl is 255.

这一发现与我输入以厘米为单位的水平位置的第一个测试程序一致.当我将厘米转换为相应的nh和nl值(对于被忽略的命令)时,得到的nl值大于127.

This finding is consistent with the first test program where I input the horizontal position in centimeters. When I convert centimeters into the corresponding nh and nl values for the commands that are ignored, the resulting nl values are greater than 127.

推荐答案

ESC/P设置绝对水平打印位置

ESC/P Set Absolute Horizontal Print Position

从ESCPrinter.java上给定的第3方Java代码中,将ESC/P控制代码发送到打印机端口的方法正在等待灾难.对于您的情况,当该值大于7位数据(127/0x7F)时.

From the given 3rd Party Java code on ESCPrinter.java, the approach to send ESC/P control code to the printer port is waiting for disaster. For your case, when the value is larger than 7-bit data (127 / 0x7F).

给出命令以设置绝对水平位置:

Given the command to set absolute horizontal position:

ESC $ nL nH
nL value: 0 <= nL < 256

当nL值超过127时,该值将被错误地转换并发送到打印机端口. 不正确的转换是由PrintStream()类引起的,该类将根据您的系统区域设置(内部创建java.io.Writer()类)调用默认字符集编码.这就是为什么永远不会正确将nL值发送到打印机端口的原因.

When nL value is over 127, the value is converted incorrectly and sent to the printer port. The incorrect conversion is caused by PrintStream() class which will call the default charset encoding based on your system locale (internally create java.io.Writer() class). That's why the value nL is never correctly send to printer port.

要解决此问题,切勿尝试使用String()类或任何其他与字符集编码相关的类来编写控制代码(例如.toString()、. toByteArray(charset),Writer).

To fix this problem, you must never try to use String() class or any other charset encoding related class to write the control code (e.g. .toString(), .toByteArray(charset), Writer).

您可以尝试对PrintStream()进行UTF-8编码,以查看其是否修复了该错误.

You can try UTF-8 encoding for PrintStream(), to see if it fixes the bug or not.

这篇关于ESC/P设定绝对水平打印位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆