Question

Based on this question I have implemented the following code to send direct commands to my 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 I want to send to the printer. Note that I save all the commands to a text file.

Well, if I send this text file to print, via the driver preferences, using tools -> Action -> Send File, it prints perfectly.

If I use the code above, it spits some extra rows of labels after printing.

It shows me, obviously, that I am doing something wrong here, but I can't figure out what.

What I have tried

  • Send commands one by one and not concatenating them like in the code. Results: Nothing gets printed.
  • Changing #10 for a #13#10. Results: Same crazy behaviour (indeed Zebra EPL documentatins says it will ignore any #13 it finds)

What else should I try in order to send to the printer the commands the exact same way Zebra's tool does?

Était-ce utile?

La solution

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

Here is what the MSDN doc states:

lpszInData [in] A 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 may code 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;

Be aware that if your command is not well formatted (e.g. missing chars), it may just create an out of memory error in the printer spooler - yes, I've seen that! In this case, you may have to kill then restart the Printer Spooler service... fix your code... and try again...

And do not forget to put the ESC character at the beginning of each of your commands[], as requested by the Zebra doc.

Autres conseils

you can use this procedure: where the LabelFile is the full path of the label file,we are using this code and works with generic text driver printer and the printer is set as the default printer. it works with zebra printer and windows xp operating system. https://stackoverflow.com/a/27647044/2977139 i hope this will help you.

If you want to use the Windows printer driver, you should use WritePrinter defined un the WinSpool unit. If I see this correctly, the TPrinter object from the Printers unit doesn't expose it's FPrinterHandle member, so you might need to use OpenPrinter and ClosePrinter yourself.

Having worked with MarkPoint printers at work, which are somewhat similar to Zebra printers: if the printer is connect to a serial port, I would warmly suggest to try and access the printer directly by connecting to the serial port with one of the several components available.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top