发信人: melodies()
整理人: kingron(2000-12-05 19:16:59), 站内信件
|
【 在 fsilence (fslc) 的大作中提到: 】 : 求: : 连续纸打印,每次Append几行, : 打印机:EPSON LQ1600KIII : : 请千万在下面打个勾!!
我没有用过lq1600的打印机, 只用过松下1125的针打. 1125的驱动盘中带了一个控制码说明文件, 说明了1125仿真 epson lq 8xx打印机的码字. 我的控制方法是: 将打印口当作一个文件打开, 然后用文件流或者pascal的 文件读写函数写该文件, 直接送控制符给打印机. 例程部分如下(源文件太多,只贴一部分)
type { TPaperFeedAmount = ( pf6, //1/6 inch (4.23 mm) Name: ESC 2 pf8, // 1/8 inch (3.2 mm) Name: ESC 0 pf60, //1/60 inch Name: ESC A n (n = 0 to 127)DEC pf180, // 1/180 inch Name: ESC 3 n n = 0 to 255. pf360 // 1/360 inch Name: ESC + n (n = 0 to 255)DEC ); } TExtPrinter = class(TPrinter) private Port : string; //打印机所在的并行口; isPrinting : Boolean; //标志: 是否正在打印 cto : TCommTimeOuts; //读写文件时的TimeOut之设定 protected
public fsLPT : TFileStream; constructor Create(PortNum : Integer=1); destructor Destroy; override; published function BeginTxt : Boolean; procedure EndTxt; function Println(s : string) :Boolean; function Print(s : string) : Boolean; function PrintBufln(s : string) : Boolean; function PrintBuf(s : string) : Boolean; // function SetPaperFeedAmount(pfa: TPaperFeedAmount; Amount: Integer=1) :Boolean; // function SetPageLength(Inches : Integer) : Boolean;
//Amount是进纸或者退纸Amount * 1/180 Inches; bFormFeed是表示进纸还是退纸 function FeedPaperN180th(Amount : Integer; bFormFeed : Boolean) : Boolean; //Feeds paper n/180 inch after printing data in the line buffer. end;
var mPrint : TExtPrinter; implementation
constructor TExtPrinter.Create(PortNum : Integer=1); begin inherited Create; if not (PortNum in [1,2,3,4]) then Port := 'LPT1' else Port := 'LPT'+IntToStr(PortNum); isPrinting :=False; cto.WriteTotalTimeoutConstant := 500; //设定写端口的TimeOut时间是1000 ms cto.WriteTotalTimeoutMultiplier := 300; cto.ReadIntervalTimeout := 10; cto.ReadTotalTimeoutMultiplier :=100; cto.ReadTotalTimeoutConstant := 200; end;
destructor TExtPrinter.Destroy; begin inherited Destroy; end;
function TExtPrinter.BeginTxt : Boolean; var eMsg : string; begin if not isPrinting then begin try fsLPT := TFileStream.Create(Port,fmOpenReadWrite); if (not SetCommTimeouts(fsLPT.Handle,cto)) then begin // FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,nil, GetLastError,$804,PChar(eMsg),255,nil); // raise Exception.Create('设定CommTimeouts时出错!'+eMsg); end; isPrinting := True; Result := True; except on E: Exception do begin Result := False; raise; end; end; end else begin Result := False; //如果正在打印, 那么返回错误 end; end;
procedure TExtPrinter.EndTxt; begin if not isPrinting then Exit; if Assigned (fsLPT) then fsLPT.Destroy; isPrinting := False; end;
function TExtPrinter.Println(s : string) : Boolean; var tmp : string; begin if s[Length(s)] <> #10 then tmp := s+#10 else tmp :=s; if BeginTxt then begin try fsLPT.WriteBuffer(PChar(tmp)^,Length(tmp)); except on E: EWriteError do begin Result := False; EndTxt; raise; Exit; end; end; EndTxt; Result := True; end else begin Result :=False; end; end;
function TExtPrinter.Print(s : string) :Boolean; begin if BeginTxt then begin try fsLPT.WriteBuffer(PChar(s)^,Length(s)); except on E: EWriteError do begin Result := False; EndTxt; raise; Exit; end; end; EndTxt; Result := True; end else begin Result :=False; end; end;
function TExtPrinter.PrintBufln(s : string) : Boolean; var tmp : string; begin if s[Length(s)] <> #10 then tmp := s+#10 else tmp :=s; if isPrinting then begin try fsLPT.WriteBuffer(PChar(tmp)^,Length(tmp)); except on E: EWriteError do begin Result := False; raise; Exit; end; end; Result := True; end else Result := False; end;
function TExtPrinter.PrintBuf(s : string) :Boolean; begin if isPrinting then begin try fsLPT.WriteBuffer(PChar(s)^,Length(s)); except on E: EWriteError do begin Result := False; raise; Exit; end; end; Result := True; end else Result := False; end; { function TExtPrinter.SetPaperFeedAmount(pfa: TPaperFeedAmount; Amount: Integer=1) : Boolean; var s : string; n : Integer; begin n :=1; if (pfa = pf60) and (Amount > 127) then n := 127; if (pfa in [pf180,pf360]) and (Amount >255) then n := 255; if (pfa in [pf6,pf8]) then n := Amount; case pfa of pf6 : s := #27#2; pf8 : s := #27#0; pf60 : s := #27+'A'+StringOfChar(Chr(n),1); pf180: s := #27+'3'+StringOfChar(Chr(n),1); pf360: s := #27+'+'+StringOfChar(Chr(n),1); end; if (not isPrinting) and BeginTxt then begin Write(F,s); Result :=true; EndTxt; end else begin Result := False; end end; } function TExtPrinter.FeedPaperN180th(Amount : Integer; bFormFeed : Boolean) : Boolean; var s1 : string; s2 : string; LF : string; begin { Note: *Reverse paper feed cannot be executed in the area within 3.6inches (91.4 mm) of the bottom perforation. Additionally, the perforation should not be included in the area of reverse paper feed. } LF := #10; if bFormFeed then s1 := #27+'J' //进纸 else s1 := #27+'j'; //退纸 if Amount >255 then s2 := s1+StringOfChar(Chr(255),1) else s2 := s1+StringOfChar(Chr(Amount),1); if (not isPrinting) and BeginTxt then begin try fsLPT.WriteBuffer(PChar(s2)^,Length(s2)); except on E: EWriteError do begin Result := False; EndTxt; raise; Exit; end; end; EndTxt; Result := True; end else begin Result := False; end end;
my e-mail: [email protected]
-- ※ 来源:.网易 BBS bbs.netease.com.[FROM: 202.112.107.20]
|
|