0

I have written a function that prints out ZPLII data to a Zebra printer as shown below

var
  St : string;

StartDocument(DocName);
StartPage;
Try
For I:=0 to DataToPrint.Count-1 do
 Begin
  St:=FormatPrintLine(I);
   Try
    Escape(PrinterHandle,PASSTHROUGH,Length(St),PAnsiChar(St),Nil);
   Except on E:Exception do
    begin
      GetWin32ApiErrorMessage(FErrorCode,FErrorText);
      Raise EPrinter.CreateFmt('Printer Write Error %d'+#13+
                               'While Printing To '+PrinterName+#13+
                               ErrorText,[ErrorCode]);
     end;
   End;
 end;
Finally
 EndPage;
 EndDocument;

I have tested the label data by using the command prompt to print it from a text file and the label prints out correctly but i cannot print it from my application. If i pause the printer i can see the job gets sent to the printer and the size of the job is 2.12Kb, roughly the size the label should be, but nothing prints out. The light on the Zebra printer for data lights up but nothing will print. I have tried this with two of the Zebra printers we own, so it is not a printer issue. My guess at this point is that maybe the program isn't sending the entire label data to the printer and the end is never received but when i trace through the send request, everthing is sent properly. the printer also shows the job has 0/0 pages for the label but i cannot understand why it is not sending the label. Is there something special that needs to go at the end of the label data besides the ^XZ termination character? I am also using Delphi XE3 if that helps.

Sir Rufo
  • 18,395
  • 2
  • 39
  • 73
aport002
  • 1,033
  • 3
  • 12
  • 17
  • Please add the declaration for variable `St` – Sir Rufo Aug 13 '13 at 00:34
  • Yes the declaration is there for that. I did not post the entire code but it is in the function variables @SirRufo – aport002 Aug 13 '13 at 01:00
  • 1
    Please add the declaration so that we can **see** it and know what type it is – Sir Rufo Aug 13 '13 at 01:16
  • St: String; <--that is the declaration @SirRufo – aport002 Aug 13 '13 at 01:22
  • 3
    What @SirRufo is asking is that you provide whatever `FormatPrintLine` is; the declaration of `St` (which appears to be a string) isn't really important, but as it's what you're sending to the printer, the **content** of it is needed. "My printer doesn't print when I send it an escape sequence I'm not going to show you. Why doesn't it work?" is pretty hard to answer. – Ken White Aug 13 '13 at 01:23
  • 1
    Yes, and it should be AnsiString – Sir Rufo Aug 13 '13 at 01:23
  • 2
    http://stackoverflow.com/questions/16969323/sending-commands-directly-to-zebra-epl?lq=1 – Sir Rufo Aug 13 '13 at 01:24
  • 1
    Looks like that did the trick. I thought because i was adding the PAnsiChar(st) as the string parameter that it would work but i guess not. Thanks for all your help – aport002 Aug 13 '13 at 01:39
  • 1
    @aport002 Please post your fixed code as a proper answer. You can then after a delay (1-2 days?) mark your answer as the correct one. – Jan Doggen Aug 13 '13 at 08:45

1 Answers1

0

Thanks to everyone's help I was able to successfully print my labels using the following changes:

St: AnsiString;
...
StartDocument(DocName);
StartPage;
Try
 For I:=0 to DataToPrint.Count-1 do
  Begin
   St:=FormatPrintLine(I);
    Try
     WritePrinter(PrinterHandle,PChar(St),Length(St),N);
    Except on E:Exception do
     begin
       GetWin32ApiErrorMessage(FErrorCode,FErrorText);
       Raise EPrinter.CreateFmt('Printer Write Error %d'+#13+
                               'While Printing To '+PrinterName+#13+
                               ErrorText,[ErrorCode]);
      end;
    End;
  end;
Finally
 EndPage;
 EndDocument;

I also had to change to writeprinter instead of escape. Escape did not print anything out after i change st to type AnsiString but writeprinter was successful.

aport002
  • 1,033
  • 3
  • 12
  • 17