繁体   English   中英

PosPrinter PrintMemoryBitmap 抛出非法异常

[英]PosPrinter PrintMemoryBitmap throws illegal exception

我正在使用Microsoft.PointOfService库来控制 Epson POS 收据打印机。 我正在尝试在收据上添加徽标,但我似乎无法让PrintMemoryBitmap(...) function 工作。 PrintBitmap(...) function 工作得很好,但是对于我的应用程序,从 memory 打印 bitmap 会更有效,而不是将图像保存到文件系统。

我的代码是:

printer.PrintMemoryBitmap(PrinterStation.Receipt, logoBitmap, PosPrinter.PrinterBitmapAsIs, PosPrinter.PrinterBitmapCenter);

但是当我运行它时,我收到以下错误:

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

我已经检查了Illegal错误代码的含义( 这里),并且我已经确认那里列出的所有内容都没有问题。 另外,考虑到PrintBitmap(...) function 工作得很好,这真的让我很难过。

任何想法或建议将不胜感激!

PrintMemoryBitmap之前和之后,尝试将ILegacyControlObject.BinaryConversion属性更改为NibbleDecimal并添加一个进程以将其返回为None
IlegacyControlObject 接口(.NET v1.12 SDK 文档的 POS)
IlegacyControlObject 属性(.NET v1.12 SDK 文档的 POS)
IlegacyControlObject.BinaryConversion 属性(.NET v1.12 SDK 文档的 POS)
BinaryConversion 枚举(.NET v1.12 SDK 文档的 POS)

调用方式示例如下,编码在 POS for .NET SDK 示例应用的MainForm.cs中。

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

或者,如果您的打印机有本机 POS for .NET 服务 object,则可以通过切换到它来毫无问题地打印。
OPOS ADK for.Net


错误信息中的Legacy.LegacyProxy表示实际服务object是OPOS。

大多数情况下,OPOS 编译为 ANSI(MBCS) 模式,.NET 为 Unicode,所以 OLE 库会自动对 BSTR 进行代码转换,即 PrintMemoryBitmap 的 Data 参数。

Bitmap数据为二进制数据,包含大量0x00和无法转换为字符集的数据,因此转换后的数据将是无效数据。

参考资料:
.NET 架构的 POS(.NET v1.12 SDK 文档的 POS)
旧服务对象的集成(.NET v1.12 SDK 文档的 POS)

统一POS

下载UnifiedPOS的当前版本1.14.1

请参阅从 A-78 页开始的System Strings(BSTR)的说明。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM