My Professional Profile

I am Johnson Augustine Sr.Software Engineer and System Architect. I have 10 Yrs of hands on expertise in ASP.net MVC 5 , Angular 5 , C# MVC Razor, WPF MVVM , Android , IOS Swift 3 , IOS11 MSSQL,MySQL Database,,PHP,C/C++/Visual C++/G++/QT++,Com,DirectX,Open CV,EMGU CV , embedded System Development , [Raspberry PI]. ,html,Javascript,Jquery,Ajax.CSS , Networking ,Cyber security, Ethical Hacking You can see my professional profile at http://linkedin.com/in/johnsontaugustine Email : johnsonaugustine@live.com

Sunday, 30 December 2012

creating TABs in Android

To create tabs in android use the bellow code

Should extend the class  TabActivity

TabHost tabobj;
tabobj=getTabHost();
 TabSpec tabinfo=tabobj.newTabSpec("info");
 tabinfo.setIndicator("Info");

Intent inf=new Intent(this,Homepage.class);
 tabinfo.setContent(inf);
tabobj.addTab(tabinfo);

How to view error details in asp.net when hosted in a remote server

To view errors instead of the error  " Error in \n application " just off the  custom error mode


 <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
           
        </customErrors>
        -->

Instead of above use this


 <customErrors mode="off" defaultRedirect="GenericErrorPage.htm">
           
        </customErrors>
        -->

Wednesday, 19 December 2012

ASP.net C# Data base connection with MS SQL


using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
/// <summary>
/// Summary description for cls_LIFE_CONNECT
/// </summary>
public class cls_Connectionclass_CONNECT
{
   private  SqlCommand cmd = new SqlCommand();
   private  SqlConnection con = new SqlConnection();
   public  SqlDataAdapter da = new SqlDataAdapter();
   public DataTable dt;

   public cls_Connectionclass_CONNECT()
{
        con.ConnectionString = "server=MYSERVER;database=DB_NyDb;uid=sa;pwd=admin123";

}
    private SqlConnection connect() // Openning connection
    {
        if (con.State == ConnectionState.Open)
        {
            con.Close();
        }
        con.Open();
        return con;
    }
    public DataTable table(string query)  // return Data tables or rows of data
    {

        cmd.Connection = connect();
        cmd.CommandText = query;
        da.SelectCommand = cmd ;
        dt = new DataTable();
        da.Fill(dt);
        return dt;
    }

    public int exe_non_query(string query) // execute query , return an integer as result
    {
        cmd.Connection = connect();
        cmd.CommandText = query;
        return cmd.ExecuteNonQuery();
    }
    public object exe_scalar(string query) // Retrieve single values
    {
        cmd.Connection = connect();
        cmd.CommandText = query;
        return cmd.ExecuteScalar();
    }

}

Managing grid view index changed event in asp C#.net

If you allowed paging for grid view  in asp.net and if some changes happened to the items then we have to tell the system to make necessary changes . here is the code.


 protected void Grd_CategoryList_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        Grd_CategoryList.PageIndex = e.NewPageIndex; //   Grd_CategoryList - Id of the GridView
       
        Fill_Category_GridList();  // Calling bind grid view manual function
    }



Software testing tools used by IT/ITES firms


Most of the IT product developing firms are using automated testing tools to validate and ensure system reliability. The following are the some tools among them . 


TestComplete
Selenium
JUnit


Saturday, 15 December 2012

Keyboard Shortcuts (Microsoft Windows)

Keyboard Shorcuts (Microsoft Windows)
1. CTRL+C (Copy)
2. CTRL+X (Cut)
...... 3. CTRL+V (Paste)
4. CTRL+Z (Undo)
5. DELETE (Delete)
6. SHIFT+DELETE (Delete the selected item permanently without placing the item in the Recycle Bin)
7. CTRL while dragging an item (Copy the selected item)
8. CTRL+SHIFT while dragging an item (Create a shortcut to the selected item)
9. F2 key (Rename the selected item)
10. CTRL+RIGHT ARROW (Move the insertion point to the beginning of the next word)
11. CTRL+LEFT ARROW (Move the insertion point to the beginning of the previous word)
12. CTRL+DOWN ARROW (Move the insertion point to the beginning of the next paragraph)
13. CTRL+UP ARROW (Move the insertion point to the beginning of the previous paragraph)
14. CTRL+SHIFT with any of the arrow keys (Highlight a block of text)
SHIFT with any of the arrow keys (Select more than one item in a window or on the desktop, or select text in a document)
15. CTRL+A (Select all)
16. F3 key (Search for a file or a folder)
17. ALT+ENTER (View the properties for the selected item)
18. ALT+F4 (Close the active item, or quit the active program)
19. ALT+ENTER (Display the properties of the selected object)
20. ALT+SPACEBAR (Open the shortcut menu for the active window)
21. CTRL+F4 (Close the active document in programs that enable you to have multiple documents opensimultaneou sly)
22. ALT+TAB (Switch between the open items)
23. ALT+ESC (Cycle through items in the order that they had been opened)
24. F6 key (Cycle through the screen elements in a window or on the desktop)
25. F4 key (Display the Address bar list in My Computer or Windows Explorer)
26. SHIFT+F10 (Display the shortcut menu for the selected item)
27. ALT+SPACEBAR (Display the System menu for the active window)
28. CTRL+ESC (Display the Start menu)
29. ALT+Underlined letter in a menu name (Display the corresponding menu) Underlined letter in a command name on an open menu (Perform the corresponding command)
30. F10 key (Activate the menu bar in the active program)
31. RIGHT ARROW (Open the next menu to the right, or open a submenu)
32. LEFT ARROW (Open the next menu to the left, or close a submenu)
33. F5 key (Update the active window)
34. BACKSPACE (View the folder onelevel up in My Computer or Windows Explorer)
35. ESC (Cancel the current task)
36. SHIFT when you insert a CD-ROMinto the CD-ROM drive (Prevent the CD-ROM from automatically playing)
Dialog Box - Keyboard Shortcuts
1. CTRL+TAB (Move forward through the tabs)
2. CTRL+SHIFT+TAB (Move backward through the tabs)
3. TAB (Move forward through the options)
4. SHIFT+TAB (Move backward through the options)
5. ALT+Underlined letter (Perform the corresponding command or select the corresponding option)
6. ENTER (Perform the command for the active option or button)
7. SPACEBAR (Select or clear the check box if the active option is a check box)
8. Arrow keys (Select a button if the active option is a group of option buttons)
9. F1 key (Display Help)
10. F4 key (Display the items in the active list)
11. BACKSPACE (Open a folder one level up if a folder is selected in the Save As or Open dialog box)

