在 Delphi 中使用 OPOS 驱动程序检查打印机消息

发布于 2024-07-18 06:17:33 字数 155 浏览 9 评论 0原文

我正在尝试使用 Delphi (BDS2006) 中的 OPOS 驱动程序打开销售点 (POS) 打印机,但不知道如何检查打印机状态。

如何检查打印机中是否有诸如 Check PaperPaper Jam 之类的消息?

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.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

年华零落成诗 2024-07-25 06:17:33

我还没有使用过 OPOS 驱动程序,但我已经使用连接到现金抽屉的 Epson 收据打印机的 POS 驱动程序进行了一些工作。 我发现,如果打印机安装在 Windows 中,您就可以打开与它的直接连接并让它执行您想要的操作。

打印机速度如此之慢的原因是它使用了Windows的图形字体功能。 当你直接打开打印机时,你将模式设置为RAW,它只会像老式点阵一样发送文本。 要打开钱箱,您只需向其发送特定的控制代码,就像要打印它们一样。 打印机在打印之前拦截代码并踢开抽屉。

顺便说一句,我不知道这如何与 Unicode 一起使用。 我所使用的打印机只能处理 ASCII 数据。 可能会有专为国际市场设计的变体,其工作方式会有所不同。

这是我用来让它工作的代码(VxMsgBox 只是 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;

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.

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, 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.

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;
星星的轨迹 2024-07-25 06:17:33

您是否使用此处的 ActiveX 控件:http://monroecs.com/oposccos.htm? 它有一个错误状态事件。

Are you using the ActiveX control from here: http://monroecs.com/oposccos.htm? It has an event for error status.

就此别过 2024-07-25 06:17:33

首先,您必须为您的设备安装正确的支持软件,您可能需要从制造商的网站下载该软件。 请记住,有时,许多设备(如收据打印机)包含标准硬件(例如 EPSON TX-88III),尽管品牌名称可能有所不同。

支持软件通常包含驱动程序、配置工具以及可能的如何使用驱动程序的编程示例。 确保正确完成以下步骤:

  1. 驱动程序安装、配置工具已完成

  2. 设备已使用正确的电缆正确连接(我在查找时遇到问题)正确的串行电缆,因为它们有许多不同类型)

  3. 您的设备被配置软件(通过驱动程序)识别并且通信良好,至少它响应一些功能

  4. 使用与驱动程序一起安装的 ActiveX 控件。 它应该与驱动程序具有相似的名称。

完成上述步骤后,您的应用程序中将拥有一个控件,它为您提供所有可用的功能、状态属性和事件(对于纸张或其他任何内容)。

First of all you have to install the right support software for your device, which you probably have to download from the manufacturer's website. Keep in mind that sometimes, many devices (like receipt printers) contain standard hardware (ex EPSON TX-88III) although the brand name might differ.

The support software usually contains the driver, configuration tools, and possibly programming examples of how to use the driver. Make sure that the following steps are correctly completed:

  1. Installation of driver, config tools is done

  2. The device is correctly connected using the right cables (I had problems finding the correct serial cable, since there are many different types of them)

  3. Your device is recognised by the configuration software (through the driver) and communicates well, at least it responds to some functions

  4. Use the ActiveX control that was installed with the driver. It should have similar name with the driver.

After the above steps you will have a control in your application that provides you with all available functions, status properties and events (for paper, or anything other).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文