public int CountSMSmessages(SerialPort port)
        {
            int CountTotalMessages = 0;

            try
            {
                #region Execute Command

                string recievedData = ComPortConnectionClass.ExecCommand(port, "AT", 300, "No phone connected at ");
                recievedData = ComPortConnectionClass.ExecCommand(port, "AT+CMGF=1", 300, "Failed to set message format.");
                String command = "AT+CPMS?";
                recievedData = ComPortConnectionClass.ExecCommand(port, command, 1000, "Failed to count SMS message");
                int uReceivedDataLength = recievedData.Length;

                #endregion

                #region If command is executed successfully
                if ((recievedData.Length >= 45))//&& (recievedData.StartsWith("AT+CPMS?")))
                {
                    #region Parsing SMS
                    string[] strSplit = recievedData.Split(',');
                    string   strMessageStorageArea1 = strSplit[0];   //SM
                    string   strMessageExist1       = strSplit[1];   //Msgs exist in SM
                    #endregion

                    #region Count Total Number of SMS In SIM
                    CountTotalMessages = Convert.ToInt32(strMessageExist1);
                    #endregion
                }
                #endregion

                #region If command is not executed successfully
                else if (recievedData.Contains("ERROR"))
                {
                    #region Error in Counting total number of SMS
                    string recievedError = recievedData;
                    recievedError = recievedError.Trim();
                    recievedData  = "Following error occured while counting the message" + recievedError;
                    #endregion
                }
                #endregion

                return(CountTotalMessages);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public List <MODEL_SMS> ReadSMS(SerialPort port, string p_strCommand)
        {
            // Set up the phone and read the messages
            List <MODEL_SMS> messages = null;

            try
            {
                #region Execute Command
                // Check connection
                ComPortConnectionClass.ExecCommand(port, "AT", 300, "No phone connected");
                // Use message format "Text mode"
                ComPortConnectionClass.ExecCommand(port, "AT+CMGF=1", 300, "Failed to set message format.");
                // Use character set "PCCP437"

                ///ComPortConnectionClass.ExecCommand(port,"AT+CSCS=\"PCCP437\"", 300, "Failed to set character set.");


                //string manufacturer = ComPortConnectionClass.ExecCommand(port, "AT+CGMI", 300, "Failed to select message storage.");
                //string model = ComPortConnectionClass.ExecCommand(port, "AT+CGMM", 300, "Failed to select message storage.");
                //string IMEI = ComPortConnectionClass.ExecCommand(port, "AT+CGSN", 300, "Failed to select message storage.");
                //string software = ComPortConnectionClass.ExecCommand(port, "AT+CGMR", 300, "Failed to select message storage.");
                ////string MSISDN = ComPortConnectionClass.ExecCommand(port, "AT+CNUM", 300, "Failed to select message storage.");
                //string IMSI = ComPortConnectionClass.ExecCommand(port, "AT+CIMI", 300, "Failed to select message storage.");

                ////string Pstatus = ComPortConnectionClass.ExecCommand(port, "AT+CPAS", 300, "Failed to select message storage.");
                ////string Nstatus = ComPortConnectionClass.ExecCommand(port, "AT+CREG", 300, "Failed to select message storage.");
                //string battery = ComPortConnectionClass.ExecCommand(port, "AT+CBC", 300, "Failed to select message storage.");
                ////string read = ComPortConnectionClass.ExecCommand(port, "AT+CMGR", 300, "Failed to select message storage.");
                ////string IMSI = ComPortConnectionClass.ExecCommand(port, "AT+CIMI", 300, "Failed to select message storage.");


                // Select SIM storage
                //string input1 = ComPortConnectionClass.ExecCommand(port, "AT+CPMS=\"SM\"", 300, "Failed to select message storage.");
                // Read the messages
                //string input = ComPortConnectionClass.ExecCommand(port, p_strCommand, 5000, "Failed to read the messages.");

                string manufacturer = ComPortConnectionClass.ExecCommand(port, "AT", 300, "Failed to select message storage.");
                string model        = ComPortConnectionClass.ExecCommand(port, "ATE1", 300, "Failed to select message storage.");
                string IMEI         = ComPortConnectionClass.ExecCommand(port, "AT+IPR=115200", 300, "Failed to select message storage.");
                string software     = ComPortConnectionClass.ExecCommand(port, "AT&W", 300, "Failed to select message storage.");


                string manufacturer1 = ComPortConnectionClass.ExecCommand(port, "AT", 300, "Failed to select message storage.");
                string model1        = ComPortConnectionClass.ExecCommand(port, "AT+CMGF=1", 300, "Failed to select message storage.");
                //string input = ComPortConnectionClass.ExecCommand(port, "AT+CMGL=\"ALL\"", 300, "Failed to select message storage.");
                //string input = ComPortConnectionClass.ExecCommand(port, "AT+CMGL=\"REC UNREAD\"", 300, "Failed to select message storage.");
                string input = ComPortConnectionClass.ExecCommand(port, p_strCommand, 300, "Failed to select message storage.");

                #endregion

                #region Parse messages
                messages = ParseMessages(input);
                #endregion
            }
            catch (Exception ex)
            {
                throw ex;
            }

            if (messages != null)
            {
                return(messages);
            }
            else
            {
                return(null);
            }
        }