ar F:TEXTFILE; BEGIN ASSIGNFILE(F,'LPT1');com2 com1 REWRITE(F); WRITELN(F,chr(27) '@'); //initial the printer WRITELN(F,'TEST1 FIRST LINE');你的内容 WRITELN(F,chr(12)); // move the paper to a new page CLOSEFILE(F); end; 你参看一下
WWWWA(aaaa) 谢谢你但是不好使
var f:txtfile; //f为txtfile类变量一个实例 begin assignfile(f,'lpt1'); //com1,com2 rewrite(f); //写方式 writein(f,chr(27) '@'); //初始化,我不明白? writein(f,'华联超市') //写内容 writein(f,chr(12)); //12是什么了? closefile(f); //关闭实例 end;你上面的是大写我是帮你翻释成小写好看一点?
txtfile这个类在那里定义的?它的源码在那里?
procedure TMain.StartBtnClick(Sender: TObject); var i,j : integer; dcb:TDCB; SetOK:Boolean; hNewCommFile:THandle; dwNumberOfBytesWritten:DWORD; MyIniFile: TIniFile; FilePath,Order,LastOrder,OrderAdd: string; secCount: integer; TF:TEXTFILE; AllNum:TStrings; ac : string; begin tCount:=0; FilePath := ExtractFilePath(Application.ExeName); MyIniFile := TIniFile.Create(FilePath+'TestPrn.ini'); hNewCommFile:=CreateFile('COM1',GENERIC_READ or GENERIC_WRITE,0,nil,OPEN_EXISTING, FILE_FLAG_OVERLAPPED,0); //hNewCommFile:=CreateFile('COM1', GENERIC_READ or GENERIC_WRITE, FILE_SHARE_READ //or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0); if(hNewCommFile=INVALID_HANDLE_VALUE) then begin //MessageBox(0,'打开端口错误','警告',MB_OK); //Result:=False; exit; end; SetupComm(hNewCommFile,1024,1024); GetCommState(hNewCommFile,dcb); dcb.BaudRate:=9600; dcb.ByteSize:=8; dcb.Parity:=NOPARITY; dcb.StopBits:=ONESTOPBIT; SetOK:=SetCommState(hNewCommFile,dcb); if(not SetOk)then begin MessageBox(0,'设置端口错误','警告',MB_OK); exit; end; CloseHandle(hNewCommFile); //Timer.Enabled:=True; //循环写入打印机命令 // MyIniFile.ReadSection('order',AllNum); // showmessage(AllNum.Strings[2]); for i:=0 to total-1 do begin OrderAdd :=''; ac :=''; CountText.Caption := inttostr(i); AssignFile(TF,'LPT1'); Rewrite(TF); begin Memo3.Lines.Clear; MyIniFile.ReadSection(inttostr(i),Memo3.Lines); secCount:=Memo3.Lines.Count; for j:=0 to secCount-1 do begin Order :=MyIniFile.ReadString(inttostr(i),inttostr(j),' '); Write(TF,'/测试命令:'+Order+'打印完毕 /'); OrderAdd := OrderAdd+' '+Order; ac := ac+chr(strtoint(Order)); end; Memo1.Lines.Add(OrderAdd); Memo1.Update; Write(TF,ac); PauseTime; end; CloseFile(TF); end; MyIniFile.Free;end;这是一个循环写入命令的例子,是做测试用的,命令是从INI文件里面读出的,写入并口最主要的就是AssignFile,如果是串口,初始化的时候改为'com1‘就可以了 DOS命令可以就用LPT1 文件名.TXT
因为NT架构下面想直接操作端口比较困难,除非你写驱动。你应该争取在window上的层面上找到其他办法。
F:TEXTFILE;
BEGIN
ASSIGNFILE(F,'LPT1');com2 com1
REWRITE(F);
WRITELN(F,chr(27) '@'); //initial the printer
WRITELN(F,'TEST1 FIRST LINE');你的内容
WRITELN(F,chr(12)); // move the paper to a new page
CLOSEFILE(F);
end;
你参看一下
f:txtfile; //f为txtfile类变量一个实例
begin
assignfile(f,'lpt1'); //com1,com2
rewrite(f); //写方式
writein(f,chr(27) '@'); //初始化,我不明白?
writein(f,'华联超市') //写内容
writein(f,chr(12)); //12是什么了?
closefile(f); //关闭实例
end;你上面的是大写我是帮你翻释成小写好看一点?
var
i,j : integer;
dcb:TDCB;
SetOK:Boolean;
hNewCommFile:THandle;
dwNumberOfBytesWritten:DWORD;
MyIniFile: TIniFile;
FilePath,Order,LastOrder,OrderAdd: string;
secCount: integer;
TF:TEXTFILE;
AllNum:TStrings;
ac : string;
begin
tCount:=0;
FilePath := ExtractFilePath(Application.ExeName);
MyIniFile := TIniFile.Create(FilePath+'TestPrn.ini');
hNewCommFile:=CreateFile('COM1',GENERIC_READ or GENERIC_WRITE,0,nil,OPEN_EXISTING,
FILE_FLAG_OVERLAPPED,0);
//hNewCommFile:=CreateFile('COM1', GENERIC_READ or GENERIC_WRITE, FILE_SHARE_READ
//or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0, 0); if(hNewCommFile=INVALID_HANDLE_VALUE) then
begin
//MessageBox(0,'打开端口错误','警告',MB_OK);
//Result:=False;
exit;
end;
SetupComm(hNewCommFile,1024,1024);
GetCommState(hNewCommFile,dcb);
dcb.BaudRate:=9600;
dcb.ByteSize:=8;
dcb.Parity:=NOPARITY;
dcb.StopBits:=ONESTOPBIT;
SetOK:=SetCommState(hNewCommFile,dcb);
if(not SetOk)then
begin
MessageBox(0,'设置端口错误','警告',MB_OK);
exit;
end;
CloseHandle(hNewCommFile);
//Timer.Enabled:=True;
//循环写入打印机命令
// MyIniFile.ReadSection('order',AllNum);
// showmessage(AllNum.Strings[2]); for i:=0 to total-1 do
begin
OrderAdd :='';
ac :='';
CountText.Caption := inttostr(i);
AssignFile(TF,'LPT1');
Rewrite(TF);
begin
Memo3.Lines.Clear;
MyIniFile.ReadSection(inttostr(i),Memo3.Lines);
secCount:=Memo3.Lines.Count;
for j:=0 to secCount-1 do
begin
Order :=MyIniFile.ReadString(inttostr(i),inttostr(j),' ');
Write(TF,'/测试命令:'+Order+'打印完毕 /');
OrderAdd := OrderAdd+' '+Order;
ac := ac+chr(strtoint(Order));
end;
Memo1.Lines.Add(OrderAdd);
Memo1.Update;
Write(TF,ac);
PauseTime;
end;
CloseFile(TF);
end;
MyIniFile.Free;end;这是一个循环写入命令的例子,是做测试用的,命令是从INI文件里面读出的,写入并口最主要的就是AssignFile,如果是串口,初始化的时候改为'com1‘就可以了
DOS命令可以就用LPT1 文件名.TXT