如何向并口直接发送字符串?(用于Pos机)救急!!(50分)

K

Kevin

Unregistered / Unconfirmed
GUEST, unregistred user!
用AssignPrn建立文件与打印端口的连接,然后对端口输出字符串,
(已按pos机格式),但不打印。
哪为大虾有此经验,请救急!!!
 
你往端口写时, 打印机的指示灯有无变化. 不要写的端口不对,以为写的方法不对.
 
var
F: TextFile;
s: String[1];
begin

s := #12;
AssignFile(F, 'LPT1');
Rewrite(F);
Writeln(F, 'Test');
Writeln(F, s');
//有些打印机要输入换页符才开始打印,此行可以删除
CloseFile(F);
end;


 
如果用95的话,简单的办法是用Int 17h中断。用NT的话可以用Escape的
PASSTHROUGH子功能直接向打印机输出。
 
让我们看一下来自Inprise的正宗回答吧。
Question and Answer Database

FAQ651D.txt Writting a raw string of data to the printer.
Category :Windows API
Platform :All
Product :All 32 bit

Question:
Howdo
I write a raw string of a data to the printer?


Answer:
Under Win16, you can use the SpoolFile function, or the
Passthrough escape if the printer supports it. This is detailed in
TI3196 - Direct Commands to Printer - Passthrough/Escape available
from the Borland web site. Under Win32, you should use WritePrinter.

The following is an example of opening a printer and writing a raw
string of data to the printer. Note that you must send the correct
printer name, such as "HP LaserJet 5MP" for the function to succeed.
You are also responsible for embedding any necessary control codes
that the printer may require.

uses WinSpool;

procedure WriteRawStringToPrinter(PrinterName:String;
S:String);
var
Handle: THandle;
N: DWORD;
do
cInfo1: TDocInfo1;
begin

if not OpenPrinter(PChar(PrinterName), Handle, nil) then

begin

ShowMessage('error ' + IntToStr(GetLastError));
Exit;
end;

withdo
cInfo1do
begin

pDocName := PChar('testdo
c');
pOutputFile := nil;
pDataType := 'RAW';

end;

StartDocPrinter(Handle, 1, @DocInfo1);
StartPagePrinter(Handle);
WritePrinter(Handle, PChar(S), Length(S), N);
EndPagePrinter(Handle);
EndDocPrinter(Handle);
ClosePrinter(Handle);
end;


procedure TForm1.Button1Click(Sender: TObject);
begin

WriteRawStringToPrinter('HP', 'Test This');
end;


 
可以采用API
CreateFile
WriteFile
CloseFile
可以编制出并口打印机,也可以对串口打印机有效。
不过,用于POS程序开发特别前台程序最好是在DOS下采用C/C++直接写
程序最好。
 
多人接受答案了。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
顶部