/// <summary> /// /// Issue an IBidi StartJob with xml markup to start an IBidi print job. /// /// We do this to have the printer check for supplies, or, just to obtain the /// printerJobID for job completion polling later. /// /// If the printer is out of supplies, throw an exception. /// /// </summary> public static int StartJob( BidiSplWrap bidiSpl, bool checkSupplies, string hopperID) { const int pollSleepMilliseconds = 2000; int printerJobID = 0; do { string printerOptionsXML = bidiSpl.GetPrinterData(strings.PRINTER_OPTIONS2); PrinterOptionsValues printerOptionsValues = Util.ParsePrinterOptionsXML(printerOptionsXML); int checkPrintRibbon = (printerOptionsValues._printHead == "Installed") ? 1 : 0; int checkEmbossSupplies = printerOptionsValues._moduleEmbosser == "None" ? 0 : 1; string startJobXml = string.Format( strings.STARTJOB_XML, hopperID, checkPrintRibbon, checkEmbossSupplies); string printerStatusXML = bidiSpl.SetPrinterData(strings.STARTJOB, startJobXml); PrinterStatusValues printerStatusValues = Util.ParsePrinterStatusXML(printerStatusXML); if (506 == printerStatusValues._errorCode) { // Printer cannot accept another job as it is busy. Try again. Console.WriteLine("StartJob(): {0} Trying again.", printerStatusValues._errorString); // let the current card process in the printer: Thread.Sleep(pollSleepMilliseconds); } else if (0 != printerStatusValues._errorCode) { var message = string.Format("StartJob(): {0} {1}", printerStatusValues._errorCode, printerStatusValues._errorString); throw new BidiException(message, printerStatusValues._printerJobID, printerStatusValues._errorCode); } else { Console.WriteLine("Printer job ID: {0} started.", printerStatusValues._printerJobID); printerJobID = printerStatusValues._printerJobID; } } while (0 == printerJobID); return(printerJobID); }
/// <summary> /// ParsePrinterOptionsXML() /// /// we have PrinterOptions2 xml from the printer. Parse the xml and populate /// a new PrinterOptionsValues instance with the data items. /// /// <?xml version="1.0"?> /// <!--Printer options2 xml file.--> /// <PrinterInfo2> /// <ColorPrintResolution>300x300 | 300x600</ColorPrintResolution> /// <ConnectionPortType>Network</ConnectionPortType> /// <ConnectionProtocol>Version2Secure</ConnectionProtocol> /// <EmbosserVersion>E1.1.25-0</EmbosserVersion> /// <LockState>Locked</LockState> /// <ModuleEmbosser>Installed</ModuleEmbosser> /// <MonochromePrintResolution>300x300 | 300x600 | 300x1200</MonochromePrintResolution> /// <OptionDuplex>Auto</OptionDuplex> /// <OptionInputhopper>MultiHopper6</OptionInputhopper> /// <OptionLocks>Installed</OptionLocks> /// <OptionMagstripe>ISO</OptionMagstripe> /// <OptionSmartcard>Single wire</OptionSmartcard> /// <PrinterAddress>172.16.2.211</PrinterAddress> /// <PrinterMessageNumber>0</PrinterMessageNumber> /// <PrinterModel>CD870</PrinterModel> /// <PrinterSerialNumber>E00105</PrinterSerialNumber> /// <PrinterStatus>Ready</PrinterStatus> /// <PrinterVersion>D3.12.4-0</PrinterVersion> /// <PrintHead>Installed</PrintHead> /// <TopcoatPrintResolution>300x300</TopcoatPrintResolution> /// <Laminator>L1,L2</Laminator> /// <LaminatorImpresser>None</LaminatorImpresser> /// <LaminatorScanner>None</LaminatorScanner> /// </PrinterInfo2> /// /// </summary> /// <param name="printerOptionsXML"></param> /// <returns>a populated PrinterOptionsValues struct</returns> public static PrinterOptionsValues ParsePrinterOptionsXML(string printerOptionsXML) { XmlDocument doc = new XmlDocument(); doc.LoadXml(printerOptionsXML); PrinterOptionsValues printerOptionsValues = new PrinterOptionsValues(); printerOptionsValues._colorPrintResolution = StringFromXml(doc, "PrinterInfo2/ColorPrintResolution"); printerOptionsValues._connectionPortType = StringFromXml(doc, "PrinterInfo2/ConnectionPortType"); printerOptionsValues._connectionProtocol = StringFromXml(doc, "PrinterInfo2/ConnectionProtocol"); printerOptionsValues._embosserVersion = StringFromXml(doc, "PrinterInfo2/EmbosserVersion"); printerOptionsValues._lockState = StringFromXml(doc, "PrinterInfo2/LockState"); printerOptionsValues._moduleEmbosser = StringFromXml(doc, "PrinterInfo2/ModuleEmbosser"); printerOptionsValues._monochromePrintResolution = StringFromXml(doc, "PrinterInfo2/MonochromePrintResolution"); printerOptionsValues._optionDuplex = StringFromXml(doc, "PrinterInfo2/OptionDuplex"); printerOptionsValues._optionInputhopper = StringFromXml(doc, "PrinterInfo2/OptionInputhopper"); printerOptionsValues._optionLocks = StringFromXml(doc, "PrinterInfo2/OptionLocks"); printerOptionsValues._optionMagstripe = StringFromXml(doc, "PrinterInfo2/OptionMagstripe"); printerOptionsValues._optionSmartcard = StringFromXml(doc, "PrinterInfo2/OptionSmartcard"); printerOptionsValues._printerAddress = StringFromXml(doc, "PrinterInfo2/PrinterAddress"); printerOptionsValues._printerMessageNumber = IntFromXml(doc, "PrinterInfo2/PrinterMessageNumber"); printerOptionsValues._printerModel = StringFromXml(doc, "PrinterInfo2/PrinterModel"); printerOptionsValues._printerSerialNumber = StringFromXml(doc, "PrinterInfo2/PrinterSerialNumber"); printerOptionsValues._printerStatus = StringFromXml(doc, "PrinterInfo2/PrinterStatus"); printerOptionsValues._printerVersion = StringFromXml(doc, "PrinterInfo2/PrinterVersion"); printerOptionsValues._printHead = StringFromXml(doc, "PrinterInfo2/PrintHead"); printerOptionsValues._topcoatPrintResolution = StringFromXml(doc, "PrinterInfo2/TopcoatPrintResolution"); printerOptionsValues._laminatorFirmwareVersion = StringFromXml(doc, "PrinterInfo2/LaminatorFirmwareVersion"); printerOptionsValues._laminator = StringFromXml(doc, "PrinterInfo2/Laminator"); printerOptionsValues._laminatorImpresser = StringFromXml(doc, "PrinterInfo2/LaminatorImpresser"); printerOptionsValues._laminatorScanner = StringFromXml(doc, "PrinterInfo2/LaminatorScanner"); return(printerOptionsValues); }