我使用的是LQ-670K+T,请问如何在DELPHI 中实现对打印机的控制,如进纸、退纸等。

解决方案 »

  1.   

    发送esc字符
    搜一下rawprint,我有个程序就是这样做的,lq300k,需要的话,联系
      

  2.   

    可参考LQ-670K+T的打印指令,应用LQ-670K+T的打印指令对打印机进行控制,这样可实现你所要求的效果
      

  3.   

    帖子太长,分三部分
    1、使用代码uses RAWPRINT,PrtRaw;procedure HeaderPrint();
    var
       headfile:Textfile;
    begin
       AssignRawPrn(headfile);
       Rewrite(headfile);
       if(firstprnfg=0) then
            write(headfile,#12);      //换页
       firstprnfg:=0;
       write(headfile,#10,#13,#10,#13);
       writeln(headfile,'xxxxxxxx    ',FormatDateTime('yyyy - MM - DD',Now),'        ',FormatDateTime('hh:mm:ss',Now));
       writeln(headfile,' ');
       writeln(headfile,'时间      发起方  机车号(个呼号)  线路号(组号) 行程号  车站       信息           指令              来源');
       closefile(headfile);
    end;procedure InitPrint();
    var
       initfile:Textfile;
    begin
       AssignRawPrn(initfile);
       Rewrite(initfile);
       write(initfile,#27,#64);
       write(initfile,#28,#107,#0);         //字体宋体
       write(initfile,#27,#51,#35);             //n/60英寸行间距
       write(initfile,#27,#108,#5);        //左边距5列
       write(initfile,#27,#67,#0,#11);         // 每页11英寸
       //write(initfile,#27,#78,#2);          //页缝空白2行
       write(initfile,#27,#68,#5,#11,#18,#24,#27,#31,#40,#49,#0); //水平定位
       closefile(initfile);
        pntrownum:=0;
        firstprnfg:=1;
    end;
      

  4.   

    2 unit PrtRaw;
    {----------------------------------------------------------
    Copyright (c) 1998 by Joe C. Hecht - All rights Reserved
    [email protected] You may use and share this unit
    providing my name and the copyright notice stays intact.
    ----------------------------------------------------------}
    {
    Usage notes:
      1) Caller is responsible for embedding all necessary control codes that the
         printer may require (including carriage return/line feed and form feed codes).  2) Caller must specify a valid printer and port name when calling StartRawPrintJob.
    }interfaceuses
      WinTypes;{$IFDEF WIN32}
    type SpoolInt = DWORD;
    {$ELSE}
    type SpoolInt = integer;
    {$ENDIF}function StartRawPrintJob(PrinterName : pChar;
                              Port : pChar;
                              DocName : pChar) : THandle;function StartRawPrintPage(hPrn : THandle) : integer;function PrintRawData(hPrn : THandle;
                          Buffer : pointer;
                          NumBytes : SpoolInt) : integer;function EndRawPrintPage(hPrn : THandle) : integer;function EndRawPrintJob(hPrn : THandle) : integer;
    implementation
    uses
       WinProcs,
    {$IFDEF WIN32}
    WinSpool;
    {$ELSE}
    Print;
    {$ENDIF}
    function StartRawPrintJob(PrinterName : pChar;
                              Port : pChar;
                              DocName : pChar) : THandle;
    {$IFDEF WIN32}
    var
       hPrn : THandle;
       DocInfo1 : TDocInfo1;
    {$ENDIF}
    begin
    {$IFDEF WIN32}
       if (OpenPrinter(PChar(PrinterName),
                       hPrn,
                       nil) = FALSE)  then begin
         Result := THandle(-1);
         Exit;
       end;
       DocInfo1.pDocName := DocName;
       DocInfo1.pOutputFile := Port;
       DocInfo1.pDataType := 'RAW';
       if (StartDocPrinter(hPrn,
                           1,
                           @DocInfo1) = 0) then begin
         Result := THandle(-1);
         exit;
       end;
       Result := hPrn;
    {$ELSE}
      result := OpenJob(Port,
                        DocName,
                        0);
    {$ENDIF}
    end;function StartRawPrintPage(hPrn : THandle) : integer;
    begin
    {$IFDEF WIN32}
       if (StartPagePrinter(hPrn) = FALSE) then begin
         Result := -1;
         exit;
       end;
       result := 1;
    {$ELSE}
      result := StartSpoolPage(hPrn);
    {$ENDIF}
    end;
    function PrintRawData(hPrn : THandle;
                          Buffer : pointer;
                          NumBytes : SpoolInt) : integer;
    {$IFDEF WIN32}
    var
      BytesWritten : DWORD;
    {$ENDIF}
    begin
      if (NumBytes = 0) then begin
        Result := 1;
        exit;
      end;
    {$IFDEF WIN32}
       if (WritePrinter(hPrn,
                        Buffer,
                        NumBytes,
                        BytesWritten) = FALSE) then begin
         Result := -1;
         exit;
       end;
       if (NumBytes <> BytesWritten) then begin
         Result := -1;
         exit;
       end;
       Result := 1;
    {$ELSE}
      result := WriteSpool(hPrn,
                           Buffer,
                           NumBytes);
    {$ENDIF}
    end;
    function EndRawPrintPage(hPrn : THandle) : integer;
    begin
    {$IFDEF WIN32}
       if (EndPagePrinter(hPrn) = FALSE) then begin
         Result := -1;
         exit;
       end;
       Result := 1;
    {$ELSE}
      result := EndSpoolPage(hPrn);
    {$ENDIF}
    end;
    function EndRawPrintJob(hPrn : THandle) : integer;
    begin
    {$IFDEF WIN32}
       if (EndDocPrinter(hPrn) = FALSE) then begin
         Result := -1;
         exit;
       end;
       if (ClosePrinter(hPrn) = FALSE) then begin
         Result := -1;
         exit;
       end;
       Result := 1;
    {$ELSE}
      result := CloseJob(hPrn);
    {$ENDIF}
    end;
    end.
      

  5.   

    3{$A+,B-,E+,F-,I+,N-,R-,S+,V-}
    unit RawPrint;interfaceuses
      Windows, SysUtils;type
        ERawPrinterException = class(Exception);    TWinRawPrinter = class
          protected
            FPrnHandle : THandle;
          public
            constructor Create(const PrinterName, PortName : string);
            destructor Destroy; override;
            procedure LineFeed;
            procedure FormFeed;
            procedure WriteBuf(P : Pointer; BufLen : Integer);
            procedure Write(const S : string);
            procedure WriteLn(const S : string);
            property PrnHandle : THandle read FPrnHandle;
          end;procedure AssignRawPrn(var F : Text);
      {-Sets up a text file device driver for sending raw data to the current Windows
        printer}implementationuses
      Printers, PrtRaw;
    {----------------------------- TWinRawPrinter -------------------------------}constructor TWinRawPrinter.Create(const PrinterName, PortName : string);
    begin
      FPrnHandle := StartRawPrintJob(PChar(PrinterName), PChar(PortName),
                                     'TWinRawPrinter Document');
      if Integer(FPrnHandle) < 0 then
        raise ERawPrinterException.Create('StartRawPrintJob failed');  if StartRawPrintPage(FPrnHandle) < 0 then begin
        EndRawPrintJob(FPrnHandle);
        raise ERawPrinterException.Create('StartRawPrintPage failed');
      end;
    end;  { Create }destructor TWinRawPrinter.Destroy;
    begin
      EndRawPrintPage(FPrnHandle);
      EndRawPrintJob(FPrnHandle);
    end;  { Destroy }procedure TWinRawPrinter.LineFeed;
    const
      ctCRLF : array[1..2] of Char = (#13, #10);
    begin
      WriteBuf(@ctCRLF, SizeOf(ctCRLF));
    end;  { LineFeed }procedure TWinRawPrinter.FormFeed;
    const
      ctFF : Char = #12;
    begin
      WriteBuf(@ctFF, SizeOf(ctFF));
    end;  { FormFeed }procedure TWinRawPrinter.WriteBuf(P : Pointer; BufLen : Integer);
    begin
      PrintRawData(FPrnHandle, P, BufLen);
    end;  { WriteBuf }procedure TWinRawPrinter.Write(const S : string);
    begin
      WriteBuf(@S[1], Length(S));
    end;  { Write }procedure TWinRawPrinter.WriteLn(const S : string);
    begin
      Write(S);
      LineFeed;
    end;  { WriteLn }const
      {This does NOT limit the length of strings that can be printed using the text
       file device driver. Strings longer than 256 chars can safely be printed.}
      ctRawPrnBufSize = 256;
    type
      TRawPrnBuffer = array[0..ctRawPrnBufSize-1] of Char;
    var
      RawPrnBuffer  : TRawPrnBuffer;
      WinRawPrinter : TWinRawPrinter = nil;function RawPrnInput(var F: TTextRec): Integer;
      {-Called when a Read or Readln is applied to a printer file. Since reading is
        illegal this routine tells the I/O system that no characters were read,
        which generates a runtime error.}
    begin
      with F do begin
        BufPos := 0;
        BufEnd := 0;
      end;
      Result := 0;
    end;  { RawPrnInput }function RawPrnOutput(var F: TTextRec): Integer;
      {-Called when a Write or Writeln is applied to a printer file. Sends the raw
        data directly to the printer via the WinRawPrinter.}
    begin
      WinRawPrinter.WriteBuf(F.BufPtr, F.BufPos);
      F.BufPos := 0;
      Result   := 0;
    end;  { RawPrnOutput }function RawPrnIgnore(var F: TTextRec): Integer;
      {-Will ignore certain requests by the I/O system such as flush while doing an
        input. }
    begin
      Result := 0;
    end;  { RawPrnIgnore }function RawPrnClose(var F: TTextRec): Integer;
      {-Destroys the TWinRawPrinter that was created by RawPrnOpen}
    begin
      WinRawPrinter.Free;
      WinRawPrinter := nil;
      Result := 0;
    end;  { RawPrnClose }function RawPrnOpen(var F: TTextRec): Integer;
      {-If opening for output (Rewrite or Append), creates the WinRawPrinter that
        will be used for sending raw data to the printer}
    var
      Device     : array[0..cchDeviceName-1] of Char;
      DriverName : array[0..MAX_PATH-1] of Char;
      Port       : array[0..32] of Char;
      DevHandle  : THandle;
    begin
      with F do
        if Mode = fmInput then begin
          {Reading is illegal. RawPrnInput will cause a runtime error when it is
           called by Read or ReadLn.}
          InOutFunc := @RawPrnInput;
          FlushFunc := @RawPrnIgnore;
          CloseFunc := @RawPrnIgnore;
        end else begin
          {If Append was called, Mode will be fmInOut. Must be changed to fmOutput
           before exiting.}
          Mode      := fmOutput;
          InOutFunc := @RawPrnOutput;
          FlushFunc := @RawPrnOutput;
          CloseFunc := @RawPrnClose;      {Get the printer name and port name of the current printer}
          Printer.GetPrinter(Device, DriverName, Port, DevHandle);      {Create a TWinRawPrinter using the name and port of the current printer}
          WinRawPrinter := TWinRawPrinter.Create(Device, Port);
        end;
      Result := 0;
    end;  { RawPrnOpen }procedure AssignRawPrn(var F : Text);
      {-Sets up a text file device driver for sending raw data to the current Windows
        printer}
    begin
     with TTextRec(F) do begin
       Mode     := fmClosed;
       BufSize  := SizeOf(RawPrnBuffer);
       BufPtr   := @RawPrnBuffer;
       BufPos   := 0; {Omitted from Delphi Help example, but absolutely needed!}
       Name[0]  := #0;
       {Set the OpenFunc. Don't set InOutFunc, FlushFunc, or CloseFunc here because
        they will be set when the OpenFunc is called. That way they can be set to
        different functions depending on whether we're opening for output (rewrite
        or append) or input (reset).}
       OpenFunc := @RawPrnOpen;
     end;
    end;  { AssignRawPrn }end.  { unit RawPrint }
      

  6.   

    bitter():看不懂啊 ,惭愧阿!解释一下