2012-10-03 102 views
0

我創建了一個ActiveX控件,其中包含處理打印機(Star TSP100)的所有方法,如實例化,打印機等。ActiveX正在註冊com。 當我通過javascript使用打印機方法時,除PrintBarCode和PrintBitmap方法外,所有方法都正常工作,並引發錯誤。PosPrinter.PrintBarCode,PosPrinter.PrintBitmap在PrintNormal工作時不工作

位圖我用: -

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 

回答

0

我有同樣的問題,併爲位圖我有一個解決辦法:

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

也許打印機不能夠擴展位圖。但是,在將位圖發送到打印機之前,很容易縮放位圖,我認爲這是一個很好的解決方法。

對於條碼問題,我只能說,我有錯誤的BarCodeSymbology(Ean13S而不是EanJan13)。如果我有進一步的見解,我會在這裏分享。

0

DLG:是打開文件對話框

cbAlignment:是包含三個值組合框:左,中,右。

tbWidthtbWidth:用於印刷

cbTextPosition的大小:對於文本位置

這裏是一個屏幕截圖:

enter image description here

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

對於條形碼數據從來沒有嘗試過對不起,如果我找到的東西,我會告訴你,好運氣的傢伙。