private void GetPrinterStatus() { //CheckPrinter(); IConnection connection = null; try { connection = myPrinter.Connection; connection.Open(); if (!CheckPrinterLanguage(connection)) { resetPage(); return; } IZebraPrinter printer = ZebraPrinterFactory.Current.GetInstance(connection); IPrinterStatus status = printer.CurrentStatus; ShowStatus(status); } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Exception:" + e.Message); ShowErrorAlert(e.Message); } finally { if ((connection != null) && (connection.IsConnected)) { connection.Close(); } resetPage(); } }
private void StartGetTemplatesFromPrinter() { CheckPrinter(); IConnection connection = myPrinter.Connection; try { connection.MaxTimeoutForRead = 5000; connection.TimeToWaitForMoreData = 1000; connection.Open(); if (!CheckPrinterLanguage(connection)) { ResetPage(); return; } IZebraPrinter printer = ZebraPrinterFactory.Current.GetInstance(connection); string[] fileNames = printer.RetrieveFileNames(new string[] { "ZPL" }); AddFormatsToList(fileNames, Format.Location.printer); } catch (Exception e) { ShowErrorAlert(e.Message + " - On printer"); } finally { if ((connection != null) && (connection.IsConnected)) { connection.Close(); } ResetPage(); } }
//Connect and send to print private void PrintLineMode() { IConnection connection = null; try { connection = ChoosenPrinter.Connection; connection.Open(); IZebraPrinter printer = ZebraPrinterFactory.Current.GetInstance(connection); if ((!CheckPrinterLanguage(connection)) || (!PreCheckPrinterStatus(printer))) { return; } sendZplReceipt(connection); if (PostPrintCheckStatus(printer)) { // Debug.WriteLine("Printing process is done"); } } catch (System.Exception ex) { // Connection Exceptions and issues are caught here //Debug.WriteLine(ex.Message); } finally { connection.Open(); if ((connection != null) && (connection.IsConnected)) { connection.Close(); } } }
void PrinterListView_ItemClick(object sender, AdapterView.ItemClickEventArgs e) { try { var bluetoothPrinter = printerList[e.Position]; RemoveHandlers(); if (bluetoothPrinter is IZebraPrinter) { SetPrinter(bluetoothPrinter); fileUtility.SaveXMLSettings(bluetoothPrinter); zebraPrinter = (IZebraPrinter)fileUtility.LoadXMLSettings(); } } catch (Exception ex) { // call LogFile method and pass argument as Exception message, event name, control name, error line number, current form name fileUtility.LogFile(ex.Message, ex.ToString(), MethodBase.GetCurrentMethod().Name, ExceptionHelper.LineNumber(ex), Class.SimpleName); } var returnIntent = new Intent(); returnIntent.PutExtra("result", "found"); SetResult(Result.Ok, returnIntent); Finish(); }
private IFieldDescription[] GetFieldsFromPrinter() { IConnection connection = myPrinter.Connection; IFieldDescription[] fields = new IFieldDescription[0]; try { connection.Open(); CheckPrinterLanguage(connection); IZebraPrinter printer = ZebraPrinterFactory.Current.GetInstance(connection); byte[] rawformat = printer.RetrieveFormatFromPrinter(_format.Path); string formatstring = Encoding.UTF8.GetString(rawformat, 0, rawformat.Length); fields = printer.GetVariableFields(formatstring); } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Exception:" + e.Message); ShowErrorAlert("GetFieldsFromPrinter" + e.Message); } finally { if ((connection != null) && (connection.IsConnected)) { connection.Close(); } } return(fields); }
private void Print(object sender, EventArgs e) { IConnection connection = null; try { connection = ChoosenPrinter.Connection; connection.Open(); IZebraPrinter printer = ZebraPrinterFactory.Current.GetInstance(connection); if ((!CheckPrinterLanguage(connection)) || (!PreCheckPrinterStatus(printer))) { return; } sendZplReceipt(connection); } catch (System.Exception ex) { // Connection Exceptions and issues are caught here } finally { connection.Open(); if ((connection != null) && (connection.IsConnected)) { connection.Close(); } } }
void Handle_Clicked(object sender, System.EventArgs e) { IConnection connection = null; try { connection = App.myPrinter.Connection; connection.Open(); if (!CheckPrinterLanguage(connection)) { //ResetPage(); return; } IZebraPrinter printer = ZebraPrinterFactory.Current.GetInstance(connection); IPrinterStatus status = printer.CurrentStatus; ShowStatus(status); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Exception:" + ex.Message); ShowErrorAlert(ex.Message); } finally { if ((connection != null) && (connection.IsConnected)) { connection.Close(); } } }
public void PrintLineMode(SoldTicket ticketContent) { IConnection connection = null; try { connection = App.myPrinter.Connection; connection.Open(); IZebraPrinter printer = ZebraPrinterFactory.Current.GetInstance(connection); /* if ((!CheckPrinterLanguage(connection)) || (!PreCheckPrinterStatus(printer))) * { * ResetPage(); * return; * }*/ SendZplReceipt(connection, ticketContent); } catch (Exception ex) { // Connection Exceptions and issues are caught here } finally { if ((connection != null) && (connection.IsConnected)) { connection.Close(); } } }
private void PrintLineMode() { IConnection connection = null; try { connection = myPrinter.Connection; connection.Open(); IZebraPrinter printer = ZebraPrinterFactory.Current.GetInstance(connection); if ((!CheckPrinterLanguage(connection)) || (!PreCheckPrinterStatus(printer))) { ResetPage(); return; } SendZplReceipt(connection); if (PostPrintCheckStatus(printer)) { //ShowAlert("Receipt printed."); } } catch (Exception ex) { // Connection Exceptions and issues are caught here ShowErrorAlert(ex.Message); } finally { if ((connection != null) && (connection.IsConnected)) { connection.Close(); } ResetPage(); } }
private void PrintFormat() { CheckPrinter(); IConnection connection = myPrinter.Connection; try { connection.Open(); IZebraPrinter printer = ZebraPrinterFactory.Current.GetInstance(connection); if ((!CheckPrinterLanguage(connection)) || (!PreCheckPrinterStatus(printer))) { resetPage(); return; } Dictionary <int, string> vars = new Dictionary <int, string>(); foreach (View item in Children) { if (item is StackLayout) { foreach (View formItem in ((StackLayout)item).Children) { if (formItem is Entry) { vars.Add(Convert.ToInt32(formItem.ClassId), ((Entry)formItem).Text); } } } } // Send a format that is on the device to the printer if (_format.FileLocation == Format.Location.device) { printer.SendFileContents(_format.Path); } // Send the vairable fields printer.PrintStoredFormat(_format.PrinterPath, vars); PostPrintCheckStatus(printer); } catch (Exception e) { // Connection issues are thrown as Exceptions System.Diagnostics.Debug.WriteLine("Exception:" + e.Message); ShowErrorAlert(e.Message); } finally { if ((connection != null) && (connection.IsConnected)) { connection.Close(); } resetPage(); } }
private bool CheckPrinterStatus(IConnection connection) { IZebraPrinter printer = ZebraPrinterFactory.Current.GetInstance(PrinterLanguage.ZPL, connection); IPrinterStatus status = printer.CurrentStatus; if (!status.IsReadyToPrint) { Log.Information("Printer in Error: " + status); } return(true); }
private bool CheckPrinterStatus(IConnection conn) { IZebraPrinter printer = ZebraPrinterFactory.Current.GetInstance(PrinterLanguage.ZPL, conn); IPrinterStatus status = printer.CurrentStatus; if (!status.IsReadyToPrint) { Debug.WriteLine("Printer in Error: " + status.ToString()); } return(true); }
public bool PreCheckPrinterStatus(IZebraPrinter printer) { // Check the printer status IPrinterStatus status = printer.CurrentStatus; if (!status.IsReadyToPrint) { Application.Current.MainPage.DisplayAlert("Unable to print. Printer is " + status.Status, "test", "test"); return(false); } return(true); }
public ZebraPrn(string printer) { dbcon_ = DependencyService.Get <ISQLiteDb>().GetConnection(); _con = null; _prn = null; _riglist = null; _mod_len = 200 * 8; // Lunghezza Modulo inziale 20 cm _codcli = ""; _coddst = ""; _codocr = ""; _printer = printer; }
protected bool PreCheckPrinterStatus(IZebraPrinter printer) { // Check the printer status IPrinterStatus status = printer.CurrentStatus; if (!status.IsReadyToPrint) { ShowErrorAlert("Unable to print. Printer is " + status.Status); return(false); } return(true); }
void LoadXMLSettings() { zebraPrinter = (IZebraPrinter)fileUtility.LoadXMLSettings(); try { ((TextView)FindViewById <TextView>(GLNLabelPrint.Resource.Id.selectedPrinterTxt)).Text = zebraPrinter.FriendlyName; // ((Button)FindViewById<Button>(GLNLabelPrint.Resource.Id.PrintButton)).Enabled = true; } catch (Exception ex) { // call LogFile method and pass argument as Exception message, event name, control name, error line number, current form name fileUtility.LogFile(ex.Message, ex.ToString(), MethodBase.GetCurrentMethod().Name, ExceptionHelper.LineNumber(ex), Class.SimpleName); } }
private IFieldDescription[] GetFieldsFromDevice() { IConnection connection = myPrinter.Connection; IFieldDescription[] fields = null; try { IZebraPrinter printer = ZebraPrinterFactory.Current.GetInstance(PrinterLanguage.ZPL, connection); string formatstring = DependencyService.Get <IFileUtil>().ReadAllText(format.Path); fields = printer.GetVariableFields(formatstring); } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Exception:" + e.Message); ShowErrorAlert("GetFieldsFromDevice:" + e.Message); ResetPage(); } return(fields); }
protected bool PostPrintCheckStatus(IZebraPrinter printer) { // Check the status again to verify print happened successfully IPrinterStatus status = printer.CurrentStatus; // Wait while the printer is printing while ((status.NumberOfFormatsInReceiveBuffer > 0) && (status.IsReadyToPrint)) { status = printer.CurrentStatus; } // verify the print didn't have errors like running out of paper if (!status.IsReadyToPrint) { ShowErrorAlert("Error durring print. Printer is " + status.Status); return(false); } return(true); }
public void SendZplPalletAsync(string header, string ipAddr) { IConnection connection = null; try { if (!string.IsNullOrEmpty(ipAddr)) { connection = ConnectionBuilder.Current.Build("TCP:" + ipAddr + ":9100"); } else { myPrinter = ConstantManager.PrinterSetting; connection = myPrinter.Connection; } connection.Open(); IZebraPrinter printer = ZebraPrinterFactory.Current.GetInstance(connection); if ((!CheckPrinterLanguage(connection)) || (!PreCheckPrinterStatus(printer))) { return; } connection.Write(GetBytes(header)); } catch (Exception ex) { // Connection Exceptions and issues are caught here Device.BeginInvokeOnMainThread(async() => { await _dialogService.DisplayAlertAsync("Error", "Could not connect to printer", "Ok"); }); Crashes.TrackError(ex); } finally { if ((connection != null) && (connection.IsConnected)) { connection.Close(); } } }
void DiscoveryHandler_OnDiscoveryFinished(object sender) { IZebraPrinter[] printers = new IZebraPrinter[printerList.Count]; for (int i = 0; i < printerList.Count; i++) { printers[i] = printerList[i]; } try { printerListView.Adapter = new ListAlternateRowAdapter(Android.App.Application.Context, Android.Resource.Layout.SimpleListItem1, printers); } catch (Exception ex) { // call LogFile method and pass argument as Exception message, event name, control name, error line number, current form name fileUtility.LogFile(ex.Message, ex.ToString(), MethodBase.GetCurrentMethod().Name, ExceptionHelper.LineNumber(ex), Class.SimpleName); } RemoveHandlers(); }
//modified from https://github.com/Zebra/LinkOS-Xamarin-Samples/blob/ZSDK_DevDemos/ZSDK_DevDemos/Xamarin_LinkOS_Developer_Demo/Xamarin_LinkOS_Developer_Demo/FormatView.cs private IFieldDescription[] PrintFormatOnPrinter(string fileNameOnPrinter, string[] mydata) { IConnection connection = myPrinter.Connection; IFieldDescription[] fields = new IFieldDescription[0]; try { connection.Open(); CheckPrinterLanguage(connection); IZebraPrinter printer = ZebraPrinterFactory.Current.GetInstance(connection); byte[] rawformat = printer.RetrieveFormatFromPrinter(fileNameOnPrinter); string formatstring = Encoding.UTF8.GetString(rawformat, 0, rawformat.Length); fields = printer.GetVariableFields(formatstring); Dictionary <int, string> vars = new Dictionary <int, string>(); int i = 0; foreach (IFieldDescription field in fields) { vars.Add(field.FieldNumber, mydata[i]); i++; } printer.PrintStoredFormat(fileNameOnPrinter, vars); } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Exception:" + e.Message); ShowErrorAlert("GetFieldsFromPrinter" + e.Message); } finally { if ((connection != null) && (connection.IsConnected)) { connection.Close(); } } return(fields); }
void BtnPrint_Clicked(object sender, System.EventArgs e) { IConnection connection = null; try { if (ChoosenPrinter is null) { connection = ConnectionBuilder.Current.Build("BT:" + txtMacAddress.Text); } else { connection = ChoosenPrinter.Connection; } connection.Open(); IZebraPrinter printer = ZebraPrinterFactory.Current.GetInstance(connection); if ((!CheckPrinterLanguage(connection)) || (!PreCheckPrinterStatus(printer))) { return; } sendZplReceipt(connection); } catch (Exception ex) { // Connection Exceptions and issues are caught here Debug.WriteLine(ex.Message); } finally { connection.Open(); if ((connection != null) && (connection.IsConnected)) { connection.Close(); } } }
public async Task <bool> PrintTest() { bool result = false; try { _con = ConnectionBuilder.Current.Build(_printer); _con.Open(); _prn = ZebraPrinterFactory.Current.GetInstance(_con); // // Query fatta per rendere il metodo asincrono // var rec = await dbcon_.QueryAsync <int>("SELECT COUNT(*) FROM canali"); Initialize(); String tmpHeader = "^XA" + "^POI^PW800^MNN^LL325^LH0,0" + "\r\n" + "^FO0,50" + "\r\n" + "^A0,N,80,80" + "\r\n" + "^FB800,1,0,C,0^FDRSA Software^FS" + "\r\n" + "^FO0,170" + "\r\n" + "^A0,N,45,45" + "\r\n" + "^FB800,1,0,C,0^FDFacile Mobile Edition^FS" + "\r\n" + "^FO0,220" + "\r\n" + "^A0,N,30,30" + "\r\n" + "^FB800,1,0,C,0^FD{0}^FS" + "\r\n" + "^FO0,300" + "\r\n\n\n\n\n\n\n\n\n" + "^GB800,5,5,B,0^FS" + "^XZ"; DateTime date = DateTime.Now; string dateString = date.ToString("dd MMMM yyyy"); string header = string.Format(tmpHeader, dateString); var t = new UTF8Encoding().GetBytes(header); _con.Write(t); PostPrintCheckStatus(); // // Settiamo la lunghezza del modulo ad 1 cm // header = "^XA" + // Inizializziamo la stampa "^PW800" + // Settiamo la Larghezza "^MNN" + // Settiamo la stampa in continuos mode "^LH0,0" + // Settiamo la posizione Iniziale "^LL80" + // Settiamo la posizione Iniziale "^XZ"; t = new UTF8Encoding().GetBytes(header); _con.Write(t); PostPrintCheckStatus(); result = true; } catch (ZebraExceptions ex) { Debug.WriteLine(ex.Message); throw; } catch (Exception ex) { Debug.WriteLine(ex.Message); throw; } finally { _con.Open(); if ((_con != null) && (_con.IsConnected)) { _con.Close(); } _con = null; _prn = null; } return(result); }
public async Task <bool> PrintDoc(Fatture doc, bool stprice, short copie = 1) { var result = false; bool rewrite = false; try { _con = ConnectionBuilder.Current.Build(_printer); _con.Open(); _prn = ZebraPrinterFactory.Current.GetInstance(_con); // // Leggiamo le righe del documento // string sql = String.Format("SELECT * FROM fatrow2 WHERE rig_tipo = {0} AND rig_n_doc = {1}", doc.fat_tipo, doc.fat_n_doc); _riglist = await dbcon_.QueryAsync <FatRow>(sql); // // Controlliamo che tutte le righe siano dello stesso fornitore // int codfor = -1; if (doc.fat_tipo == (int)DocTipo.TIPO_DDT) { foreach (var rig in _riglist) { if (!string.IsNullOrWhiteSpace(rig.rig_art)) { sql = String.Format("SELECT * FROM artanag WHERE ana_codice = {0} LIMIT 1", rig.rig_art.Trim().SqlQuote(false)); var ana = await dbcon_.QueryAsync <Artanag>(sql); if (ana.Count > 0) { if (codfor == -1) { codfor = ana[0].ana_for_abituale; } if (codfor != ana[0].ana_for_abituale) { codfor = -1; break; } } } } if (codfor == -1) { codfor = 0; } _codcli = "C.F. "; _coddst = "C.C. "; sql = String.Format("SELECT * FROM agganci1 WHERE agg_forn = {0} AND agg_cli = {1} AND agg_dst = {2} LIMIT 1", codfor, doc.fat_inte, 0); var agg = await dbcon_.QueryAsync <Agganci>(sql); if (agg.Count > 0) { _codcli = _codcli + agg[0].agg_codice; _coddst = _coddst + agg[0].agg_codice; } sql = String.Format("SELECT * FROM agganci1 WHERE agg_forn = {0} AND agg_cli = {1} AND agg_dst = {2} LIMIT 1", codfor, doc.fat_inte, doc.fat_dest); agg = await dbcon_.QueryAsync <Agganci>(sql); if (agg.Count > 0) { _coddst = "C.C. " + agg[0].agg_codice; } _codcli = _codcli.Trim(); _coddst = _coddst.Trim(); if (_codcli == "C.F.") { _codcli = ""; } if (_coddst == "C.C.") { _coddst = ""; } _codocr = ""; if (doc.fat_tipo_ven == (int)DocTipoVen.VEN_TRASFERT && codfor != 0) { sql = String.Format("SELECT * FROM fornito1 WHERE for_codice = {0} LIMIT 1", codfor); var forList = await dbcon_.QueryAsync <Fornitori>(sql); if (forList.Count > 0 && forList[0].for_nota != 0) { sql = String.Format("SELECT * FROM descriz1 WHERE des_codice = {0} LIMIT 1", forList[0].for_nota); var desList = await dbcon_.QueryAsync <Descrizioni>(sql); if (desList.Count > 0) { desList[0].des_newdes = desList[0].des_newdes.Trim(); doc.fat_n_from = forList[0].for_codice; if (desList[0].des_newdes.Length < 130) { doc.fat_annotaz = desList[0].des_newdes; } else { doc.fat_annotaz = desList[0].des_newdes.Substring(0, 129); if (desList[0].des_newdes.Length > 130) { doc.fat_desc_varie_0 = desList[0].des_newdes.Substring(130, desList[0].des_newdes.Length >= 260 ? 259 : desList[0].des_newdes.Length - 1); } if (desList[0].des_newdes.Length > 260) { doc.fat_desc_varie_1 = desList[0].des_newdes.Substring(260, desList[0].des_newdes.Length >= 390 ? 389 : desList[0].des_newdes.Length - 1); } if (desList[0].des_newdes.Length > 390) { doc.fat_desc_varie_2 = desList[0].des_newdes.Substring(390, desList[0].des_newdes.Length - 1); } } doc.fat_annotaz = doc.fat_annotaz.Trim(); doc.fat_desc_varie_0 = doc.fat_desc_varie_0.Trim(); doc.fat_desc_varie_1 = doc.fat_desc_varie_1.Trim(); doc.fat_desc_varie_2 = doc.fat_desc_varie_2.Trim(); rewrite = true; } } if (codfor == 1L) // NESTLE { int ocr = 0; _codocr = string.Format("<{0}{1}{2:00}", RsaUtils.GetShowedNumDoc(doc.fat_n_doc), doc.fat_registro, 1); for (int y = 1; y < _codocr.Length; y++) { ocr += _codocr[y] * y; } ocr = ocr % 93; _codocr = _codocr + $"{ocr:00}>"; } } } if (rewrite) { await dbcon_.UpdateAsync(doc); } Initialize(); _mod_len = CalcLength(stprice) > _mod_len?CalcLength(stprice) : _mod_len; for (short idx = 0; idx < copie; idx++) { int row = 0; PrePrintCheckStatus(); row = await PrintDocHeaderAsync(doc, row, stprice); row = await PrintDocBodyAsync(doc, row, stprice); row = await PrintDocFooterAsync(doc, row, stprice); } result = true; } catch (ZebraExceptions ex) { Debug.WriteLine(ex.Message); throw; } catch (Exception ex) { Debug.WriteLine(ex.Message); throw; } finally { _con.Open(); if ((_con != null) && (_con.IsConnected)) { _con.Close(); } _con = null; _prn = null; } return(result); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(GLNLabelPrint.Resource.Layout.Main); // Get our button from the layout resource, // and attach an event to it var printButton = FindViewById <Button>(GLNLabelPrint.Resource.Id.PrintButton); printButton.Click += PrintButton_Click; // disable print button until we have a printer connected and something selected to print printButton.Enabled = false; var selectedPrinter = (TextView)FindViewById <TextView>(GLNLabelPrint.Resource.Id.selectedPrinterTxt); selectedPrinter.Text = ""; locationsView = ((ListView)FindViewById <ListView>(GLNLabelPrint.Resource.Id.locationsView)); locationList = new System.Collections.ObjectModel.ObservableCollection <IGLNLocation>(); locationsView.Adapter = new CheckListCustomArrayAdapter(Android.App.Application.Context, Android.Resource.Layout.SimpleListItemChecked, locationList); locationsView.ItemClick += LocationsView_ItemClick; locationsView.ItemSelected += LocationsView_ItemSelected; // set up file utility for saving/loading settings fileUtility = new FileUtilImplementation(); zebraPrinter = (IZebraPrinter)fileUtility.LoadXMLSettings(); try { ((TextView)FindViewById <TextView>(GLNLabelPrint.Resource.Id.selectedPrinterTxt)).Text = zebraPrinter.FriendlyName; printButton.Enabled = true; } catch (Exception ex) { ((TextView)FindViewById <TextView>(GLNLabelPrint.Resource.Id.selectedPrinterTxt)).SetText(GLNLabelPrint.Resource.String.NoPrinter); // call LogFile method and pass argument as Exception message, event name, control name, error line number, current form name fileUtility.LogFile(ex.Message, ex.ToString(), MethodBase.GetCurrentMethod().Name, ExceptionHelper.LineNumber(ex), Class.SimpleName); } // #if DEBUG // #else if (!AntiPiracyCheck()) { var dialogBuilder = new AlertDialog.Builder(this); dialogBuilder.SetTitle("Error"); dialogBuilder.SetMessage("This software is not permitted for use on this device.\n\rPlease contact your IT department."); dialogBuilder.SetIcon(Android.Resource.Drawable.IcDialogAlert); dialogBuilder.SetPositiveButton(Android.Resource.String.Ok, delegate { Finish(); }); dialogBuilder.Show(); } else { // load list of locations files var findFilesPage = new Android.Content.Intent(this, typeof(FindFilesActivity)); StartActivityForResult(findFilesPage, (int)ActivityCode.LoadLocations); } // #endif // var findFilesPage = new Android.Content.Intent(this, typeof(FindFilesActivity)); // StartActivityForResult(findFilesPage, (int)ActivityCode.LoadLocations); }
void SetPrinter(IZebraPrinter bluetoothPrinter) => zebraPrinter = bluetoothPrinter;