Microsoft Natural Keyboard Shortcuts
1. Windows Logo (Display or hide the Start menu)
2. Windows Logo+BREAK (Display the System Properties dialog box)
3. Windows Logo+D (Display the desktop)
4. Windows Logo+M (Minimize all of the windows)
5. Windows Logo+SHIFT+M (Restorethe minimized windows)
6. Windows Logo+E (Open My Computer)
7. Windows Logo+F (Search for a file or a folder)
8. CTRL+Windows Logo+F (Search for computers)
9. Windows Logo+F1 (Display Windows Help)
10. Windows Logo+ L (Lock the keyboard)
11. Windows Logo+R (Open the Run dialog box)
12. Windows Logo+U (Open Utility Manager)
13. Accessibility Keyboard Shortcuts
14. Right SHIFT for eight seconds (Switch FilterKeys either on or off)
15. Left ALT+left SHIFT+PRINT SCREEN (Switch High Contrast either on or off)
16. Left ALT+left SHIFT+NUM LOCK (Switch the MouseKeys either on or off)
17. SHIFT five times (Switch the StickyKeys either on or off)
18. NUM LOCK for five seconds (Switch the ToggleKeys either on or off)
19. Windows Logo +U (Open Utility Manager)
20. Windows Explorer Keyboard Shortcuts
21. END (Display the bottom of the active window)
22. HOME (Display the top of the active window)
23. NUM LOCK+Asterisk sign (*) (Display all of the subfolders that are under the selected folder)
24. NUM LOCK+Plus sign (+) (Display the contents of the selected folder)
25. NUM LOCK+Minus sign (-) (Collapse the selected folder)
26. LEFT ARROW (Collapse the current selection if it is expanded, or select the parent folder)
27. RIGHT ARROW (Display the current selection if it is collapsed, or select the first subfolder)
Shortcut Keys for Character Map
After you double-click a character on the grid of characters, you can move through the grid by using the keyboard shortcuts:
1. RIGHT ARROW (Move to the rightor to the beginning of the next line)
2. LEFT ARROW (Move to the left orto the end of the previous line)
3. UP ARROW (Move up one row)
4. DOWN ARROW (Move down one row)
5. PAGE UP (Move up one screen at a time)
6. PAGE DOWN (Move down one screen at a time)
7. HOME (Move to the beginning of the line)
8. END (Move to the end of the line)
9. CTRL+HOME (Move to the first character)
10. CTRL+END (Move to the last character)
11. SPACEBAR (Switch between Enlarged and Normal mode when a character is selected)
Microsoft Management Console (MMC)
Main Window Keyboard Shortcuts
1. CTRL+O (Open a saved console)
2. CTRL+N (Open a new console)
3. CTRL+S (Save the open console)
4. CTRL+M (Add or remove a console item)
5. CTRL+W (Open a new window)
6. F5 key (Update the content of all console windows)
7. ALT+SPACEBAR (Display the MMC window menu)
8. ALT+F4 (Close the console)
9. ALT+A (Display the Action menu)
10. ALT+V (Display the View menu)
11. ALT+F (Display the File menu)
12. ALT+O (Display the Favorites menu)

