PosPrinter PrintMemoryBitmap 抛出非法异常
PosPrinter PrintMemoryBitmap throws illegal exception
我正在使用 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
错误代码 (here) 的含义,并且我已经确认 none 列出的内容存在问题。另外,考虑到 PrintBitmap(...)
函数工作得很好,这真的让我很困惑。
如有任何想法或建议,我们将不胜感激!
在PrintMemoryBitmap
之前和之后,尝试将ILegacyControlObject.BinaryConversion
属性更改为Nibble
或Decimal
并添加一个进程到return它至 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)
调用示例如下,代码在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 服务对象,您可以通过切换到它来毫无问题地打印。
OPOS ADK for .Net
错误信息中的Legacy.LegacyProxy
表示实际服务对象为OPOS
大多数情况下OPOS是按ANSI(MBCS)模式编译的,.NET是Unicode,所以OLE库会自动对BSTR进行编码转换,BSTR是PrintMemoryBitmap的Data参数
位图数据为二进制数据,包含大量0x00和无法转换为字符集的数据,因此转换后的数据将是无效数据。
参考资料:
POS for .NET Architecture (POS for .NET v1.12 SDK Documentation)
Integration of Legacy Service Objects (POS for .NET v1.12 SDK Documentation)
请参考从第 A-78 页开始的 System Strings(BSTR)
的描述。
我正在使用 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
错误代码 (here) 的含义,并且我已经确认 none 列出的内容存在问题。另外,考虑到 PrintBitmap(...)
函数工作得很好,这真的让我很困惑。
如有任何想法或建议,我们将不胜感激!
在PrintMemoryBitmap
之前和之后,尝试将ILegacyControlObject.BinaryConversion
属性更改为Nibble
或Decimal
并添加一个进程到return它至 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)
调用示例如下,代码在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 服务对象,您可以通过切换到它来毫无问题地打印。
OPOS ADK for .Net
错误信息中的
Legacy.LegacyProxy
表示实际服务对象为OPOS
大多数情况下OPOS是按ANSI(MBCS)模式编译的,.NET是Unicode,所以OLE库会自动对BSTR进行编码转换,BSTR是PrintMemoryBitmap的Data参数
位图数据为二进制数据,包含大量0x00和无法转换为字符集的数据,因此转换后的数据将是无效数据。
参考资料:
POS for .NET Architecture (POS for .NET v1.12 SDK Documentation)
Integration of Legacy Service Objects (POS for .NET v1.12 SDK Documentation)
请参考从第 A-78 页开始的 System Strings(BSTR)
的描述。