c# - PosPrinter PrintMemoryBitmap 抛出非法异常
问题描述
我正在使用Microsoft.PointOfService
库来控制 Epson POS 收据打印机。我正在尝试在收据上添加徽标,但我似乎无法使该PrintMemoryBitmap(...)
功能正常工作。该PrintBitmap(...)
功能工作得很好,但对于我的应用程序,从内存中打印位图会更有效,而不是将图像保存到文件系统中。
我的代码是:
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(...)
功能工作得很好,这真的让我很难过。
任何想法或建议将不胜感激!
解决方案
之前和之后PrintMemoryBitmap
,尝试将ILegacyControlObject.BinaryConversion
属性更改为Nibble
orDecimal
并添加一个进程以将其返回None
。
ILegacyControlObject 接口(POS for .NET v1.12 SDK 文档)
ILegacyControlObject 属性(POS for .NET v1.12 SDK 文档) ILegacyControlObject.BinaryConversion 属性(POS for .NET
v1.12 SDK 文档)
BinaryConversion 枚举(POS for .NET v1. 12 SDK 文档)
调用示例如下,在MainForm.cs
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); } }
或者,如果您的打印机有本机 POS for .NET 服务对象,则可以通过切换到该对象进行打印而不会出现问题。
.Net 的 OPOS ADK
Legacy.LegacyProxy
错误信息中表示实际服务对象为OPOS。
大多数情况下,OPOS 编译为 ANSI(MBCS) 模式,而 .NET 是 Unicode,所以 OLE 库会自动对 BSTR 进行代码转换,即 PrintMemoryBitmap 的 Data 参数。
位图数据是二进制数据,包含大量的0x00和无法转换为字符集的数据,所以转换后的数据将是无效数据。
参考资料:
POS for .NET Architecture(POS for .NET v1.12 SDK 文档)
集成旧服务对象(POS for .NET v1.12 SDK 文档)
请参阅System Strings(BSTR)
从 A-78 页开始的说明。
推荐阅读
- java - 使用子选择和窗口函数执行复杂查询时出现 SQLite Java 错误
- python - 如何在 matplolib 框架中以日期格式绘制数据框?
- excel - 用于检查字母和计算单词的 Excel 公式
- java - Elasticsearch7.3中SpringBoot的NoClassDefFoundError异常
- typescript - TypeScript:使用通用扩展?
- c# - 更改 WCF 参考网址 .Net Core
- javascript - JS中是否可以动态设置要解构的属性?
- typescript - 创建递归样式对象时的打字稿问题
- google-earth-engine - 如何从 Google 地球引擎导出图像集合?
- mule - 无法使用(`String`,`Array 调用`++`
`)