MMC Console Window Keyboard Shortcuts
1. CTRL+P (Print the current page or active pane)
2. ALT+Minus sign (-) (Display the window menu for the active console window)
3. SHIFT+F10 (Display the Action shortcut menu for the selected item)
4. F1 key (Open the Help topic, if any, for the selected item)
5. F5 key (Update the content of all console windows)
6. CTRL+F10 (Maximize the active console window)
7. CTRL+F5 (Restore the active console window)
8. ALT+ENTER (Display the Properties dialog box, if any, for theselected item)
9. F2 key (Rename the selected item)
10. CTRL+F4 (Close the active console window. When a console has only one console window, this shortcut closes the console)
Remote Desktop Connection Navigation
1. CTRL+ALT+END (Open the Microsoft Windows NT Security dialog box)
2. ALT+PAGE UP (Switch between programs from left to right)
3. ALT+PAGE DOWN (Switch between programs from right to left)
4. ALT+INSERT (Cycle through the programs in most recently used order)
5. ALT+HOME (Display the Start menu)
6. CTRL+ALT+BREAK (Switch the client computer between a window and a full screen)
7. ALT+DELETE (Display the Windows menu)
8. CTRL+ALT+Minus sign (-) (Place a snapshot of the active window in the client on the Terminal server clipboard and provide the same functionality as pressing PRINT SCREEN on a local computer.)
9. CTRL+ALT+Plus sign (+) (Place asnapshot of the entire client window area on the Terminal server clipboardand provide the same functionality aspressing ALT+PRINT SCREEN on a local computer.)

Microsoft Internet Explorer Keyboard Shortcuts
1. CTRL+B (Open the Organize Favorites dialog box)
2. CTRL+E (Open the Search bar)
3. CTRL+F (Start the Find utility)
4. CTRL+H (Open the History bar)
5. CTRL+I (Open the Favorites bar)
6. CTRL+L (Open the Open dialog box)
7. CTRL+N (Start another instance of the browser with the same Web address)
8. CTRL+O (Open the Open dialog box,the same as CTRL+L)
9. CTRL+P (Open the Print dialog box)
10. CTRL+R (Update the current Web )

Friday, 14 December 2012

Send sms using API and sms gateway


It is very simple code to do this . use api http request for doing that . For this you should have enough sms credit in your account  with a registered account with sms.scibero.com.

Code

======


public string apicall(string url)  // API Push
    {
        HttpWebRequest httpreq = (HttpWebRequest)WebRequest.Create(url);

        try
        {

            HttpWebResponse httpres = (HttpWebResponse)httpreq.GetResponse();

            StreamReader sr = new StreamReader(httpres.GetResponseStream());

            string results = sr.ReadToEnd();

            sr.Close();
            return results;



        }
        catch
        {
            return "0";
        }
    }




public void SendSMS()
    {

        try
        {
         
            mobile = "to number";
            message2 = "Your sms here '";
            username = "your user name";
            password = "your pwd";
            domian = "sms.scibero.com";
            senderid = "sender";
            string result = apicall("http://" + domian + "/pushsms.php?username=" + username + "&password=" + password + "&sender=" + senderid + "&to=" + mobile + "&message=" + message2);

            if (!result.StartsWith("Wrong Username or Password"))
            {
                //ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "success", "alert('Message Sent')", true);
            }
            else
            {
               // ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "success", "alert('Message Sending Failed')", true);
            }

        }
        catch
        {
        }
    }

Sending dynamic email from Webmails


Code bellow shows how to send emails from asp.net c#  from web servers .

 public void SendMail()
    {

        MailMessage mm = new MailMessage("from id ", "toid");
       //(2) Assign the MailMessage's properties
         mm.Subject = "sub";
         mm.Body = "message";
         mm.IsBodyHtml =true;
        //(3) Create the SmtpClient object
        //'Dim smtp As New SmtpClient
       SmtpClient  smtp = new SmtpClient("scibero.com");
        //'(4) Send the MailMessage (will use the Web.config settings)
       smtp.Send(mm);
     }

Receive SMS using ASP.net C#

This is used to receive sms from gsm modem and decode it . It needs a static number and high efficency GSM modem . Don't try with your gsm mobile hand set may cause problems . . I used this GSM modem in my MCA Degree days to send Bulk sms to my friends , but after few months i loss my phone from working condition .i also implemented dynamic messaging that is if some one send sms to me , if i have the number in my contact then i will select a random sms from my canned sms table and replay to him with his name ie hi < name> "wr are u now "  , that is fully dynamic . . you people can also try this


// ************Code by Johnson Augustine*******


using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
namespace SMS
{
    //The function of this class is to read message from a mobile and decrypt it
 
    class ReceiveSMS
    {
        SMSCOMMS SMSEngine;
        SendSMS obj = new SendSMS();
        public static string[] messageDetails;

        public ReceiveSMS()
        {
            messageDetails = new string[3];
            messageDetails[0] = "";
            messageDetails[1] = "";
            messageDetails[2] = "";
        }
        //This function is the entry point to this class.All other functions are called from this class
        public void receiveSMS()
        {
            try
            {
                messageDetails[0] = "";
                messageDetails[1] = "";
                messageDetails[2] = "";
                SMSCOMMS.pdu = string.Empty;
                string pdu;
                string x = "COM20";
                SMSEngine = new SMSCOMMS(ref x);
                SMSEngine.Open();               // Open the Port in which mobile is connected
                SMSEngine.readSMS();      // Read SMS From Mobile through Port
                SMSEngine.Close();              // Close Port
                if (SMSCOMMS.pdu== "")
                {
                }
                else
                {
                    messageDetails[0] = decryptNumber(extractMessageCentre(SMSCOMMS.pdu));       // Decrypt Message Centre Number
                    messageDetails[1] = decryptNumber(extractSenderNumber(SMSCOMMS.pdu));        // Decrypt Sender Number
                    messageDetails[2] = DecryptMessage(ExtractMessageFromPdu(SMSCOMMS.pdu));      // Decrypt Message
                }
                }
            catch (Exception ex)
            {
            }
        }


