0

我创建了一个 ActiveX 控件,其中包含处理打印机(Star TSP100)的所有方法,例如实例化、打开打印机等。ActiveX 正在 com.xml 中注册。当我通过 javascript 使用打印机方法时,所有方法都可以正常工作,除了 PrintBarCode 和 PrintBitmap 方法并引发错误。

对于我使用过的位图:-

printer.PrintBitmap(PrinterStation.Receipt, path, percentWidth * lineWidth / 100, PosPrinter.PrinterBitmapCenter);

对于条形码:-

printer.PrintBarCode(PrinterStation.Receipt, code, BarCodeSymbology.Code93, 80, (int)(0.9 * lineWidth), PosPrinter.PrinterBarCodeCenter, BarCodeTextPosition.Below);

虽然这两种方法也在 Visual Studio 的调试模式下工作。但是在创建设置并在系统中安装之后,这两个都不起作用。

错误是: -

Microsoft.PointOfService.PosControlException: Method PrintBarCode threw an exception.  Attempt was made to perform an illegal or unsupported operation with the device, or an invalid parameter value was used.
   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.InvokeMethodAndCheckImpl(String methodName, Object[] parameters)
   at Microsoft.PointOfService.Legacy.LegacyProxy.InvokeMethodAndCheck(String methodName, Object param1, Object param2, Object param3, Object param4, Object param5, Object param6, Object param7)
   at Microsoft.PointOfService.Legacy.LegacyPosPrinter.PrintBarCode(PrinterStation station, String data, BarCodeSymbology symbology, Int32 height, Int32 width, Int32 alignment, BarCodeTextPosition textPosition)
   at xyx.testclass.PrintBarCode(String code)
ErrorCode: Illegal
ErrorCodeExtended: 0
4

2 回答 2

0

I have the same problem and for the Bitmap I have a workaround:

printer.PrintBitmap(PrinterStation.Receipt, path, PosPrinter.PrinterBitmapAsIs, PosPrinter.PrinterBitmapCenter);

Maybe the printer is not able to scale bitmaps. But for it's easy to scale your bitmap before sending it to the printer, I think this is a good workaround.

For the Barcode problem I can only say, that I had the wrong BarCodeSymbology (Ean13S instead of EanJan13). If I have further insights, I'll share them here.

于 2012-10-12T14:48:10.710 回答
0

dlg : 是打开文件对话框

cbAlignment:是包含三个值的组合框:Left、Center、Right。

tbWidthtbWidth:用于打印的大小

cbTextPosition : 用于文本位置

这是一个屏幕截图:

在此处输入图像描述

我有Epson-T20,代码对我来说很好:

//In the loading of the form : to init cbTextPosition
cbTextPosition.Items.Clear();
cbTextPosition.Items.AddRange(Enum.GetNames(typeof (BarCodeTextPosition)));

并打印:

try
            {
                //Show the Open File Dialog Box
                OpenFileDialog dlg = new OpenFileDialog();
                dlg.Filter = "Image files|*.bmp;*.gif;*.jpg";

                //Try It First With Monochrome Bmp Image : try it with 384x384 px
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    //Init your stuff here
                    PosExplorer explorer;
                    DeviceInfo _device;
                    PosPrinter _oposPrinter;

                    explorer = new PosExplorer();
                    _device = explorer.GetDevice(DeviceType.PosPrinter, "T20PRINTER");

                    _oposPrinter = (PosPrinter) explorer.CreateInstance(_device);
                    _oposPrinter.Open();
                    if (!_oposPrinter.Claimed)
                    {
                        _oposPrinter.Claim(5000);
                        _oposPrinter.DeviceEnabled = true;
                        PrinterStation CurrentStation = PrinterStation.Receipt;

                        //This is a Header :
                        _oposPrinter.PrintNormal(PrinterStation.Receipt, "Here is your LOGO : ");

                        //Printing Your Logo :
                        int alignment; 
                        if (cbAlignment.Text == "Left")
                            alignment = PosPrinter.PrinterBarCodeLeft;
                        else if (cbAlignment.Text == "Center")
                            alignment = PosPrinter.PrinterBarCodeCenter;
                        else if (cbAlignment.Text == "Right")
                            alignment = PosPrinter.PrinterBarCodeRight;
                        else
                            alignment = int.Parse(cbAlignment.Text, System.Globalization.CultureInfo.CurrentCulture);

                        //Print it : you can try 384px for real size in tbWidth
                        _oposPrinter.PrintBitmap(
                            CurrentStation,
                            dlg.FileName,
                            int.Parse(tbWidth.Text, System.Globalization.CultureInfo.CurrentCulture),
                            alignment);

                        //Cutting your Paper :
                        _oposPrinter.CutPaper(95);
                    }

                }

            }
            catch (Exception c)
            {
                MessageBox.Show(c.Message);
            }

对于 Codebar 从未尝试过,对不起,如果我找到了我会告诉你的东西,祝你好运。

于 2014-03-21T20:10:41.737 回答