I'm using the Microsoft.PointOfService
library to control an Epson POS receipt printer. I'm trying to add logos to the receipts, but I can't seem to get the PrintMemoryBitmap(...)
function to work. The PrintBitmap(...)
function works just fine, but for my application, it would be much more efficient to print a bitmap from memory, instead of saving the image to the file system.
My code is:
printer.PrintMemoryBitmap(PrinterStation.Receipt, logoBitmap, PosPrinter.PrinterBitmapAsIs, PosPrinter.PrinterBitmapCenter);
But when I run this, I get the following error:
ErrorCode:
Illegal
ExtendedErrorCode:
300002
Message:
Method PrintMemoryBitmap threw an exception. Attempt was made to perform an illegal or unsupported operation with the device, or an invalid parameter value was used.
StackTrace:
at Microsoft.PointOfService.Legacy.LegacyProxy.ThrowLegacyMethodException(String methodName, Int32 ResultCode, Exception e)
at Microsoft.PointOfService.Legacy.LegacyProxy.InvokeMethod(String methodName, Object[]& parameters, Boolean[] byRef)
at Microsoft.PointOfService.Legacy.LegacyProxy.InvokeMethodAndCheckImpl(String methodName, Object[]& parameters, Boolean[] byRef)
at Microsoft.PointOfService.Legacy.LegacyProxy.InvokeMethodAndCheck(String methodName, Object param1, Object param2, Object param3, Object param4, Object param5)
at Microsoft.PointOfService.Legacy.LegacyPosPrinter.PrintMemoryBitmap(PrinterStation station, Bitmap data, Int32 width, Int32 alignment)
at ReceiptLogoDemo.frmPrinterDemo.btnPrintLogo_Click(Object sender, EventArgs e) in C:\projects\receiptLogoDemo\receiptLogoDemo\frmPrinterDemo.cs:line 138
I have checked the meaning of the Illegal
error code (here), and I have confirmed that none of the things listed there are the issue. Also, considering that the PrintBitmap(...)
function works just fine, this really has me stumped.
Any ideas or suggestions would be greatly appreciated!
Before and after PrintMemoryBitmap
, try changing the ILegacyControlObject.BinaryConversion
property to Nibble
or Decimal
and add a process to return it to None
.
ILegacyControlObject Interface (POS for .NET v1.12 SDK Documentation)
ILegacyControlObject Properties (POS for .NET v1.12 SDK Documentation)
ILegacyControlObject.BinaryConversion Property (POS for .NET v1.12 SDK Documentation)
BinaryConversion Enumeration (POS for .NET v1.12 SDK Documentation)
An example of how to call it is as follows, which is coded in MainForm.cs
of the sample application of POS for.NET SDK.
ILegacyControlObject co = pc as ILegacyControlObject; cbBinaryConversion.Enabled = (co != null); if (co != null && pc.State != ControlState.Closed) { try { cbBinaryConversion.Text = co.BinaryConversion.ToString(); } catch(Exception){} } else { cbBinaryConversion.Text = ""; }
private void cbBinaryConversion_SelectedIndexChanged(object sender, System.EventArgs e) { PosDeviceTag tag = currentDevice; if (tag == null) return; try { PosCommon posCommon = tag.posCommon; if (posCommon is ILegacyControlObject) ((ILegacyControlObject) posCommon).BinaryConversion = (BinaryConversion) Enum.Parse(typeof(BinaryConversion), cbBinaryConversion.Text); } catch(Exception ae) { ShowException(ae); } }
Alternatively, if you have a native POS for.NET service object for your printer, you may be able to print without problems by switching to it.
OPOS ADK for .Net
Legacy.LegacyProxy
in the error information indicates that the actual service object is OPOS.
In most cases, OPOS is compiled in ANSI(MBCS) mode and .NET is Unicode, so the OLE library will automatically do the code conversion for the BSTR, which is the Data parameter of PrintMemoryBitmap.
Bitmap data is binary data and contains a large number of 0x00 and data that cannot be converted to character sets, so the converted data will be invalid data.
Reference materials:
POS for .NET Architecture (POS for .NET v1.12 SDK Documentation)
Integration of Legacy Service Objects (POS for .NET v1.12 SDK Documentation)
Please refer the description of System Strings(BSTR)
starting with page A-78.