        //The function is to extract Message centre number from PDU

        public string extractMessageCentre(string pdu)
        {
            string[] messageDetails = new string[3];
            string extractedNumber = string.Empty;
            try
            {
                for (int i = 4; i < 16; i++)
                {
                    extractedNumber = "" + extractedNumber + pdu.Substring(i, 1) + "";

                }
            }
            catch (Exception ex)
            {
            }
            return extractedNumber;
        }

        //The function is to extract   sender number from the PDU

        public string extractSenderNumber(string pdu)
        {
            string extractedNumber = string.Empty;
            try
            {
                for (int i = 22; i < 34; i++)
                {
                    extractedNumber = "" + extractedNumber + pdu.Substring(i, 1) + "";

                }
            }
            catch (Exception ex)
            {
            }
            return extractedNumber;
        }

        //The function is to Decrypt a number from PDU (Message Centre Number & Sender Number)

        public string decryptNumber(string number)
        {
            string[] receive = new string[number.Length + 1];
            string returnreceive = string.Empty;
            try
            {

                for (int i = 0; i < number.Length; i++)
                {
                    receive.SetValue(number.Substring(i, 1), i);
                }


                for (int i = 0; i < receive.Length; i++)
                {
                    string swap;
                    swap = receive[i].ToString();
                    receive[i] = receive[i + 1].ToString();
                    receive[i + 1] = swap;
                    i++;
                    if (i == number.Length - 1)
                    {
                        if (number.Length % 2 == 0)
                        {
                            i++;
                        }
                    }
                }
                for (int i = 0; i < receive.Length; i++)
                {
                    returnreceive = "" + returnreceive + receive[i].ToString() + "";
                }
            }
            catch (Exception ex)
            {

            }
            return returnreceive;
        }


        //The Function is to extract Message in the encrypted format from the PDU

        public string ExtractMessageFromPdu(string pdu)
        {
            string msg = string.Empty;
            try
            {
                for (int i = 54; i < pdu.Length; i++)
                {
                    msg = "" + msg + pdu.Substring(i, 1);
                }
            }
            catch (Exception ex)
            {
            }
            return msg;
        }

        // The two functions below decrypts message extracted from the PDU

        public string DecryptMessage(string msg)
        {
            int j = 0;
            string[] bin = new string[1000];
            try
            {
                string message = msg.Trim();
                int count = 1, pos = 0;
                string[] hexInput = new string[(msg.Length) / 2];
                string[] splitstring = new string[8];
                string[] binSeven = new string[100];
                string concat = string.Empty;
                string temp = string.Empty;

             

                //Split entire string into pairs

                for (int i = 0; i < message.Length - 1; i++)
                {
                    hexInput[j] = msg.Substring(i, 2);
                    j++;
                    i++;

                }

                //Convert each pair into 8  bit binary

                for (int i = 0; i < j; i++)
                {

                    bin[i] = Convert.ToString(Convert.ToInt32(hexInput[i], 16), 2);

                    while (bin[i].Length != 8)
                    {
                        bin[i] = "0" + bin[i] + "";
                    }

                }
            }
            catch (Exception ex)
            {
            }
            //Passes a string array containing 8 bit binary values to the next function

           return CovertFromHex(bin, j);



        }
        //The input to this function is a string array containing 8 bit binary values equivalent to hex values

        public string CovertFromHex(string[] hexValue, int length)
        {
            string message = string.Empty;
            try
            {
                int count = 1, pos = 0;
                string[] hexInput = new string[hexValue.Length];
                string[] splitstring = new string[8];
                string[] bin = new string[1000];
                string concat = string.Empty;
                string temp = string.Empty;
                for (int i = 0; i < length; i++)
                {

                    string extract = hexValue[i].ToString();

                    if (extract != string.Empty)
                    {
                        string[] x = new string[count];
                        for (int k = 0; k < extract.Length; k++)
                        {

                            if (k >= count)
                            {
                                concat = "" + concat + extract.Substring(k, 1) + "";
                            }
                            else
                            {

                                x[k] = extract.Substring(k, 1);
                            }
                        }
                        bin[pos] = "" + concat + temp + "";
                        temp = string.Empty;
                        concat = string.Empty;
                        count = count + 1;
                        for (int j = 0; j < x.Length; j++)
                        {
                            temp = "" + temp + x[j].ToString() + "";
                        }
                        pos++;
                        if (count == 8)
                        {
                            count = 1;
                            bin[pos] = temp;
                            temp = string.Empty;
                            pos++;

                        }
                    }


                }
                bin[pos - 1] = "" + temp + bin[pos - 1].ToString() + "";


                //Binary to ASCII
                string[] asciiVal = new string[pos];
                for (int i = 0; i < pos; i++)
                {
                    asciiVal[i] = Convert.ToInt64(bin[i].ToString(), 2).ToString();

                }

                for (int i = 0; i < pos; i++)
                {

                    message = "" + message + char.ConvertFromUtf32(Convert.ToInt32(asciiVal[i].ToString()));
                }
            }
            catch (Exception ex)
            {
            }
            return message;

        }

    }
    }

