Zebra Printer Direct Link

Based on this question , I applied the following code to send direct commands to the Zebra TLP2844

var cmm: AnsiString; i: integer; begin commands.saveToFile('path\to\a\file'); Printer.BeginDoc; cmm := ''; for i := 0 to commands.Count-1 do cmm := cmm + commands[i] + #10; Escape(Printer.Canvas.Handle, PASSTHROUGH, Length(cmm), PAnsiChar(cmm), nil); Printer.EndDoc; end; 

commands is a TSringList containing all the commands that I want to send to the printer. Please note that I save all the commands in a text file.

Well, if I send this text file for printing using the driver settings, using tools β†’ Action β†’ Send file, it will print fine.

If I use the code above, after printing it overlays a few extra lines of labels.

It shows me, obviously, that I am doing something wrong here, but I cannot understand that.

What i tried

  • Send commands one by one, and not concatenate them, as in the code. Results: nothing is printed.
  • Change # 10 to # 13 # 10. Results: The same insane behavior (indeed, the Zebra EPL document claims to ignore any found # 13).

What else should I try to send commands to the printer just like Zebra does?

+4
source share
3 answers

AFAIK, you need to format the buffer as expected using the ExtEscape() API layout. I never used Escape() , but ExtEscape() - and worked with a Zebra printer.

This is what the MSDN doc says :

lpszInData [in] Pointer to the input structure required for the specified escape. The first word in the buffer contains the number of bytes of input data. The remaining bytes of the buffer contain the data itself.

So you can specify this as such:

  cmm := '00'; // reserve space for the initial `word` for i := 0 to commands.Count-1 do cmm := cmm + commands[i] + #10; pword(cmm)^ := length(cmm)-2; // store the length if ExtEscape(Printer.Canvas.Handle, PASSTHROUGH, Length(cmm), pointer(cmm), 0, nil)<0 then raise Exception.Create('Error at printing to printer'); Printer.EndDoc; 

Keep in mind that if your command is poorly formatted (for example, missing characters), it can simply create a memory error in the print spooler - yes, I saw it! In this case, you may need to kill and then restart the print spooler service ... fix your code ... and try again ...

And don't forget to put the ESC character at the beginning of each of your commands[] , as required by the Zebra document.

+2
source

If you want to use the Windows printer driver, you must use WritePrinter , which is defined without a WinSpool block. If I see this correctly, the TPrinter object from the Printers block does not provide it to the FPrinterHandle member, so you may need to use OpenPrinter and ClosePrinter yourself.

When working with MarkPoint printers at work, which are somewhat similar to Zebra printers: if the printer is connected to a serial port, I would strongly recommend trying and accessing the printer directly by connecting it to the serial port with one of the available components.

0
source

you can use this procedure: where LabelFile is the full path to the label file, we use this code and work with the universal text printer driver, and the printer is installed as the default printer. It works with zebra printer and Windows XP operating system. fooobar.com/questions/1500430 / ... I hope this helps you.

0
source

Source: https://habr.com/ru/post/1500427/


All Articles