/************************************************************************************************** * Function Name: CloseConnectionToPrinter * * Purpose: Releases a handle to the printer driver for the selected printer. * * Parameters: None * * Returns: True = Handle released * False = Failed to release a handle to the printer driver * * History: * Date Who Comment * 12/9/2010 ACT Function creation. ***************************************************************************************************/ private bool CloseConnectionToPrinter() { try { string errMsg = string.Empty; _thePrinterSDK.Close(out errMsg); if (errMsg == string.Empty) { return(true); } else { MessageBox.Show("Unable to close device [" + cboPrn.Text + "]. " + errMsg); } } catch (Exception ex) { MessageBox.Show("CloseConnectionToPrinter threw exception: " + ex.Message); } return(false); }
// CONTACT Sample Code ---------------------------------------------------------------------------------- public void ContactEncode(string drvName, string _contactReader, int eject, out string msg) { ZBRPrinter printer = null; int errValue = 0; msg = ""; try { printer = new ZBRPrinter(); // Opens a connection to a printer driver if (!printer.Open(drvName, out msg)) { msg = "CONTACT Open Error: " + ZBRUtil.TranslateErrorCode(errValue) + "\n" + "Error Code : " + errValue.ToString(); return; } // Moves the card into position for encoding if (printer.MoveCardToSmartCardEncoder(CONTACT, out errValue) == 0) { msg = "CONTACT StartCard Error:" + ZBRUtil.TranslateErrorCode(errValue) + "\n" + "Error Code : " + errValue.ToString(); return; } byte[] key = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; //perform the smart card encoding: ContactSupport contact = new ContactSupport(); string cardType = "PVC,SLE4428"; contact.ContactTest(ref cardType, _contactReader, key, true, out msg); if (msg.Length > 0) { return; } if (printer.MoveSmartCardToPrintReadyPosition(CONTACT, out errValue) == 0) { msg = "CONTACT Prnt Card Error: " + errValue.ToString(); return; } if (printer.EjectCard(out errValue) == 0) { msg = "CONTACT Eject Card Error: " + errValue.ToString(); return; } } catch (Exception ex) { msg += ex.Message; System.Windows.Forms.MessageBox.Show(ex.ToString(), "CONTACTCode threw exception"); } finally { if (printer != null) { printer.EjectCard(out errValue); if (msg.Length == 0) { printer.Close(out msg); } else { string tempmsg = ""; printer.Close(out tempmsg); } printer = null; } } }