SMSCOMMS class for send sms using AT Commands



All development rights reserved to Johnson TA . Use this for study purpose only .

See this for AT Command descriptions

My code

=====================
using System;
using System.IO.Ports;
using System.Threading;
using System.Text;


public class SMSCOMMS
{
   
    private SerialPort SMSPort;
    private Thread ReadThread;
    public static string pdu;
    //Constructor
    public SMSCOMMS(ref string COMMPORT)
    {
        SMSPort = new SerialPort();
        SMSPort.PortName = COMMPORT;
        SMSPort.BaudRate = 9600;
        SMSPort.Parity = Parity.None;
        SMSPort.DataBits = 8;
        SMSPort.StopBits = StopBits.One;
        SMSPort.Handshake = Handshake.RequestToSend;
        SMSPort.DtrEnable = true;
        SMSPort.RtsEnable = true;
        SMSPort.NewLine = System.Environment.NewLine;
        ReadThread = new Thread(
            new System.Threading.ThreadStart(readSMS));

        pdu = string.Empty;


    }

    //Open the port
    public void Open()
    {
        try
        {
            if (SMSPort.IsOpen == false)
            {
                SMSPort.Open();

            }
        }
        catch (Exception ex)
        {
        }
       
    }

    //Close the Port
    public void Close()
    {
        try
        {
            if (SMSPort.IsOpen == true)
            {
                SMSPort.Close();
            }
        }
        catch (Exception ex)
        {
        }
    }


    //Send message in pdu format
    public  void SendPDU(string SMSMessage,int length)
    {
        try
        {
            string MyMessage = SMSMessage.Trim();
            string cmd;
            string port = SMSPort.PortName;
            char ch = '"';
            int lengthOfMessage;
            if (length % 7 > 0)
            {
                lengthOfMessage = ((length + 13) - (length / 7));

            }
            else
            {
                lengthOfMessage = (((length + 13) - (length / 7)) + 1);

            }

            if (SMSPort.IsOpen == true)
            {
                string b;
                ASCIIEncoding ascii = new ASCIIEncoding();

                cmd = "AT+CMGS=" + lengthOfMessage + "";
                SMSPort.WriteLine(cmd);

                byte[] RXBuffer = new byte[SMSPort.ReadBufferSize + 1];
                SMSPort.Read(RXBuffer, 0, SMSPort.ReadBufferSize);

                b = Encoding.ASCII.GetString(RXBuffer, 0, RXBuffer.Length);

                cmd = string.Empty;
                cmd = "" + MyMessage + char.ConvertFromUtf32(26) + "";
                SMSPort.WriteLine(cmd);

                SMSPort.Read(RXBuffer, 0, SMSPort.ReadBufferSize);

                b = Encoding.ASCII.GetString(RXBuffer, 0, RXBuffer.Length);

                string x = string.Empty;

                b = Encoding.ASCII.GetString(RXBuffer, 0, RXBuffer.Length);

            }
        }
        catch (Exception ex)
        {
        }
     
    }


    //Read the port

    public void readSMS()
    {
        try
        {
        Open();
        string cmd;
        char ch = '"';
        ASCIIEncoding ascii = new ASCIIEncoding();
        cmd = "AT+CPMS=" + ch + "ME" + ch + "";
        SMSPort.WriteLine(cmd);
        Thread.Sleep(1000);
        byte[] RXBuffer = new byte[SMSPort.ReadBufferSize + 1];
        SMSPort.Read(RXBuffer, 0, SMSPort.ReadBufferSize);
        string x = Encoding.ASCII.GetString(RXBuffer, 0, RXBuffer.Length);
        Thread.Sleep(1000);
        cmd = "AT+CMGR=5";
        SMSPort.WriteLine(cmd);
        cmd = "" + char.ConvertFromUtf32(13) + "";
       
   
       // SMSPort.Read(RXBuffer, 0, SMSPort.ReadBufferSize);
       //string  b = Encoding.ASCII.GetString(RXBuffer, 0, RXBuffer.Length);

       pdu = SMSPort.ReadLine();

       pdu = SMSPort.ReadLine();
       if (pdu == "+CMS ERROR: 500")
       {
           pdu = string.Empty;
       }
       else
       {
           pdu = SMSPort.ReadLine();
           pdu = pdu.Trim();
       }

       cmd = "AT+CMGD=1";
       SMSPort.WriteLine(cmd);
           Close();
   
        }
        catch(Exception ex)
        {
        }
   
        }
}

======================================

SMS and the PDU format


Introduction

