private void getStatus() { string[] args = new string[] { "-n", datacard.getName() }; CommandLineOptions commandLineOptions = new CommandLineOptions(); CommandLine.Utility.Arguments arguments = new CommandLine.Utility.Arguments(args); if (string.IsNullOrEmpty(arguments["n"])) { Console.WriteLine("Some information"); } bool boolVal = false; if (Boolean.TryParse(arguments["n"], out boolVal)) { Console.WriteLine("Some information"); } commandLineOptions.printerName = arguments["n"]; if (!string.IsNullOrEmpty(arguments["j"])) { commandLineOptions.jobStatus = true; } BidiSplWrap bidiSpl = null; try { bidiSpl = new BidiSplWrap(); bidiSpl.BindDevice(commandLineOptions.printerName); string driverVersionXml = bidiSpl.GetPrinterData(strings.SDK_VERSION); //Console.WriteLine(Environment.NewLine + "driver version: " + Util.ParseDriverVersionXML(driverVersionXml) + Environment.NewLine); string printerOptionsXML = bidiSpl.GetPrinterData(strings.PRINTER_OPTIONS2); PrinterOptionsValues printerOptionsValues = Util.ParsePrinterOptionsXML(printerOptionsXML); DisplayPrinterOptionsValues(printerOptionsValues); string printerCardCountXML = bidiSpl.GetPrinterData(strings.COUNTER_STATUS2); PrinterCounterStatus printerCounterStatusValues = Util.ParsePrinterCounterStatusXML(printerCardCountXML); DisplayPrinterCounterValues(printerCounterStatusValues); string suppliesXML = bidiSpl.GetPrinterData(strings.SUPPLIES_STATUS3); SuppliesValues suppliesValues = Util.ParseSuppliesXML(suppliesXML); DisplaySuppliesValues(suppliesValues); //string printerStatusXML = bidiSpl.GetPrinterData(strings.PRINTER_MESSAGES); //PrinterStatusValues printerStatusValues = Util.ParsePrinterStatusXML(printerStatusXML); //DisplayPrinterStatusValues(printerStatusValues); } catch (Exception e) { Console.WriteLine(e.Message); } finally { bidiSpl.UnbindDevice(); } }
private void GetPrinterProperties(String printerName) { BidiSplWrap bidiSpl = null; int printerJobID = 0; try { bidiSpl = new BidiSplWrap(); String BindResponse = bidiSpl.BindDevice(printerName); textBox4.Text += Environment.NewLine + BindResponse; string driverVersionXml = bidiSpl.GetPrinterData(strings.SDK_VERSION); textBox4.Text += Environment.NewLine + "driver version: " + Util.ParseDriverVersionXML(driverVersionXml) + Environment.NewLine; string printerOptionsXML = bidiSpl.GetPrinterData(strings.PRINTER_OPTIONS2); PrinterOptionsValues printerOptionsValues = Util.ParsePrinterOptionsXML(printerOptionsXML); if ("Ready" != printerOptionsValues._printerStatus && "Busy" != printerOptionsValues._printerStatus) { throw new Exception(printerName + " is not ready. status: " + printerOptionsValues._printerStatus); } else { string printerOptionsXMLSupply = bidiSpl.GetPrinterData(strings.SUPPLIES_STATUS3); SuppliesValues printerOptionsSupplyValues = Util.ParseSuppliesXML(printerOptionsXMLSupply); textBox4.Text += Environment.NewLine + "Printer Status: " + printerOptionsValues._printerStatus; textBox4.Text += Environment.NewLine + "Ribbon Type: " + printerOptionsSupplyValues._printRibbonType; textBox4.Text += Environment.NewLine + "Ribbon Serial Number: " + printerOptionsSupplyValues._printRibbonSerialNumber; textBox4.Text += Environment.NewLine + "Ribbon Level: " + printerOptionsSupplyValues._ribbonRemaining + "%"; } } catch (BidiException e) { textBox4.Text += Environment.NewLine + e.Message; Util.CancelJob(bidiSpl, e.PrinterJobID, e.ErrorCode); } catch (Exception e) { textBox4.Text += Environment.NewLine + e.Message; if (0 != printerJobID) { Util.CancelJob(bidiSpl, printerJobID, 0); } } finally { bidiSpl.UnbindDevice(); } }
private void button1_Click(object sender, EventArgs e) { String printerName = comboBox1.Text; GetPrinterProperties(printerName); ///printing is activated here BidiSplWrap bidiSpl = null; int printerJobID = 0; try { bidiSpl = new BidiSplWrap(); String BindResponse = bidiSpl.BindDevice(printerName); textBox2.Text += Environment.NewLine + BindResponse; string driverVersionXml = bidiSpl.GetPrinterData(strings.SDK_VERSION); textBox2.Text += Environment.NewLine + "driver version: " + Util.ParseDriverVersionXML(driverVersionXml) + Environment.NewLine; string printerOptionsXML = bidiSpl.GetPrinterData(strings.PRINTER_OPTIONS2); PrinterOptionsValues printerOptionsValues = Util.ParsePrinterOptionsXML(printerOptionsXML); if ("Ready" != printerOptionsValues._printerStatus && "Busy" != printerOptionsValues._printerStatus) { throw new Exception(printerName + " is not ready. status: " + printerOptionsValues._printerStatus); } else { string hopperID = string.Empty; printerJobID = Util.StartJob( bidiSpl, false, hopperID); Application.DoEvents(); Util.PrintTextAndGraphics(bidiSpl, printerName, textBox1.Text); Application.DoEvents(); if (0 != printerJobID) { // wait for the print spooling to finish and then issue an EndJob(): Util.WaitForWindowsJobID(bidiSpl, printerName); bidiSpl.SetPrinterData(strings.ENDJOB); } Application.DoEvents(); Util.PollForJobCompletion(bidiSpl, printerJobID); } } catch (BidiException ee) { textBox2.Text += Environment.NewLine + ee.Message; Util.CancelJob(bidiSpl, ee.PrinterJobID, ee.ErrorCode); } catch (Exception ee) { textBox2.Text += Environment.NewLine + ee.Message; if (0 != printerJobID) { Util.CancelJob(bidiSpl, printerJobID, 0); } } finally { bidiSpl.UnbindDevice(); } }