0

我正在尝试在 Epson TM-T20II 上打印图像。这是我的代码:

string path = @"test.bmp";
if (File.Exists(path))
{
    Console.WriteLine("exists");
    OPOSHelper.printer.ErrorEvent += Printer_ErrorEvent; // Do I have to configure this?
    OPOSHelper.printer.SetBitmap(1, PrinterStation.Receipt, path, PosPrinter.PrinterBitmapAsIs, PosPrinter.PrinterBitmapCenter);
    OPOSHelper.printer.PrintNormal(PrinterStation.Receipt, "\x1B|1B");                     
}
else
{
    Console.WriteLine("DOES NOT EXIST!!!");
}

当我运行它时,我得到了下一个错误:

方法 SetBitmap 引发了异常。发生了特定于类的错误情况。错误条件代码在 ResultCodeExtended 属性中可用

我想阅读ResultCodeExtended property但我找不到如何,我必须配置ErrorEvent吗?或者它应该如何阅读?

4

2 回答 2

0

将代码包装在 try/catch 中。SetBitmap 函数是 POS for .NET 框架的一部分。

请参阅此链接以查看有关 SetBitmap 函数的文档:https://docs.microsoft.com/en-us/previous-versions/windows/embedded/ms843078(v%3dwinembedded.11)

您的 try catch 应该至少将异常类型转换为 POSControlException:

SetBitmap 可能会抛出带有以下错误代码的 PosControlException:

Illegal

出现以下情况之一:

指定的站点无效 - 它必须是 Slip 或 Receipt。

指定的工作站不支持位图的打印(即,适当的 CapSlpBitmap 或 CapRecBitmap 属性设置为 false)。

打印机当前处于插入模式。打印机当前处于移除模式。为 bitmapNumber 指定的数字小于 1 或大于 20,因此无效。

宽度值小于或等于零,但未设置为 PrinterBitmapAsIs,因此无效。

NoExist

找不到文件名。

Extended

ExtendedErrorTooBig:位图要么太宽而无法在不转换的情况下打印,要么太大而无法转换。

ExtendedErrorBadFormat:指定的文件不是位图文件,或者是不受支持的格式。

如果您在捕获时设置断点,您将看到有关 ResultCodeExtended 属性的详细信息,我敢肯定。

于 2018-08-17T14:09:24.090 回答
0

ResultCodeExtended是 的一个属性ControlObject

OPOSHelper.printer可能是由某人创建的库,您将ControlObject通过该库使用内部。

如果OPOSHelper.printer不暴露ResultCodeExtended,你就无法知道。

请查看 的规范OPOSHelper.printer或相应的源代码。

于 2018-07-21T01:02:26.630 回答