使用Delphi中的OPOS驱动程序检查打印机信息 [英] Checking Printer Messages using OPOS Drivers in Delphi

查看:334
本文介绍了使用Delphi中的OPOS驱动程序检查打印机信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Delphi(BDS2006)中的OPOS驱动程序打开销售点(POS)打印机,但是没有关于如何检查打印机状态的线索。

I'm trying to open a Point of Sale (POS) printer using the OPOS Drivers in Delphi (BDS2006), but don't have a clue on how to check the printer status.

如何从打印机检查邮件,如检查纸张卡纸? / p>

How would I check for messages like Check Paper and Paper Jam from the printer?

推荐答案

我没有使用OPOS驱动程序,但我已经完成了一些工作与POS驱动程序连接到一个现金抽屉的爱普生收据打印机。我发现的是,如果打印机安装在Windows中,则可以打开直接连接到它,并使其执行任何您想要的。

I haven't used OPOS Drivers but I have done some work with POS Drivers for an Epson receipt printer connected to a cash drawer. What I discovered was that, if the printer is installed in Windows, you can then open a direct connection to it and make it do whatever you want.

打印机如此缓慢的原因是它使用Windows的图形字体功能。当您直接打开打印机时,您将将模式设置为RAW,并且只会像旧样式的点阵一样发送文本。要打开现金抽屉,您只需要发送具体的控制代码,就像打算打印一样。打印机打印之前会拦截代码,并打开抽屉。

The reason the printer is so slow is that it's using the graphical font functions of Windows. When you open the printer directly, you will set the mode to RAW and it will just send text out like an old-style dot-matrix. To kick the cash drawer open, you just send it the specific control codes as if you were going to print them. The printer intercepts the codes before it prints and kicks the drawer open.

BTW,我不知道如何使用Unicode。打印机我只是真正使用ASCII数据。可能会为国际市场设计不同的变体。

BTW, I have no idea how this would work with Unicode. The printer I had only really worked with ASCII data. There might be variants designed for international markets that would work differently.

这是我用来使其工作的代码(VxMsgBox只是MessageBox的封面):

Here's the code I've used to make it work (VxMsgBox is just a cover to MessageBox):

{***************************************************************************}
{**             PrintDirect2Printer                                       **}
{***************************************************************************}
procedure PrintDirect2Printer(PrinterName, Data:pchar; dwByteCount:DWORD);
var PrinterHandle  : THandle;
    DocInfo        : TDocInfo1;
    dwJob          : DWORD;
    dwBytesWritten : DWORD;
begin
if not OpenPrinter(PrinterName, PrinterHandle, nil) then exit; //failed to open printer, abort
DocInfo.pDocName    := 'Direct 2 Printer';
DocInfo.pOutputFile := nil;
DocInfo.pDataType   := 'RAW';
dwJob:=StartDocPrinter(PrinterHandle, 1, @DocInfo);
if dwJob=0 then //failed to start a document
   begin
   ClosePrinter(PrinterHandle);
   exit;
   end;
if not StartPagePrinter(PrinterHandle) then
   begin
   EndDocPrinter(PrinterHandle);
   ClosePrinter(PrinterHandle);
   exit;
   end;
if not WritePrinter(PrinterHandle, Data, dwByteCount, dwBytesWritten) then
   begin
   EndPagePrinter(PrinterHandle);
   EndDocPrinter(PrinterHandle);
   ClosePrinter(PrinterHandle);
   exit;
   end;
if not EndPagePrinter(PrinterHandle) then
   begin
   EndDocPrinter(PrinterHandle);
   ClosePrinter(PrinterHandle);
   exit;
   end;
if not EndDocPrinter(PrinterHandle) then
   begin
   ClosePrinter(PrinterHandle);
   exit;
   end;
ClosePrinter(PrinterHandle);
if dwBytesWritten<>dwByteCount then
   VxMsgBox('Print Direct To Printer failed.', 'Printer Error', mb_Ok);
end;

{***************************************************************************}
{**             OpenPrintDirect2Printer                                   **}
{***************************************************************************}
function OpenPrintDirect2Printer(PrinterName, DocName:pchar; var PrinterHandle:THandle):boolean;
var DocInfo        : TDocInfo1;
    dwJob          : DWORD;
begin
result:=false;
if not OpenPrinter(PrinterName, PrinterHandle, nil) then exit; //failed to open printer, abort
DocInfo.pDocName    := DocName;
DocInfo.pOutputFile := nil;
DocInfo.pDataType   := 'RAW';
dwJob:=StartDocPrinter(PrinterHandle, 1, @DocInfo);
if dwJob=0 then //failed to start a document
   begin
   ClosePrinter(PrinterHandle);
   exit;
   end;
if not StartPagePrinter(PrinterHandle) then
   begin
   EndDocPrinter(PrinterHandle);
   ClosePrinter(PrinterHandle);
   exit;
   end;
result:=true;
end;

{***************************************************************************}
{**             WritePrintDirect2Printer                                  **}
{***************************************************************************}
function WritePrintDirect2Printer(PrinterHandle:THandle; Data:pchar; dwByteCount:DWORD):boolean;
var dwBytesWritten : DWORD;
begin
result:=true;
if not WritePrinter(PrinterHandle, Data, dwByteCount, dwBytesWritten) then
   result:=false;
if dwBytesWritten<>dwByteCount then
   VxMsgBox('WritePrintDirect2Printer byte check failed.', 'Printer Error', mb_Ok);
end;


{***************************************************************************}
{**             ClosePrintDirect2Printer                                  **}
{***************************************************************************}
procedure ClosePrintDirect2Printer(var PrinterHandle:THandle);
begin
if not EndPagePrinter(PrinterHandle) then
   begin
   EndDocPrinter(PrinterHandle);
   ClosePrinter(PrinterHandle);
   PrinterHandle:=0;
   exit;
   end;
if not EndDocPrinter(PrinterHandle) then
   begin
   ClosePrinter(PrinterHandle);
   PrinterHandle:=0;
   exit;
   end;
ClosePrinter(PrinterHandle);
PrinterHandle:=0;
end;

这篇关于使用Delphi中的OPOS驱动程序检查打印机信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