我创建了一个ActiveX控件,其中包含处理打印机的所有方法(Star TSP100),例如实例化,打开打印机等.Active正在com中注册。 当我通过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
答案 0 :(得分:0)
我有同样的问题,对于Bitmap,我有一个解决方法:
printer.PrintBitmap(PrinterStation.Receipt, path, PosPrinter.PrinterBitmapAsIs, PosPrinter.PrinterBitmapCenter);
打印机可能无法缩放位图。但是为了在将位图发送到打印机之前很容易扩展位图,我认为这是一个很好的解决方法。
对于条形码问题我只能说,我有错误的BarCodeSymbology(Ean13S而不是EanJan13)。如果我有进一步的见解,我会在这里分享。
答案 1 :(得分:0)
dlg :是打开文件对话框
cbAlignment :是包含三个值的Combobox:Left,Center,Right。
tbWidth 和 tbWidth :用于打印尺寸
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从未尝试过对不起,如果我找到了我会告诉你的东西,祝你好运。