Exemple #1
0
        public string LoadSIM(SerialPort port)
        {
            string ma       = "";
            string provider = GetNameServiceCenter(port);
            SIM    sim      = new SIM(provider);

            ma = sim.maTimSoSIM;

            string command      = "AT+CUSD=1,\"" + ma + "\",15";
            string recievedData = ExecCommand(port, command, 2000, "Failed to set message format.");
            string result       = "";

            if (recievedData.Contains("+CUSD:"))
            {
                string[] chuoi = recievedData.Replace("\r\nOK\r\n", "").Split('\"');
                result = chuoi[3].Split('\r')[1];
                Thread.Sleep(500);
            }
            else
            {
                result = "ERROR";
            }
            return(result);
        }
Exemple #2
0
        //thu kiem tra account //1: TK chinh 2: TK khuyen mai
        public string GetBalances(SerialPort port, int n)
        {
            try
            {
                string provider     = GetNameServiceCenter(port).Replace("\"", "").Trim('\n').Trim(' ');
                string recievedData = ExecCommand(port, "AT", 300, "No phone connected");
                string command      = "AT+CMGF=1";
                recievedData = ExecCommand(port, command, 300, "Failed to set message format.");
                string result = "";
                SIM    sim    = new SIM(provider);
                string ma     = "";
                if (n == 1)
                {
                    ma = sim.maTKChinh;
                    switch (provider)
                    {
                    case "VN MOBIFONE":
                        result = GuiUSSD(command, recievedData, ma, port);
                        if (recievedData.Contains("+CUSD: 1"))
                        {
                            command = "AT+CUSD=1,\"" + ma + "\",15";
                            ExecCommand(port, command, 300, "Failed to set message format.");
                            Thread.Sleep(1000);
                        }
                        break;

                    default:
                        result = GuiUSSD(command, recievedData, ma, port);
                        break;
                    }
                    ;
                }
                else if (n == 2)
                {
                    ma = sim.maTKPhu;
                    switch (provider)
                    {
                    case "VN MOBIFONE":
                        result = GuiUSSD(command, recievedData, ma, port);
                        if (recievedData.Contains("+CUSD: 1"))
                        {
                            command = "AT+CUSD=1,\"" + ma + "\",15";
                            ExecCommand(port, command, 300, "Failed to set message format.");
                            Thread.Sleep(1000);
                        }
                        break;

                    default:
                        result = GuiUSSD(command, recievedData, ma, port);
                        break;
                    }
                    ;
                }

                return(result);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }