private void PerformMagneticPrintTest(ref ZXPSampleCode zxp, string test) { try { switch (test) { case "Print With Magnetic Encoding": zxp.PrintWithMag(); break; case "Write Mag Data": zxp.MagneticDataOnly(); break; case "Read Mag Data": zxp.Tracks = DataSourceEnum.Track1Data | DataSourceEnum.Track2Data | DataSourceEnum.Track3Data; // Reads and displays all 3 magnetic tracks if (zxp.MagRead()) { MessageBox.Show("Track 1 = " + zxp.Track1Data + "\r\n" + "Track 2 = " + zxp.Track2Data + "\r\n" + "Track 3 = " + zxp.Track3Data); } break; } } catch (Exception ex) { MessageBox.Show("PerformMagneticPrintTest threw exception: " + ex.Message); } }
private void btnLocatePrinters_Click(object sender, EventArgs e) { ZXPSampleCode z = null; try { Cursor = Cursors.WaitCursor; lbStatus.Visible = true; lbJobStatus.Text = "Searching for printers"; lbSamples.Items.Clear(); Refresh(); Application.DoEvents(); // Get a list of ZXP devices if (cboPrnInit(rbUSB.Checked)) { // Loads list box with samples for (int i = 0; i < _lbSamples.Length; i++) { this.lbSamples.Items.Add(_lbSamples[i]); } this.lbSamples.Text = _lbSamples[0]; // Displays versions z = new ZXPSampleCode(this.cboPrn.Text); this.lblVersions.Text = z.GetVersions(); if (!z.IsZXP7) { // Loads card types based on type of sample type _cardTypeList = new ArrayList(); CardTypesInit(ref z, this.cboPrn.Text); cboCardTypeInit(SAMPLE_TYPE.PRINTING); } else { cboCardType.Enabled = false; } } else //do not close the program { string temp = rbUSB.Checked ? " USB" : " Ethernet"; MessageBox.Show("Could not locate a ZXP Printer via " + temp, "Warning"); } } catch (Exception ex) { MessageBox.Show("btnLocatePrinters_Click exception: " + ex.Message); } finally { z = null; lbStatus.Visible = false; Cursor = Cursors.Default; } }
// Initializes the printer selection combo box // based on printer discovery from GetDeviceList // -------------------------------------------------------------------------------------------------- private bool cboPrnInit(bool usb) { Cursor.Current = Cursors.WaitCursor; this.cboPrn.Text = string.Empty; this.cboPrn.Items.Clear(); this.cboPrn.Refresh(); ZXPSampleCode z = null; bool bRet = true; try { if (!string.IsNullOrEmpty(cboPrn.Text)) { return(true); } else //search for printers { z = new ZXPSampleCode(); //---------------------------------------------------------------------------------------------------- //note: pass true for searching for usb-connected printers, false to search for ethernet printers //for ethernert printers, only those printers on the same subnet as the sample application will be //located //---------------------------------------------------------------------------------------------------- z.GetDeviceList(usb); if (z.DeviceList != null) { Array array = (Array)z.DeviceList; for (int i = 0; i < array.GetLength(0); i++) { this.cboPrn.Items.Add((string)array.GetValue(i)); } this.cboPrn.Text = (string)array.GetValue(0); } else { bRet = false; } } } catch { bRet = false; } finally { z = null; Cursor.Current = Cursors.Default; } return(bRet); }
private void DisconnectFromPrinter(ref ZXPSampleCode z, ref Job job) { try { z.Disconnect(ref job); } catch (Exception ex) { MessageBox.Show("DisconnectFromPrinter threw exception: " + ex.Message); } }
private void frmMain_Shown(object sender, EventArgs e) { ZXPSampleCode z = null; try { // Get a list of USB ZXP devices if (cboPrnInit(true)) { // Loads list box with samples for (int i = 0; i < _lbSamples.Length; i++) { this.lbSamples.Items.Add(_lbSamples[i]); } this.lbSamples.Text = _lbSamples[0]; // Displays versions z = new ZXPSampleCode(this.cboPrn.Text); this.lblVersions.Text = z.GetVersions(); if (!z.IsZXP7) { // Loads card types based on type of sample type _cardTypeList = new ArrayList(); CardTypesInit(ref z, this.cboPrn.Text); cboCardTypeInit(SAMPLE_TYPE.PRINTING); } else { cboCardType.Enabled = false; } Text = "ZXP Sample Code " + ProductVersion; } else //do not close the program { MessageBox.Show("Could not locate a ZXP Printer on USB ports", "Warning"); } } catch (Exception ex) { MessageBox.Show("frmMain_Load threw exception: " + ex.Message); } finally { z = null; } }
private void PerformMultiPrintTest(ref ZXPSampleCode zxp, string printer) { try { using (frmMultiPrint f = new frmMultiPrint(printer)) { f.ShowDialog(); } } catch (Exception ex) { MessageBox.Show("PerformMultiPrintTest threw exception: " + ex.Message); } }
private void PerformPrintTest(ref ZXPSampleCode zxp, string test, string cardType) { try { lbJobStatus.Visible = true; lbJobStatus.Text = "Waiting for " + test + " to complete"; Refresh(); Application.DoEvents(); switch (test) { case "Print 1": zxp.Print_1(cardType); break; case "Print 2": zxp.Print_2(cardType); break; case "Print 3": zxp.Print_3(cardType); break; case "Print 4": zxp.Print_4(cardType); break; case "Print 5": zxp.Print_5(cardType); break; case "Print 6": zxp.Print_6(cardType); break; } } catch (Exception ex) { MessageBox.Show("PerformPrintTest exception: " + ex.Message); } finally { lbJobStatus.Text = "Job Result = " + zxp.Msg; } }
private void SetDestinations(ref ZXPSampleCode zxp, string source, string destination) { try { // Sets the card source location switch (source) { case "ATM Slot": zxp.Feeder = FeederSourceEnum.ATMSlot; break; case "Internal": zxp.Feeder = FeederSourceEnum.Internal; break; default: zxp.Feeder = FeederSourceEnum.CardFeeder; break; } // Sets the card destination location switch (destination) { case "Feeder": zxp.Destination = DestinationTypeEnum.Feeder; break; case "Hold": zxp.Destination = DestinationTypeEnum.Hold; break; case "Reject Bin": zxp.Destination = DestinationTypeEnum.Reject; break; default: zxp.Destination = DestinationTypeEnum.Eject; break; } } catch (Exception ex) { MessageBox.Show("SetDestinations threw exception: " + ex.Message); } }
private void PerformSmartCardTest(ref ZXPSampleCode zxp, string test) { try { switch (test) { case "Print With Contactless Smart Card": zxp.ContactlessSmartCardAndPrint(); break; case "Smart Card Process": zxp.SmartCard(); break; } } catch (Exception ex) { MessageBox.Show("PerformSmartCardTest threw exception: " + ex.Message); } }
// Builds the _cardTypes ArrayList // from the selected printer // -------------------------------------------------------------------------------------------------- private int CardTypesInit(ref ZXPSampleCode z, string deviceName) { Job job = null; try { _cardTypeList.Clear(); job = new Job(); if (!ConnectToPrinter(ref z, ref job, deviceName)) { return(0); } z.GetCardTypeList(ref job); if (z.CardTypeList != null) { Array array = (Array)z.CardTypeList; for (int i = 0; i < array.GetLength(0); i++) { _cardTypeList.Add((string)array.GetValue(i)); } } else { MessageBox.Show("No ZMotif devices found"); this.Refresh(); } } catch (Exception e) { MessageBox.Show("cboCardTypeInit Exception: " + e.Message); } finally { DisconnectFromPrinter(ref z, ref job); job = null; } return(_cardTypeList.Count); }
private bool ConnectToPrinter(ref ZXPSampleCode z, ref Job job, string deviceName) { try { if (!z.Connect(ref job)) { Cursor.Current = Cursors.Default; MessageBox.Show("Unable to open device [" + deviceName + "]"); DisconnectFromPrinter(ref z, ref job); } else { return(true); } } catch (Exception ex) { MessageBox.Show("ConnectToPrinter threw exception: " + ex.Message); } return(false); }
private void PerformPositionCardTest(ref ZXPSampleCode zxp, string test) { try { switch (test) { case "Position Card": zxp.PositionCard(); break; case "Eject Card": zxp.EjectCard(); break; case "Reject Card": zxp.RejectCard(); break; } } catch (Exception ex) { MessageBox.Show("PerformPositionCardTest threw exception: " + ex.Message); } }
// Starts a sample routine // -------------------------------------------------------------------------------------------------- private void btnRun_Click(object sender, EventArgs e) { ZXPSampleCode zxp = null; try { zxp = new ZXPSampleCode(this.cboPrn.Text); btnRun.Enabled = false; SetDestinations(ref zxp, this.cboSrc.Text, this.cboDest.Text); // Sets the card type //zxp.CardType = this.cboCardType.Text; lbStatus.Text = "Active Job: " + lbSamples.Text; lbStatus.Visible = true; Refresh(); Application.DoEvents(); // Runs the specified sample code if (lbSamples.Text.Contains("Smart Card")) { if (IsValidIP(ConnectionType)) { MessageBox.Show("Smartcard Encoding over Ethernet not supported by this application", "Warning"); } else { PerformSmartCardTest(ref zxp, lbSamples.Text); } } else if (lbSamples.Text.Contains("Card")) { PerformPositionCardTest(ref zxp, lbSamples.Text); } else if (lbSamples.Text.Contains("Multi")) { PerformMultiPrintTest(ref zxp, cboPrn.Text); } else if (lbSamples.Text.Contains("Mag")) { PerformMagneticPrintTest(ref zxp, lbSamples.Text); } else if (lbSamples.Text.Contains("Print")) { PerformPrintTest(ref zxp, lbSamples.Text, cboCardType.Text); } } catch (Exception ex) { MessageBox.Show("btnRun_Click threw exception: " + ex.Message); } finally { zxp = null; btnRun.Enabled = true; lbStatus.Visible = false; Refresh(); Application.DoEvents(); } }
private void btnConnectToPrinter_Click(object sender, EventArgs e) { ZXPSampleCode z = null; Job job = null; try { Cursor = Cursors.WaitCursor; lbStatus.Visible = true; lbStatus.Text = "Connecting to printer"; lbSamples.Items.Clear(); Refresh(); Application.DoEvents(); job = new Job(); z = new ZXPSampleCode(this.cboPrn.Text); if (z.Connect(ref job)) { // Loads list box with samples for (int i = 0; i < _lbSamples.Length; i++) { this.lbSamples.Items.Add(_lbSamples[i]); } this.lbSamples.Text = _lbSamples[0]; // Displays versions this.lblVersions.Text = z.GetVersions(); if (!z.IsZXP7) { // Loads card types based on type of sample type _cardTypeList = new ArrayList(); CardTypesInit(ref z, this.cboPrn.Text); cboCardTypeInit(SAMPLE_TYPE.PRINTING); } else { cboCardType.Enabled = false; } Text = "ZXP Sample Code " + ProductVersion; } else { MessageBox.Show("Could not open connection to printer " + cboPrn.Text, "Warning"); } } catch (Exception ex) { MessageBox.Show("btnConnectToPrinter_Click exception: " + ex.Message); } finally { if (z != null) { z.Disconnect(ref job); } z = null; lbStatus.Visible = false; Cursor = Cursors.Default; } }
// Starts the printing process // -------------------------------------------------------------------------------------------------- private void btnRun_Click(object sender, EventArgs e) { Job job = null; ZXPSampleCode z = null; int actionID = 0; short alarm = 0; string msg = string.Empty; string status = string.Empty; // Ensures that count is a number if (!IsInteger(this.tbCount.Text)) { MessageBox.Show("Count is not an integer value"); this.tbCount.Focus(); return; } try { job = new Job(); z = new ZXPSampleCode(_deviceName); // Opens a connection with a ZXP printer z.Connect(ref job); _isZXP7 = z.IsZXP7; // Sets the card source and destination job.JobControl.FeederSource = FeederSourceEnum.CardFeeder; job.JobControl.Destination = DestinationTypeEnum.Eject; int count = Convert.ToInt16(this.tbCount.Text); this.tbResults.AppendText(DisplayTime() + ": Start\r\n"); if (!BuildBitmaps()) { MessageBox.Show("Unable to build bitmaps"); this.Close(); } // Prints (count) number of cards for (int cardCount = 1; cardCount <= count;) { // Checks to see if the printer is in alarm condition alarm = GetAlarm(ref job, out msg); if (!string.IsNullOrEmpty(msg)) { this.tbResults.AppendText(DisplayTime() + ": " + cardCount.ToString() + ": " + msg); } // If the printer is not in alarm condition // starts a print job and increments cardCount if (alarm == 0) { // Sets the card type if (!_isZXP7) { job.JobControl.CardType = _cardType; } // Builds and prints the graphic layers job.BuildGraphicsLayers(SideEnum.Front, PrintTypeEnum.Color, 0, 0, 0, -1, GraphicTypeEnum.BMP, _bmpFront); job.BuildGraphicsLayers(SideEnum.Back, PrintTypeEnum.MonoK, 0, 0, 0, -1, GraphicTypeEnum.BMP, _bmpBack); job.PrintGraphicsLayers(1, out actionID); this.tbResults.AppendText(DisplayTime() + ": " + cardCount.ToString() + ": Print Job Processed with no Errors\r\n"); // Waits for the job status // "cleaning_up" or "done_ok" or is in error state z.JobWait(ref job, actionID, 180, out status); this.tbResults.AppendText(DisplayTime() + ": " + cardCount.ToString() + ": Job Wait Status = " + status + "\r\n"); cardCount++; } } // Make sure the last job is truly finished while (true) { z.JobWait(ref job, actionID, 180, out status); if (status == "done_ok" || status.Contains("error")) { break; } } this.tbResults.AppendText(DisplayTime() + ": Finished\r\n"); } catch (Exception exc) { this.tbResults.AppendText("Exception: " + exc.Message); } finally { z.Disconnect(ref job); z = null; } }