以前我用过LQ300K打印机的票据打印:
试试看
procedure PrintData(hLpt: THandle;
szData: string);
var
PRIn, iNum, endtime: DWORD;
tOut: TCommTimeouts;
lapped: TOverlapped;
begin
FillChar(tOut, SizeOf(tOut), 0);
tOut.WriteTotalTimeoutMultiplier := 15;
tOut.WriteTotalTimeoutConstant := 1000;
SetCommTimeouts(hLpt, tOut);
FillChar(lapped, SizeOf(lapped), 0);
lapped.hEvent := CreateEvent(nil, True, False, nil);
while Truedo
begin
if not WriteFile(hLpt, (PChar(szData))^, Length(szData), iNum, nil) then
begin
iNum := 0;
if GetLastError() = ERROR_IO_PENDING then
begin
endtime := GetTickCount() + 1000;
while not GetOverlappedResult(hLpt, lapped, iNum, False)do
begin
if GetTickCount() > endtime then
begin
Application.MessageBox( '超时错误!', '打印出错!',
mb_Ok or mb_ICONEXCLAMATION);
break;
end
end;
// break;
end
else
begin
PRIn:=Application.MessageBox('请检查打印机连线是否正确, 电源是否打开,'
+Chr(13)+Chr(10)+'打印纸是否准备好! 重试吗?', '打印出错!',
mb_RETRYCANCEL or mb_ICONQUESTION);
if PRIn=IDCancel then
begin
Application.MessageBox('您将丢失此票据打印, 请打印此票据!',
'打印出错!',mb_Ok or mb_ICONINFORMATION);
Break;
end;
//清除打印机内存数据
end;
end
else
begin
ResetEvent(lapped.hEvent);
Break;
end;
end;
ResetEvent(lapped.hEvent);
end;
procedure AllTjPrint(lp1:string);
var
hPrintFile: THandle;
szPrint: string;
begin
hPrintFile := CreateFile(
'LPT1',
GENERIC_READ or GENERIC_WRITE,
0,
nil,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL or FILE_FLAG_OVERLAPPED,
0);
if hPrintFile = INVALID_HANDLE_VALUE then
begin
ShowMessage('访问打印设备出错!');
Exit;
end;
szPrint := '';//打印控制码+打印内容+#12
PrintData(hPrintFile, szPrint);
CloseHandle(hPrintFile);
end;
具体打印机的打印控制码不一样!根据控制码调试