Board index » delphi » How to send commands direct to LPT1 like in Dos with Delphi5

How to send commands direct to LPT1 like in Dos with Delphi5

I want to send direct commands to a fujitsu dot matrix printer. The commands
are in ASCII, dezimal or hex signs. How can I realize it?

Thanks for your help

Mathias

 

Re:How to send commands direct to LPT1 like in Dos with Delphi5


Something like:

procedure PrintPCL;
var
 Handle : THandle;
 numwrite : DWORD;
 Docinfo1 : TDocInfo1;
 PrintFile, InFile, SampForm : TMemoryStream;
 buffer : array[0..4096] of char;
 HPLetter, HPLegal, NC : array[0..15] of char;
 temp : array[0..3] of char;
 FF : char;
 numread : longint;
 x : integer;
 FileName : String;
begin
 If(OpenPrinter(PrinterName,Handle,nil)) then
  begin
   FF := Chr(12);
   strcopy(HPLetter,chr(27));
   strcat(HPLetter,'&l6d66p1h2A');
   strcopy(HPLegal,chr(27));
   strcat(HPLegal,'&l6d84p4h3A');
   strcopy(NC,chr(27));
   strcat(NC,'&l');
   strcat(NC,StrPCopy(temp,InttoStr(NumCopies)));
   strcat(NC,'X');
   try
    PrintFile := TMemoryStream.Create;
    for x := 0 to Printlist.Count - 1 do
      begin
        FileName := Copy(PrintList[x],1,pos(',',printlist[x])-1);
        InFile := TMemoryStream.Create;
        InFile.LoadFromFile(FileName);
        If(Integer(filename[Length(FileName)-1]) = 49) then
          PrintFile.Write(HPLetter,Strlen(HPLetter))
        else
          PrintFile.Write(HPLegal,Strlen(HPLegal));
        PrintFile.Write(NC,strlen(NC));
        PrintFile.CopyFrom(InFile,0);
        InFile.Free;
        If Sample Then
          Begin
            try
              SampForm := TMemoryStream.Create;
              SampForm.LoadFromFile(AppPath + 'SAMPLE.PRN');
              PrintFile.Copyfrom(SampForm, 0);
            finally
              SampForm.Free;
            end;
          End;
        PrintFile.Write(FF,SizeOf(FF));
      end;
      DocInfo1.pDocName := PChar('PCLPrinter');
      DocInfo1.pOutputFile := nil;
      DocInfo1.pDataType := 'RAW';
      PrintFile.Seek(0,0);
      StartDocPrinter(Handle,1,@DocInfo1);
      StartPagePrinter(Handle);
      numread := 0;
      numwrite := 0;
      while (numread = numwrite) AND (PrintFile.Position <> PrintFile.Size)
do
        begin
          numread := PrintFile.Read(buffer,sizeof(buffer));
          WritePrinter(Handle, @buffer,numread,numwrite);
          UpdateProgress(round((PrintFile.Position/PrintFile.Size)*100));
        end;
   EndPagePrinter(Handle);
   EndDocPrinter(Handle);
   ClosePrinter(Handle);
   finally
     PrintFile.Free;
   end;
  end;
end;

The procedure above spools a RAW PCL file to the printer. Mainly you need to
use the WritePrinter API call along with OpenPrinter. It should be pretty
easy to change the above into what you need.

DD

Other Threads