SEND转义命令到收据打印机

时间:2014-09-22 22:44:15

标签: delphi printing escaping

我正在尝试用delphi xe 6编写订单打印程序。我在互联网上找到了这个代码

  type
  TPassThroughData = record
      nLen: Word;
      Data: array[0..255] of Byte;
  end;

procedure PrintText(s: string);
var
  PTBlock: TPassThroughData;
begin
  PTBlock.nLen := Length(s);
  StrPCopy(@PTBlock.Data, s);
  Escape(Printer.Handle, PASSTHROUGH, 0, @PTBlock, nil);
end;

procedure PrintOut;
begin
  Printer.BeginDoc;
  PrintText(#27'&l12D' + 'Hello, World!');
  Printer.EndDoc;
end;

并且它的工作不像我想要的那样。它打印空行并剪切纸张,纸张上没有任何数据。我正在使用IBM收据打印机type4610-1nr。我想问你们有什么想法我可以在上面打印数据吗?

1 个答案:

答案 0 :(得分:0)

在像IBM 4610这样的打印机上打印,将字符串放在输出流上有点复杂......我不知道这里的Printer对象是什么,但是我可以给出的建议你要仔细阅读Programming Guide of the printer

无论如何要在不剪纸的情况下打印单行,在发送该行的ASCII数据后,您应该放置此命令行:

X'0A'

请注意,正如有人正确说明:打印机只能处理 ASCII 数据字符串,因此您需要在Delphi XE中使用AnsiString。 。