I am trying to send commands directly to a Zebra TLP2844 printer. I followed the suggestion made here and my final code came to be as follows:
var cm: String; p: TPrinter; i: integer; begin p := Printer; p.BeginDoc; for i := 0 to memo1.Lines.Count-2 do begin cm := memo1.Lines[i]; if Escape(p.Canvas.Handle, PASSTHROUGH, Length(cm), PAnsiChar(cm), nil) = 0 then ShowMessage('Command error: ' + IntToStr(GetLastError)); end; p.EndDoc; end;
The content of memo1 is (first line is empty) as purposed here:
N q609 Q203,26 B26,26,0,UA0,2,2,152,B,"603679025109" A253,26,0,3,1,1,N,"SKU 6205518 MFG 6354" A253,56,0,3,1,1,N,"2XIST TROPICAL BEACH" A253,86,0,3,1,1,N,"STRIPE SQUARE CUT TRUNK" A253,116,0,3,1,1,N,"BRICK" A253,146,0,3,1,1,N,"X-LARGE" P1,1
The commands don't seem to be properly received or interpreted by the printer. I checked that the printer is in Page Mode (EPL2), with the suggested code I am able to open the printer handle. But nothing is printed, only a new line of labels is feeded.
I tried to completely change the commands to something obviously wrong and the behaviour is the same.
What else should I be looking to get things printed?
Most printers that take raw commands require a prefix (starting sequence of characters) and suffix (ending sequence of chars) wrapping each command. I don't know what the prefix and suffix are for the Zebra, but the documentation should tell you.
Just add a pair of constants to define the prefix and suffix, and add them to your command before sending it.
The other issue might be that you're reading the content of your commands from a TMemo
, which in Delphi 2009 and higher contains Unicode strings. You're then casting them down to PAnsiChar
, which may be truncating the content. Do the conversion ahead of time by defining cm
as an AnsiString
, and then assigning to it first (as you are) before typecasting to pass to the Escape
function. I've done this in my code to illustrate it.
var cm: AnsiString; p: TPrinter; i: integer; const ZPrefix = AnsiString('$('); // Replace values for each of these with what ZSuffix = AnsiString(')$'); // your documentation says you should use begin p := Printer; p.BeginDoc; for i := 0 to memo1.Lines.Count-2 do begin cm := ZPrefix + memo1.Lines[i] + ZSuffix; if Escape(p.Canvas.Handle, PASSTHROUGH, Length(cm), PAnsiChar(cm), nil) = 0 then ShowMessage('Command error: ' + IntToStr(GetLastError)); end; p.EndDoc; end;
I program in php which is like C
I can send things to the printer just fine
my code looks like your code the only thing is I am not sure how your programming language handles the newline in php it's \n at the end of each line
if the newline is not there the print job will not print
and if the " are not sent it will not print
your EPL looks fine and should print
there is somewhere on the zebra web site a download where you can send commands to a printer which is hooked up to your computer by USB cable
think it is called Zebra Setup Utilities