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();
}
}
...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.
If "TEXT 4 0 30 40\r\n"
is not a way to send CRLFs, what is?
UPDATE
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));
...this should have been this:
serialPort.Write(string.Format("BARCODE 128 1 1 50 150 130 {0}\r\n", barcode));
...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?!?
UPDATE 2
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.