The SMS message, as specified by the Etsi  organization (documents GSM 03.40 and GSM 03.38), can be up to 160 characters long, where each character is 7 bits according to the 7-bit default alphabet. Eight-bit messages (max 140 characters) are usually not viewable by the phones as text messages; instead they are used for data in e.g. smart messaging (images and ringing tones) and OTA provisioning of WAP settings.  16-bit messages (max 70 characters) are used for Unicode (UCS2) text messages, viewable by most phones. A 16-bit text message of class 0 will on some phones appear as a Flash SMS (aka blinking SMS or alert SMS) Thanks for [http://www.dreamfabric.com] .


The 7 bit default alphabet

This is the 7 bit default alphabet as specified by GSM 03.38. The corresponding ISO-8859-1 decimal codes are shown in the rightmost column. Note that the euro sign (€) is a member of the ISO-8859-15 character set. 

HexDecCharacter nameCharacterISO-8859-1 DEC
0x000COMMERCIAL AT@64
0x011POUND SIGN£163
0x022DOLLAR SIGN$36
0x033YEN SIGN¥165
0x044LATIN SMALL LETTER E WITH GRAVEè232
0x055LATIN SMALL LETTER E WITH ACUTEé233
0x066LATIN SMALL LETTER U WITH GRAVEù249
0x077LATIN SMALL LETTER I WITH GRAVEì236
0x088LATIN SMALL LETTER O WITH GRAVEò242
0x099LATIN CAPITAL LETTER C WITH CEDILLAÇ199
0x0A10LINE FEED10
0x0B11LATIN CAPITAL LETTER O WITH STROKEØ216
0x0C12LATIN SMALL LETTER O WITH STROKEø248
0x0D13CARRIAGE RETURN13
0x0E14LATIN CAPITAL LETTER A WITH RING ABOVEÅ197
0x0F15LATIN SMALL LETTER A WITH RING ABOVEå229
0x1016GREEK CAPITAL LETTER DELTAΔ
0x1117LOW LINE_95
0x1218GREEK CAPITAL LETTER PHIΦ
0x1319GREEK CAPITAL LETTER GAMMAΓ
0x1420GREEK CAPITAL LETTER LAMBDAΛ
0x1521GREEK CAPITAL LETTER OMEGAΩ
0x1622GREEK CAPITAL LETTER PIΠ
0x1723GREEK CAPITAL LETTER PSIΨ
0x1824GREEK CAPITAL LETTER SIGMAΣ
0x1925GREEK CAPITAL LETTER THETAΘ
0x1A26GREEK CAPITAL LETTER XIΞ
0x1B27ESCAPE TO EXTENSION TABLE
0x1B0A27 10FORM FEED12
0x1B1427 20CIRCUMFLEX ACCENT^94
0x1B2827 40LEFT CURLY BRACKET{123
0x1B2927 41RIGHT CURLY BRACKET}125
0x1B2F27 47REVERSE SOLIDUS (BACKSLASH)\92
0x1B3C27 60LEFT SQUARE BRACKET[91
0x1B3D27 61TILDE~126
0x1B3E27 62RIGHT SQUARE BRACKET]93
0x1B4027 64VERTICAL BAR|124
0x1B6527 101EURO SIGN164 (ISO-8859-15)
0x1C28LATIN CAPITAL LETTER AEÆ198
0x1D29LATIN SMALL LETTER AEæ230
0x1E30LATIN SMALL LETTER SHARP S (German)ß223
0x1F31LATIN CAPITAL LETTER E WITH ACUTEÉ201
0x2032SPACE32
0x2133EXCLAMATION MARK!33
0x2234QUOTATION MARK"34
0x2335NUMBER SIGN#35
0x2436CURRENCY SIGN¤164 (ISO-8859-1)
0x2537PERCENT SIGN%37
0x2638AMPERSAND&38
0x2739APOSTROPHE'39
0x2840LEFT PARENTHESIS(40
0x2941RIGHT PARENTHESIS)41
0x2A42ASTERISK*42
0x2B43PLUS SIGN+43
0x2C44COMMA,44
0x2D45HYPHEN-MINUS-45
0x2E46FULL STOP.46
0x2F47SOLIDUS (SLASH)/47
0x3048DIGIT ZERO048
0x3149DIGIT ONE149
0x3250DIGIT TWO250
0x3351DIGIT THREE351
0x3452DIGIT FOUR452
0x3553DIGIT FIVE553
0x3654DIGIT SIX654
0x3755DIGIT SEVEN755
0x3856DIGIT EIGHT856
0x3957DIGIT NINE957
0x3A58COLON:58
0x3B59SEMICOLON;59
0x3C60LESS-THAN SIGN<60
0x3D61EQUALS SIGN=61
0x3E62GREATER-THAN SIGN>62
0x3F63QUESTION MARK?63
0x4064INVERTED EXCLAMATION MARK¡161
0x4165LATIN CAPITAL LETTER AA65
0x4266LATIN CAPITAL LETTER BB66
0x4367LATIN CAPITAL LETTER CC67
0x4468LATIN CAPITAL LETTER DD68
0x4569LATIN CAPITAL LETTER EE69
0x4670LATIN CAPITAL LETTER FF70
0x4771LATIN CAPITAL LETTER GG71
0x4872LATIN CAPITAL LETTER HH72
0x4973LATIN CAPITAL LETTER II73
0x4A74LATIN CAPITAL LETTER JJ74
0x4B75LATIN CAPITAL LETTER KK75
0x4C76LATIN CAPITAL LETTER LL76
0x4D77LATIN CAPITAL LETTER MM77
0x4E78LATIN CAPITAL LETTER NN78
0x4F79LATIN CAPITAL LETTER OO79
0x5080LATIN CAPITAL LETTER PP80
0x5181LATIN CAPITAL LETTER QQ81
0x5282LATIN CAPITAL LETTER RR82
0x5383LATIN CAPITAL LETTER SS83
0x5484LATIN CAPITAL LETTER TT84
0x5585LATIN CAPITAL LETTER UU85
0x5686LATIN CAPITAL LETTER VV86
0x5787LATIN CAPITAL LETTER WW87
0x5888LATIN CAPITAL LETTER XX88
0x5989LATIN CAPITAL LETTER YY89
0x5A90LATIN CAPITAL LETTER ZZ90
0x5B91LATIN CAPITAL LETTER A WITH DIAERESISÄ196
0x5C92LATIN CAPITAL LETTER O WITH DIAERESISÖ214
0x5D93LATIN CAPITAL LETTER N WITH TILDEÑ209
0x5E94LATIN CAPITAL LETTER U WITH DIAERESISÜ220
0x5F95SECTION SIGN§167
0x6096INVERTED QUESTION MARK¿191
0x6197LATIN SMALL LETTER Aa97
0x6298LATIN SMALL LETTER Bb98
0x6399LATIN SMALL LETTER Cc99
0x64100LATIN SMALL LETTER Dd100
0x65101LATIN SMALL LETTER Ee101
0x66102LATIN SMALL LETTER Ff102
0x67103LATIN SMALL LETTER Gg103
0x68104LATIN SMALL LETTER Hh104
0x69105LATIN SMALL LETTER Ii105
0x6A106LATIN SMALL LETTER Jj106
0x6B107LATIN SMALL LETTER Kk107
0x6C108LATIN SMALL LETTER Ll108
0x6D109LATIN SMALL LETTER Mm109
0x6E110LATIN SMALL LETTER Nn110
0x6F111LATIN SMALL LETTER Oo111
0x70112LATIN SMALL LETTER Pp112
0x71113LATIN SMALL LETTER Qq113
0x72114LATIN SMALL LETTER Rr114
0x73115LATIN SMALL LETTER Ss115
0x74116LATIN SMALL LETTER Tt116
0x75117LATIN SMALL LETTER Uu117
0x76118LATIN SMALL LETTER Vv118
0x77119LATIN SMALL LETTER Ww119
0x78120LATIN SMALL LETTER Xx120
0x79121LATIN SMALL LETTER Yy121
0x7A122LATIN SMALL LETTER Zz122
0x7B123LATIN SMALL LETTER A WITH DIAERESISä228
0x7C124LATIN SMALL LETTER O WITH DIAERESISö246
0x7D125LATIN SMALL LETTER N WITH TILDEñ241
0x7E126LATIN SMALL LETTER U WITH DIAERESISü252
0x7F127LATIN SMALL LETTER A WITH GRAVEà224



Flash SMS

On some phones (all Nokia, some Siemens, Ericsson, Motorola etc..) a class 0 message will appear as a flash SMS message. These messages appear on the screen immediately upon arrival, without the need to press any buttons on the phone. If the data coding scheme is set to 16-bit unicode (ucs2), and the message starts with "0001", it will appear as a blinking flash message.

OctetValueDescription
TP-DCS1816 bits (UCS2), message class 0
TP-VPAAValidity period
TP-UDL0CUser Data Length, 12 octets
TP-UD00 01 00 41 00 6C 00 65 00 72 00 74User Data, message "Alert"
This table shows some relevant octets in a flash SMS message

The first unicode character ("00 01") enables the blinking. The maximum length of such a message will then be 69 unicode characters.


The PDU format

There are two ways of sending and receiving SMS messages: by text mode and by PDU (protocol description unit) mode. The text mode (unavailable on some phones) is just an encoding of the bit stream represented by the PDU mode. Alphabets may differ and there are several encoding alternatives when displaying an SMS message. The most common options are "PCCP437", "PCDN", "8859-1", "IRA" and "GSM". These are all set by the at-command  AT+CSCS, when you read the message in a computer application. If you read the message on your phone, the phone will choose a proper encoding. An application capable of reading incoming SMS messages, can thus use text mode or PDU mode. If text mode is used, the application is bound to (or limited by) the set of preset encoding options. In some cases, that's just not good enough. If PDU mode is used, any encoding can be implemented.
Receiving a message in the PDU mode

The PDU string contains not only the message, but also a lot of meta-information about the sender, his SMS service center, the time stamp etc. It is all in the form of hexa-decimal octets or decimal semi-octets. The following string is what I received on a Nokia 6110  when sending the message containing "hellohello" from www.mtn.co.za .

07 917283010010F5 040BC87238880900F10000993092516195800AE8329BFD4697D9EC37

This octet sequence consists of three parts: An initial octet indicating the length of the SMSC information ("07"), the SMSC information itself ("917283010010F5"), and the SMS_DELIVER part (specified by ETSI in GSM 03.40).

Note: on some phones (e.g. Ericssson 888?) the first three (colored) parts are omitted when showing the message in PDU mode!


Octet(s)Description
07Length of the SMSC information (in this case 7 octets)
91Type-of-address of the SMSC. (91 means international format of the phone number)
72 83 01 00 10 F5Service center number(in decimal semi-octets). The length of the phone number is odd (11), so a trailing F has been added to form proper octets. The phone number of this service center is "+27381000015". See below.
04First octet of this SMS-DELIVER message.
0BAddress-Length. Length of the sender number (0B hex = 11 dec)
C8Type-of-address of the sender number
72 38 88 09 00 F1Sender number (decimal semi-octets), with a trailing F
00TP-PID. Protocol identifier.
00TP-DCS Data coding scheme
99 30 92 51 61 95 80TP-SCTS. Time stamp (semi-octets)
0ATP-UDL. User data length, length of message. The TP-DCS field indicated 7-bit data, so the length here is the number of septets (10). If the TP-DCS field were set to indicate 8-bit data or Unicode, the length would be the number of octets (9).
E8329BFD4697D9EC37TP-UD. Message "hellohello" , 8-bit octets representing 7-bit data.

All the octets above are hexa-decimal 8-bit octets, except the Service center number, the sender number and the timestamp; they are decimal semi-octets. The message part in the end of the PDU string consists of hexa-decimal 8-bit octets, but these octets represent 7-bit data (see below). 

The semi-octets are decimal, and e.g. the sender number is obtained by performing internal swapping within the semi-octets from "72 38 88 09 00 F1" to "27 83 88 90 00 1F". The length of the phone number is odd, so a proper octet sequence cannot be formed by this number. This is the reason why the trailing F has been added. The time stamp, when parsed, equals "99 03 29 15 16 59 08", where the 6 first characters represent date, the following 6 represents time, and the last two represents time-zone related to GMT. 

Interpreting 8-bit octets as 7-bit messages

This transformation is described in detail in GSM 03.38,  The transformation is based on the 7 bit default alphabet , but an application built on the PDU mode can use any character encoding.

Sending a message in the PDU mode

The following example shows how to send the message "hellohello" in the PDU mode from a Nokia 6110.

AT+CMGF=0 //Set PDU mode AT+CSMS=0 //Check if modem supports SMS commands AT+CMGS=23 //Send message, 23 octets (excluding the two initial zeros) &gt;0011000B916407281553F80000AA0AE8329BFD4697D9EC37&lt;ctrl-z&gt; There are 23 octets in this message (46 'characters'). The first octet ("00") doesn't count, it is only an indicator of the length of the SMSC information supplied (0). The PDU string consists of the following:

Octet(s)Description
00Length of SMSC information. Here the length is 0, which means that the SMSC stored in the phone should be used. Note: This octet is optional. On some phones this octet should be omitted! (Using the SMSC stored in phone is thus implicit)
11First octet of the SMS-SUBMIT message.
00TP-Message-Reference. The "00" value here lets the phone set the message reference number itself.
0BAddress-Length. Length of phone number (11)
91Type-of-Address. (91 indicates international format of the phone number).
6407281553F8The phone number in semi octets (46708251358). The length of the phone number is odd (11), therefore a trailing F has been added, as if the phone number were "46708251358F". Using the unknown format (i.e. the Type-of-Address 81 instead of 91) would yield the phone number octet sequence 7080523185 (0708251358). Note that this has the length 10 (A), which is even.
00TP-PID. Protocol identifier
00TP-DCS. Data coding scheme.This message is coded according to the 7bit default alphabet. Having "04" instead of "00" here, would indicate that the TP-User-Data field of this message should be interpreted as 8bit rather than 7bit (used in e.g. smart messaging, OTA provisioning etc).
AATP-Validity-Period. "AA" means 4 days. Note: This octet is optional, see bits 4 and 3 of the first octet
0ATP-User-Data-Length. Length of message. The TP-DCS field indicated 7-bit data, so the length here is the number of septets (10). If the TP-DCS field were set to 8-bit data or Unicode, the length would be the number of octets.
E8329BFD4697D9EC37TP-User-Data. These octets represent the message "hellohello". How to do the transformation from 7bit septets into octets is shown here




Coding 7-bit data (septets) into octets

The message "hellohello" consists of 10 characters, called septets when represented by 7 bits each. These septets need to be transformed into octets for the SMS transfer.

hellohello
104101108108111104101108108111
1101000110010111011001101100110111111010001100101110110011011001101111
1101000
1100101
1101100
1101100
1101111
1101000
1100101
1101100
1101100
1101111

The first septet (h) is turned into an octet by adding the rightmost bit of the second septet. This bit is inserted to the left which yields 1 + 1101000 = 11101000 ("E8"). The rightmost bit of the second character is then consumed, so the second character (septet) needs two bits (yellow) of the third character to make an 8bit octet. This process goes on and on yielding the following octets:

11101000
00110010
10011011
11111101
01000110
10010111
11011001
11101100
110111
E8329BFD4697D9
EC37

The 9 octets from "hellohello" are E8 32 9B FD 46 97 D9 EC 37


+CMS ERROR

Message service error
Description These are the error codes for +CMS ERROR.
Error code Meaning 
0-127 GSM 04.11 Annex E-2 values 
128-255 GSM 03.40 section 9.2.3.22 values 
300 Phone failure 
301 SMS service of phone reserved 
302 Operation not allowed 
303 Operation not supported 
304 Invalid PDU mode parameter 
305 Invalid text mode parameter 
310 SIM not inserted 
311 SIM PIN necessary 
312 PH-SIM PIN necessary 
313 SIM failure 
314 SIM busy 
315 SIM wrong 
320 Memory failure 
321 Invalid memory index 
322 Memory full 
330 SMSC (message service center) address unknown 
331 No network service 
332 Network timeout 
500 Unknown error 
512 Manufacturer specific