Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending data to USB printer in Delphi

How do I send text commands to a printer connected in the USB port using Delphi?

I have a Zebra TLP2844 printer and want to program a direct communication with it.

like image 610
Ricardo Acras Avatar asked Jun 05 '13 20:06

Ricardo Acras


1 Answers

You use the WinAPI function Escape, passing it the Printer.Canvas.Handle as the first parameter and PASSTHROUGH as the nEscape parameter.

var
  YourCommand: String;
begin
  YourComamnd := 'Your command here';

  if Escape(Printer.Canvas.Handle, 
                PASSTHROUGH, 
                Length(YourCommand), 
                PChar(YourCommand), 
                nil) <> 0 then
    // Handle return value (listed in docs link above)
  else
    // send next command 

Escape is defined in the Windows unit. Note you have to call Printer.StartPage before using this function in order to prepare the printer driver to receive content.

like image 156
Ken White Avatar answered Sep 29 '22 01:09

Ken White