Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Delphi 发送特定于打印机的命令_Delphi_Binary Data_Magnetic Cards - Fatal编程技术网

Delphi 发送特定于打印机的命令

Delphi 发送特定于打印机的命令,delphi,binary-data,magnetic-cards,Delphi,Binary Data,Magnetic Cards,我这里有一个问题,我正在尝试将磁条数据编码到Fargo DTC400打印机,在规范中,它说我需要从示例记事本、写字板等发送以下字符串命令: ~1%TRACK NUMBER ONE? ~2;123456789? ~3;123456789? 本例对第一轨中的字符串以及第二轨和第三轨中的数字123456789进行编码。。这可以从Notepad.exe进行操作 编辑: 我使用的当前delphi代码在另一台打印机上工作: procedure SendQuote(MyCommand : AnsiStrin

我这里有一个问题,我正在尝试将磁条数据编码到Fargo DTC400打印机,在规范中,它说我需要从示例记事本、写字板等发送以下字符串命令:

~1%TRACK NUMBER ONE?
~2;123456789?
~3;123456789?
本例对第一轨中的字符串以及第二轨和第三轨中的数字123456789进行编码。。这可以从Notepad.exe进行操作

编辑: 我使用的当前delphi代码在另一台打印机上工作:

procedure SendQuote(MyCommand : AnsiString);
var
  PTBlock       : TPassThrough;

begin
  PTBlock.nLen := Length(MyCommand);
  StrPCopy(@PTBlock.SData, MyCommand);
  Escape(printer.handle, PASSTHROUGH, 0, @PTBlock, nil);
end;
当我试图从自己的应用程序中对这个字符串进行编码时,我遇到了麻烦,似乎打印机完全忽略了我的命令,当我选择“打印到文件”时,我可以读取二进制数据并在打印的文件中看到我的字符串,当我试着从示例notepad.exe打印到文件时,我得到的只是粗糙的二进制数据,根本找不到我的字符串

所以我想知道记事本做了什么来发送这个字符串命令,而我没有

希望有人能对此有所帮助,因为我渴望在我的应用程序中实现fargo支持已经有很长一段时间了

谢谢

更新。 下面的代码很古老,但它可以完成这项工作,但是有没有其他方法可以将其与上面的直通代码一起使用

var
  POutput: TextFile;
  k: Integer;
begin
  with TPrintDialog.Create(self) do
  try
    if Execute then
    begin
      AssignPrn(POutput);
      Rewrite(POutput);

      Writeln(POutput,'~1%TESTENCODER?');
      Writeln(POutput,'~2;123456789?');
      Writeln(POutput,'~2;987654321?');
      CloseFile(POutput);
    end;
  finally
    free;
  end
end;

TPassThrough的声明应如下所示:

type 
  TPassThrough = packed record 
    nLen  : SmallInt; 
    SData : Array[0..255] of AnsiChar; 
  end; 
您可能正在使用现代的Delphi 2009或更新版本,或者忘记了打包指令

另请参见此SO问题,了解更多信息

下面是FatihÖlçer编写的示例片段: 备注:修改后也可用于Unicode Delphi版本

{
  By using the Windows API Escape() function,
  your application can pass data directly to the printer.
  If the printer driver supports the PASSTHROUGH printer escape,
  you can use the Escape() function and the PASSTHROUGH printer escape
  to send native printer language codes to the printer driver.
  If the printer driver does not support the PASSTHROUGH printer escape,
  you must use the DeviceCapabilities() and ExtDevMode() functions instead.


  Mit der Windows API Funktion Escape() kann man Daten direkt zum Drucker schicken.
  Wenn der Drucker Treiber dies nicht unterstützt, müssen die DeviceCapabilities()
  und ExtDevMode() Funktionen verwendet werden.
}

//  DOS like printing using Passthrough command
// you should use "printer.begindoc" and "printer.enddoc"

type
  TPrnBuffRec = packed record
  bufflength: Word;
  Buff_1: array[0..255] of AnsiChar;
end;

function DirectToPrinter(S: AnsiString; NextLine: Boolean): Boolean;
var 
  Buff: TPrnBuffRec;
  TestInt: Integer;
begin
  TestInt := PassThrough;
  if Escape(Printer.Handle, QUERYESCSUPPORT, SizeOf(TESTINT), @testint, nil) > 0 then
  begin
    if NextLine then  S := S + #13 + #10;
    StrPCopy(Buff.Buff_1, S);
    Buff.bufflength := StrLen(Buff.Buff_1);
    Escape(Printer.Canvas.Handle, Passthrough, 0, @buff, nil);
    Result := True;
  end
  else
    Result := False;
end;

// this code works if the printer supports escape commands
// you can get special esc codes from printer's manual

//  example:
printer.BeginDoc;
try
  DirectToPrinter('This text ');
finally
  printer.EndDoc;
end;

TPassThrough的声明应如下所示:

type 
  TPassThrough = packed record 
    nLen  : SmallInt; 
    SData : Array[0..255] of AnsiChar; 
  end; 
您可能正在使用现代的Delphi 2009或更新版本,或者忘记了打包指令

另请参见此SO问题,了解更多信息

下面是FatihÖlçer编写的示例片段: 备注:修改后也可用于Unicode Delphi版本

{
  By using the Windows API Escape() function,
  your application can pass data directly to the printer.
  If the printer driver supports the PASSTHROUGH printer escape,
  you can use the Escape() function and the PASSTHROUGH printer escape
  to send native printer language codes to the printer driver.
  If the printer driver does not support the PASSTHROUGH printer escape,
  you must use the DeviceCapabilities() and ExtDevMode() functions instead.


  Mit der Windows API Funktion Escape() kann man Daten direkt zum Drucker schicken.
  Wenn der Drucker Treiber dies nicht unterstützt, müssen die DeviceCapabilities()
  und ExtDevMode() Funktionen verwendet werden.
}

//  DOS like printing using Passthrough command
// you should use "printer.begindoc" and "printer.enddoc"

type
  TPrnBuffRec = packed record
  bufflength: Word;
  Buff_1: array[0..255] of AnsiChar;
end;

function DirectToPrinter(S: AnsiString; NextLine: Boolean): Boolean;
var 
  Buff: TPrnBuffRec;
  TestInt: Integer;
begin
  TestInt := PassThrough;
  if Escape(Printer.Handle, QUERYESCSUPPORT, SizeOf(TESTINT), @testint, nil) > 0 then
  begin
    if NextLine then  S := S + #13 + #10;
    StrPCopy(Buff.Buff_1, S);
    Buff.bufflength := StrLen(Buff.Buff_1);
    Escape(Printer.Canvas.Handle, Passthrough, 0, @buff, nil);
    Result := True;
  end
  else
    Result := False;
end;

// this code works if the printer supports escape commands
// you can get special esc codes from printer's manual

//  example:
printer.BeginDoc;
try
  DirectToPrinter('This text ');
finally
  printer.EndDoc;
end;


这是一个编程问题网站。请告诉我你在Delphi代码中做了什么。你印刷得怎么样?别让我们猜你做错了什么。告诉我们你是怎么打印的。我会像这样测试对原始打印机端口的写入。有关原始打印信息,请参阅此链接。是的,我忘了粘贴我使用的代码,抱歉:我现在更新了。使用文本文件输出有什么问题?这似乎是一个清晰而简单的解决方案。TPassthrough的实现到底做了什么。你表现出了一种没有人能告诉你的高度。你有源代码。只需一步,直到您找到win32 api调用,或者找到一些低级别的调用,人们可以帮助您更好地理解它。现在,显示一个类调用另一个类TPassthrough-这是什么?不可回答。@LU RD,如果不是因为一件事,我会使用文本文件。我还需要发送位图到打印机,并结合这将不会很好地工作,我想,我的应用程序有两个选项,编码只,和编码与位图一起。单一编码使用文本文件没有问题,但结合位图,我必须结合begindoc和EndDoct。这是一个编程问题网站。请告诉我你在Delphi代码中做了什么。你印刷得怎么样?别让我们猜你做错了什么。告诉我们你是怎么打印的。我会像这样测试对原始打印机端口的写入。有关原始打印信息,请参阅此链接。是的,我忘了粘贴我使用的代码,抱歉:我现在更新了。使用文本文件输出有什么问题?这似乎是一个清晰而简单的解决方案。TPassthrough的实现到底做了什么。你表现出了一种没有人能告诉你的高度。你有源代码。只需一步,直到您找到win32 api调用,或者找到一些低级别的调用,人们可以帮助您更好地理解它。现在,显示一个类调用另一个类TPassthrough-这是什么?不可回答。@LU RD,如果不是因为一件事,我会使用文本文件。我还需要发送位图到打印机,并结合这将不会很好地工作,我想,我的应用程序有两个选项,编码只,和编码与位图一起。单一编码使用textfile没有问题,但与位图一起,我必须结合begindoc和enddocyes,我试图将所有内容都转换为unicode,但unicode对于这一部分来说并不是真正需要的,因为磁条仅限于ascii字符。。。虽然我尝试了这个声明,但没有任何改变。。。字符串似乎是以不同的方式发送的我明天将查看堆栈页面:现在对我来说太晚了,感谢al,现在将继续测试我今天已经测试了更多,在另一个程序中,notepad++它似乎也能够对我的打印机进行编码,在fargo的支持下,我正在做正确的事情,但这可能是字符编码问题吗?根据ascii表,~字符是126。其他人在32到95岁之间。我不明白为什么这会是一个编码问题。是的,这里也是。这很奇怪,我不知道
I don’我现在不知道从哪里开始寻找:上面的路线不起作用,我在begindoc之后和EndDoc之前发送此消息是的,我正在尝试使用unicode,但这部分并不真正需要unicode,因为磁条仅限于ascii字符。。。虽然我尝试了这个声明,但没有任何改变。。。字符串似乎是以不同的方式发送的我明天将查看堆栈页面:现在对我来说太晚了,感谢al,现在将继续测试我今天已经测试了更多,在另一个程序中,notepad++它似乎也能够对我的打印机进行编码,在fargo的支持下,我正在做正确的事情,但这可能是字符编码问题吗?根据ascii表,~字符是126。其他人在32到95岁之间。我不明白为什么这会是一个编码问题。是的,这里也是。这很奇怪,我现在不知道从哪里开始寻找:上面的路线不起作用,我在begindoc之后和enddoc之前发送这个