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.
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.