Exemplo n.º 1
0
        /// <summary>
        /// Perform sim card connection and contacts read.
        /// </summary>
        private void SimConnect()
        {
            MainClass.QtWait();

            if (GlobalObj.IsPowered)
            {
                // Disconnect card if needed
                GlobalObj.CloseConnection();
            }

            // Connect to smartcard
            retStr = GlobalObj.AnswerToReset(ref ATR);

            // check for error
            if (retStr != "")
            {
                // error on answer to reset
                log.Error("MainWindowClass::SimConnect: " + retStr);
                MainClass.ShowMessage(this, "ERROR", retStr, MainClass.MessageType.Error);
                return;
            }

            // read sim contacts and fill list
            retStr = GlobalObjUI.SelectSimContactsList();

            // check for error
            if (retStr != "")
            {
                if (retStr == GlobalObjUI.LMan.GetString("needpindisable"))
                {
                    // Pin1 enabled
                    MainClass.ShowMessage(this, "ERROR", retStr, MainClass.MessageType.Error);
                    EnableSimPinControl();
                    return;
                }
                else
                {
                    // error on reading contacts list
                    GlobalObj.CloseConnection();
                    MainClass.ShowMessage(this, "ERROR", retStr, MainClass.MessageType.Error);
                    return;
                }
            }

            ScanSimBefore();
            mainwindow_Ui.LstSimContacts.Clear();

            // Reset status values
            GlobalObjUI.SimADNStatus   = 1;
            GlobalObjUI.SimADNPosition = 0;
            GlobalObjUI.SimADNError    = "";

            // Start thread for reading process
            isEnd     = false;
            isReading = true;
            simThread = new System.Threading.Thread(new
                                                    System.Threading.ThreadStart(GlobalObjUI.ReadSimContactsList));
            simThread.Start();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Perform Power On
        /// </summary>
        private void GetATR()
        {
            mainwindow_Ui.TxtATR.Text  = "";
            mainwindow_Ui.TxtResp.Text = "";
            mainwindow_Ui.TxtCmd.Text  = "";
            MainClass.QtWait();

            // Connect to smartcard
            retStr = GlobalObj.AnswerToReset(ref ATR);

            if (retStr != "")
            {
                // error on answer to reset
                log.Error(retStr);
                MainClass.ShowMessage(this, "ERROR", retStr, MainClass.MessageType.Error);
                return;
            }

            mainwindow_Ui.TxtATR.Text = ATR;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Console Application
        /// </summary>
        public static void StartApp()
        {
            // create readers list
            List <string> allreaders = new List <string>();

            // loop for each managed readers type
            foreach (IReader rdr in GlobalObj.ReaderManager.Values)
            {
                allreaders.AddRange(rdr.Readers);
            }


            // display available readers
            Console.WriteLine("\r\n" + GlobalObj.LMan.GetString("readerslist") + ":");
            for (int n = 0; n < allreaders.Count; n++)
            {
                Console.WriteLine(n.ToString().PadLeft(3) + ". " + allreaders[n]);
            }
            Console.WriteLine("\r\n" + GlobalObj.LMan.GetString("readersel"));
            Console.Write("> ");
            command = Console.ReadLine();

            if (command == "EXIT")
            {
                // exit from application
                return;
            }

            try
            {
                // set reader to use
                GlobalObj.SelectedReader = allreaders[int.Parse(command)];
            }
            catch (Exception Ex)
            {
                // error detected
                log.Error("ConsoleManager::StartApp: " + Ex.Message);
                return;
            }


            // Connect to smartcard
            ret = GlobalObj.AnswerToReset(ref ATR);

            if (ret != "")
            {
                // error on answer to reset
                log.Error("ConsoleManager::StartApp: " + ret);
                Console.WriteLine(ret);
                return;
            }

            Console.WriteLine("\r\nAnswer To Reset: " + ATR + "\r\n");

            while (1 == 1)
            {
                Console.WriteLine(GlobalObj.LMan.GetString("cmdtosend"));
                Console.Write("> ");
                command = Console.ReadLine();

                if (command == "EXIT")
                {
                    // exit from loop and from application
                    GlobalObj.CloseConnection();
                    break;
                }

                ret = GlobalObj.SendReceive(command, ref response);
                if (ret != "")
                {
                    // error on send command
                    log.Error("ConsoleManager::StartApp: " + ret);
                    Console.WriteLine("< " + ret);
                }
                else
                {
                    // response returned
                    Console.WriteLine("< " + response + "\r\n");
                }
            }
        }