I have created an ActiveX control which contains all the methods to handle a printer (Star TSP100) such as instantiating, Opening printer etc. The ActiveX is being registered in the com.
When i am using printers methods through javascript, all methods are working fine except PrintBarCode and PrintBitmap method and throwing an error.
For bitmap i have used :-
printer.PrintBitmap(PrinterStation.Receipt, path, percentWidth * lineWidth / 100, PosPrinter.PrinterBitmapCenter);
and for barcode :-
printer.PrintBarCode(PrinterStation.Receipt, code, BarCodeSymbology.Code93, 80, (int)(0.9 * lineWidth), PosPrinter.PrinterBarCodeCenter, BarCodeTextPosition.Below);
Although these two methods are also working in debug mode from visual studio. but after creating the setup and installing in the system it these two are not working.
The error is :-
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
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.
dlg : is Open File Dialog
cbAlignment : is Combobox containing the three values : Left, Center, Right.
tbWidth and tbWidth : for the size of the printing
cbTextPosition : For the text position
Here is a Screen shot :
i have Epson-T20, code works fine for me :
//In the loading of the form : to init cbTextPosition
cbTextPosition.Items.Clear();
cbTextPosition.Items.AddRange(Enum.GetNames(typeof (BarCodeTextPosition)));
And to print :
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);
}
For the Codebar never tried it sorry, if i find something i will tell you, good luck guys.