即使我添加了crlf,为什么所有内容都打印在同一行上? [英] Why does everything print on the same line, even though I'm adding crlfs?

查看:72
本文介绍了即使我添加了crlf,为什么所有内容都打印在同一行上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这将通过运行在Motorola MC3100掌上电脑上的CE/CF应用程序在Zebra QL220带式打印机上打印(尽管仍然很难看):

This will print (although still ugly) on the Zebra QL220 belt printer from my CE/CF app running on a Motorola MC3100 handheld:

public void PrintBarcode(string barcode, string UPC, string description, decimal listPrice)
{
    using (SerialPort serialPort = new SerialPort())
    {
        serialPort.BaudRate = 19200;
        serialPort.Handshake = Handshake.XOnXOff; 
        serialPort.DataBits = 8;
        serialPort.Parity = Parity.None;
        serialPort.StopBits = StopBits.One; // other choice is Two (see p. 14-21 in CPCL pdf)
        serialPort.PortName = "COM1:"; 

        serialPort.Open(); 

        Thread.Sleep(2500); // I don't know why this is needed, or if it really is...

        serialPort.Write("! 0 200 200 210 1\r\n");

        serialPort.Write("TEXT 4 0 30 40 Hola el Mundo\r\n"); //Bonjour le Monde --- Hola el Mundo --- Hallo die Welt
        serialPort.Write("TEXT 4 0 30 40 \r\n");

        serialPort.Write("BARCODE-TEXT 7 0 5\r\n"); 
        serialPort.Write(string.Format("BARCODE 128 1 1 50 150 10 {0}\r\n", barcode));
        serialPort.Write("TEXT 4 0 30 40\r\n");
        serialPort.Write("FORM\r\n");
        serialPort.Write("PRINT\r\n");

        serialPort.Close();
    }
}

...但是,总的来说,就像半个躁狂的青少年在一个沼泽地里一样-最后打印的条形码实际上是纸上的最高点,"Hola el Mundo"和看起来像"FOIPM"(那是怎么到达的?!?).

...but all together, like half-manic teens in a mosh pit - the barcode, printed last, is actually at the highest point on the paper, and the "Hola el Mundo" and what looks like "FOIPM" (how did that get there?!?), too.

如果"TEXT 4 0 30 40 \ r \ n" 不是发送CRLF的方法,那是什么?

If "TEXT 4 0 30 40\r\n" is not a way to send CRLFs, what is?

我注意到我在args中有一个错字来打印条形码.这个:

I noticed I had a typo in the args to print the barcode. This:

    serialPort.Write(string.Format("BARCODE 128 1 1 50 150 10 {0}\r\n", barcode));

...应该是这个:

    serialPort.Write(string.Format("BARCODE 128 1 1 50 150 130 {0}\r\n", barcode));

...但是当我固定"它(将垂直起始点从10更改为130)时,打印结果是相同的!对不起,我的法语,但是北达科他州正在发生什么?!?

...but when I "fixed" it (changed the vertical starting point from 10 to 130), the printed result was identical! Excuse my French, but what the North Dakota is going on here?!?

没关系,一旦我将修复程序添加到正确的位置,它就可以正常工作(将"10"更改为"130").现在,我必须使其变得智能",因为它将考虑先前的打印区域,并且始终在低于起始打印点+先前打印高度的位置打印后续行.

Never mind, once I add the fix to the right place, it does actually work (changing "10" to "130"). Now I've got to make it "smart" in that it will take into account previous printing areas and always print subsequent lines below the starting point + height of prior printings.

推荐答案

好像您是直接将CPCL写入打印机.您正在使用的TEXT命令在命令中包含x和y坐标本身-即,您正在编写的"30"和"40"告诉打印机始终将每行文本打印在坐标30,40处.尝试在要打印的每一行后续文本中更改这些坐标.据我所知,CPCL没有自动换行功能,因此您必须为每一行文本手动进行此操作.

It look's like you're writing CPCL directly to the printer. The TEXT command that you are using includes x and y coordinates itself in the command - namely, the '30' and '40' that you are writing is telling your printer to always print each line of text at the coordinates 30,40. Try changing these coordinates with each subsequent line of text that you want to print. To my knowledge, there is no 'auto-wrap' feature for CPCL, so you will have to do this manually for each line of text.

或者,您可以将打印机置于行打印模式.在这种模式下,打印机将只打印接收到的所有文本,而'\ r \ n'将使打印机在下一行开始打印.您可以通过向打印机发送以下命令来切换行打印模式:

Alternatively, you can put the printer in line-print mode. In this mode, the printer will simply print any text that it receives, and '\r\n' will cause the printer to start printing on the next line. You can toggle line print mode by sending the following command to the printer:

!U1 setvar"device.languages""line_print" [此处输入新行字符]

! U1 setvar "device.languages" "line_print" [NEW LINE CHARACTER HERE]

来源:CPCL手册- http://www.zebra.com/content/dam/zebra/manuals/en-us/printer/cpcl-pm-en.pdf

source: CPCL Manual - http://www.zebra.com/content/dam/zebra/manuals/en-us/printer/cpcl-pm-en.pdf

这篇关于即使我添加了crlf,为什么所有内容都打印在同一行上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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