Exemplo n.º 1
0
        public String[] ReadMagCard(int timeout)
        {
            bool error = true;

            try
            {
                ThePrinterConn.Open();
                printer = ZebraPrinterFactory.GetInstance(ThePrinterConn);
                mcr     = printer.GetMagCardReader();

                PrinterStatus printerStatus = printer.GetCurrentStatus();
                bool          ready         = printerStatus.IsReadyToPrint;
                if (ready == false)
                {
                    return(null);
                }

                //MagCardReader mcr = printer.GetMagCardReader();
                if (mcr != null)
                {
                    //read
                    String[] tracks = mcr.Read(timeout);

                    if (tracks[0] != "" || tracks[1] != "" || tracks[2] != "")
                    {
                        ready = printerStatus.IsReadyToPrint;
                        if (ready)
                        {
                            String header = "! 0 200 200 0 1";
                            ThePrinterConn.Write(Encoding.UTF8.GetBytes(header + "\r\nBEEP 1\r\nPRINT\r\n"));
                        }
                    }

                    //SystemSounds.Beep.Play();
                    return(tracks);
                }

                //thePrinterConn.Close();

                error = false;
            }
            catch (Exception e)
            {
                Logger.Logger.Log(e);
                error = true;
            }
            if (error)
            {
                return(null);
            }
            else
            {
                return(new String[3] {
                    "", "", ""
                });
            }
        }
 /**
  * Thread for reading magnetic card swiped through printer
  * **/
 private void doReadMagCard()
 {
     updateGuiFromWorkerThread("Waiting for swipe...", Color.Gold);
     if (printer != null)
     {
         MagCardReader mcr = printer.GetMagCardReader();
         if (mcr != null)
         {
             String[] tracks = mcr.Read(10 * 1000);
             updateGuiTracks(tracks);
             updateGuiFromWorkerThread("Done", Color.Blue);
         }
         else
         {
             updateGuiFromWorkerThread("Failed to swipe", Color.Red);
         }
     }
     else
     {
         updateGuiFromWorkerThread("Connection error", Color.Red);
     }
     updateButtonFromWorkerThread(true);
 }