2012-03-21 2 views
1

여기에 메모장, 워드 패드 등에서 다음 문자열 명령을 보내야한다고 지정하는 사양에서 Fargo DTC400 프린터에 자기 스트라이프 데이터를 인코딩하려고하는데 문제가 있습니다.프린터 특정 명령 보내기

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

이 예제는 트랙 1의 문자열과 트랙 2와 3의 숫자 123456789를 인코딩합니다. 이것은 Notepad.exe에서 작동합니다.

편집 : 다른 프린터에 작품을 사용 현재 델파이 코드 :

난 내 자신의 응용 프로그램에서이 문자열을 인코딩하려고
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에서 파일로 인쇄하려고하면 이진 데이터를 문질러서 문자를 찾을 수 없습니다. ..

그래서 메모장에서 th 내가하지 말아야 할 문자열 명령인가?

장기간 내 응용 프로그램에서 fargo 지원을 구현하기 위해 열심히 노력했기 때문에 누군가가이 문제를 해결할 수 있기를 바랍니다.

감사

업데이트. 다음 코드는 고대이지만 작업을 수행하지만 위의 통과 코드에서이 코드를 사용할 수있는 또 다른 방법이 있습니까? 당신은 현대 델파이 (2009 이상) 사용하고있는

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

또는 포장 지시어를 잊어 :

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; 
+3

이것은 프로그래밍 관련 질문 웹 사이트입니다. 델파이 코드에서 무엇을하고 있는지 말해주십시오. 너 어떻게 지내니? 우리가 뭘 잘못하고 있는지 짐작하지 마십시오. 인쇄 방법을 알려주십시오. 이렇게 원시 프린터 포트에 쓰는 것을 테스트했을 것입니다. 원시 인쇄 정보는이 링크를 참조하십시오. http://www.efg2.com/Lab/Library/Delphi/Printing/index.html –

+1

예 사용하는 코드를 붙여 넣는 것을 잊어 버렸습니다. 죄송합니다. 지금 업데이트했습니다. – Plastkort

+0

'TextFile' 출력을 사용하는 것이 잘못된 이유는 무엇입니까? 명확하고 간단한 해결책처럼 보입니다. –

답변

4

은 TPassThrough는 다음과 같이 선언한다.

correct-way-to-send-commands-directly-to-printer에 대한 본 질문도 참조하십시오.

Torry's에는 예제 코드 단편 (Fatih Ölçer 작성)이 있습니다. 비고 : 유니 코드 델피 버전에서도 사용하도록 수정되었습니다.

{ 
    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; 
+0

네, 유니 코드로 만들려고 노력하고 있지만 유니 코드는이 부분에 필요하지 않습니다. 마그네틱 스트라이프는 아스키 문자로 제한되어 있기 때문에 ... altho는이 선언을 시도했지만 아무 것도 변경되지 않았습니다. 다른 방법 – Plastkort

+1

나는 내일 스택 페이지를 보게 될 것이다 :) 지금 나를 위해 너무 늦었 어, 지금은 감사하다. – Plastkort

+0

나는 alittlebit를 다른 프로그램에서 테스트하고있다. notepad ++ 또한 가능할 것 같다. 내 printern을 인코딩하고, fargo에서 지원에서 올바른 일을하고 있지만, 이것이 문자 인코딩 문제가 될 수도 있습니까? – Plastkort