1

ここで問題が発生しました。磁気ストライプデータをFargoDTC400プリンターにエンコードしようとしています。仕様では、メモ帳、ワードパッドなどから次の文字列コマンドを送信する必要があると書かれています。

~1%TRACK NUMBER ONE?
~2;123456789?
~3;123456789?

この例では、文字列をトラック1にエンコードし、番号123456789をトラック2と3の両方にエンコードします。これは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;
4

1 に答える 1

4

TPassThroughは次のように宣言する必要があります:

type 
  TPassThrough = packed record 
    nLen  : SmallInt; 
    SData : Array[0..255] of AnsiChar; 
  end; 

最新のDelphi(2009以降)を使用しているか、パックされたディレクティブを忘れている可能性があります。

コマンドを直接プリンタに送信する正しい方法については、このSOの質問も参照してください。

Torry'sには、サンプルスニペット(FatihÖlçerによって作成)があります。備考:UnicodeDelphiバージョンでも使用できるように変更されています。

{
  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;
于 2012-03-21T21:26:21.140 に答える