0

I am trying to print an image on Epson TM-T20II. Here is my code:

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!!!");
}

When I run it I got the next error:

Method SetBitmap threw an exception. A class-specific error condition ocurred. the error condition code is available in the ResultCodeExtended property

I want to read the ResultCodeExtended property but i cant find how, do I have to configure the ErrorEvent? Or how is it suppouse to read it?

Fernando Santiago
  • 2,128
  • 10
  • 44
  • 75

2 Answers2

0

ResultCodeExtended is a property of ControlObject.

Your OPOSHelper.printer is probably a library created by someone, you would be using internal ControlObject via the library.

If OPOSHelper.printer does not expose ResultCodeExtended, you can not know it.

Please check the specification of OPOSHelper.printer, or the corresponding source code.

AustinWBryan
  • 3,249
  • 3
  • 24
  • 42
kunif
  • 4,060
  • 2
  • 10
  • 30
0

Wrap the code in a try/catch. The SetBitmap function is part of the POS for .NET framework.

See this link to view documentation on the SetBitmap Function:https://learn.microsoft.com/en-us/previous-versions/windows/embedded/ms843078(v%3dwinembedded.11)

Your try catch should be typecasting the exception to at the very least a POSControlException:

SetBitmap may throw a PosControlException with the following ErrorCodes:

Illegal

One of the following conditions has occurred:

The specified station is invalid—it must be either Slip or Receipt.

The specified station does not support printing of bitmaps (that is, the appropriate CapSlpBitmap or CapRecBitmap property is set to false).

The printer is currently in Insertion mode. The printer is currently in Removal mode. The number that is specified for bitmapNumber is less than 1 or greater than 20 and therefore invalid.

The value for width is less than or equal to zero but not set to PrinterBitmapAsIs and therefore invalid.

NoExist

fileName was not found.

Extended

ExtendedErrorTooBig: The bitmap is either too wide to print without transformation, or it is too big to transform.

ExtendedErrorBadFormat: The specified file is either not a bitmap file, or it is in an unsupported format.

If you set a breakpoint at your catch, you'll see the details about the ResultCodeExtended property, I'm sure.