简体   繁体   中英

How can I write to a Zebra QL220 using OpenNETCF.IO.Ports?

The "SerialPort" below is from OpenNETCF.IO.Ports.

Does this first pass/semi-edicated guess make sense for printing to a belt printer (Zebra QL220); that is, is it a decent starting point?

using (SerialPort serialPort = new SerialPort()) 
{
    string someString = "Bla";
    //serialPort.BaudRate = // I don't know what to put here yet, assuming this is needed
    //serialPort.DataBits = // " "
    //serialPort.Parity = // " "
    //serialPort.StopBits = // " "
    serialPort.PortName = "COM1"; // Is this what it wants?

    serialPort.Open();

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

    serialPort.Write(" ! U1 setvar \"device.languages\" \"line_print\"\r\n");
    serialPort.Write(" ! U SETLP 5 1 46\r\nPAGE-WIDTH 480\r\nSETBOLD 2\r\nPRINT\r\n");          
    serialPort.Write(" ! U1 CENTER\r\n"+someString"\r\n! U1 SETBOLD 0\r\n");
    serialPort.Write(" ! U1 CENTER\r\n");
    serialPort.Write(" ! U1 SETLP 0 2 24");

    serialPort.Close();
}

You might say, "Why don't you just try it and see?" but at present, at least, it's a long involved process to do that, because I can't run my app in my XP Mode VM on either deployment "Device" or Emulator (see How can I run my Windows CE project from within Visual Studio (2003)? if interested); what I need to do is copy the binary to the handheld to test any modified code; so, I'd rather be somewhat sure that it will work in some fashion before going through that rigamarole.

Yes, that is roughly what you want to do. You'll need to check the printer docos on what comm settings are required. It is typically 19200,N,8,1. With some printers, you need to pace how quickly you send the data. It is possible to send data so quickly that you exceed the serial data buffer on the printer. I recall, for example, having to add a small delay every 512 bytes sent or the tail end of a print stream would be lost. Not sure of the printer model though, so it is just something to keep an eye out for.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM