1 year ago
#73079

XTOO
ESC/POS Printing Issue on android device (HiStone HK316) - Xamarin Forms
I am working on A xamarin forms app, where i need to implement bluetooth printing. I am successfully able to print on regular iOS and android devices. but on HiStone(hk316) its not printing as it should be
Below is the code i've used for Printing
using (var ms = new MemoryStream())
{
using (var bw = new BinaryWriter(ms))
{
bw.Write(e.Initialize());
bw.Write(e.PrintLine(" "));
bw.Write(e.CenterAlign());
bw.Write(e.SetStyles(PrintStyle.Bold));
bw.Write(e.PrintLine(GlobalVariables.Instance.Business.Business.BusinessDisplayName));
bw.Write(e.PrintLine(GlobalVariables.Instance.Business.Location.LocationName));
bw.Write(e.PrintLine(string.Format("{0}, {1}", GlobalVariables.Instance.Business.Location.Address, GlobalVariables.Instance.Business.Location.Zip)));
bw.Write(e.PrintLine("Phone: " + GlobalVariables.Instance.Business.Location.Phone.ToFormattedPhone()));
bw.Write(e.SetStyles(PrintStyle.None | PrintStyle.FontB));
bw.Write(e.PrintLine(string.Format("Payout#: {0}", cashDrawer.InvoiceNumber)));
bw.Write(e.SetStyles(PrintStyle.None | PrintStyle.FontB));
bw.Write(e.PrintLine(string.Format("Date: {0} Clerk: {1}", cashDrawer.Dated.ToString("MM/dd/yyyy"), GlobalVariables.Instance.User.DisplayName)));
bw.Write(e.PrintLine(string.Format("Station: {0} Time: {1}", GlobalVariables.Instance.Business.Register.RegisterName, cashDrawer.Dated.ToString("HH:mm:ss"))));
bw.Write(e.PrintLine(""));
bw.Write(e.LeftAlign());
bw.Write(e.SetStyles(PrintStyle.None | PrintStyle.FontB));
bw.Write(e.PrintLine(""));
bw.Write(e.PrintLine($"Sig:_______________________"));
bw.Write(e.PrintLine(""));
bw.Write(e.PrintLine(""));
bw.Write(e.PrintLine(string.Format("Amount (Cash): {0}", cashDrawer.Amount.ToString("C"))));
bw.Write(e.PrintLine(string.Format("Reason : {0}", cashDrawer.Reason)));
bw.Write(e.PrintLine(""));
bw.Write(e.PrintLine(""));
bw.Write(e.PrintLine(""));
bw.Write(e.PrintLine("Witness:____________________"));
bw.Write(e.PrintLine(""));
bw.Write(e.PrintLine(""));
bw.Write(AsciiControlChars.GroupSeparator);
bw.Write('V');
bw.Write((byte)66);
bw.Write((byte)3);
bw.Flush();
ms.Position = 0;
var sr = new StreamReader(ms);
var str = sr.ReadToEnd();
System.Diagnostics.Debug.WriteLine(str);
var bytesToPrint = System.Text.Encoding.ASCII.GetBytes(str).ToArray();
if (printerType == PrinterType.Bluetooth)
{
var res = await DependencyService.Get<IBlueToothService>().ConnectAndPrintAsync(bytesToPrint);
}
else if (printerType == PrinterType.Network)
{
DependencyService.Get<IPrintService>().PrintOverNetwork(bytesToPrint);
}
bw.Finish();
}
}
I have used Shiny plugin for bluetooth connection. Thanks
android
xamarin.forms
printing
bluetooth
escpos
0 Answers
Your Answer