Click here to Skip to main content
14,422,431 members
Rate this:
Please Sign up or sign in to vote.
See more:
Dear All I Already Using a Code With At Command With Nokia Phone For Sending SMS by Using Data cable As Now A Day Smart Phone Have to all Person Then please any one help me or Guide me How To Send SMS By Android Phone

What I have tried:

public class CommSetting
{
    public static int Comm_Port=0;
    public static Int64 Comm_BaudRate=0;
    public static Int64 Comm_TimeOut=0;
    public static GsmCommMain comm;

    public CommSetting()
    {
        //
        // TODO: Add constructor logic here
        //
    }
}

GsmCommMain comm = new GsmCommMain(port, baudRate, timeout);
try
{
        comm.Open();
        while (!comm.IsConnected())
        {
            Cursor.Current = Cursors.Default;
            if (MessageBox.Show(this, "No phone connected.",
               "Connection setup", MessageBoxButtons.RetryCancel,
                 MessageBoxIcon.Exclamation) == DialogResult.Cancel)
            {
                comm.Close();
                return;
            }
            Cursor.Current = Cursors.WaitCursor;
        }

        // Close Comm port connection (Since it's just for testing
        // connection)
        comm.Close();
}
catch(Exception ex)
{
    MessageBox.Show(this, "Connection error: " + ex.Message,
    "Connection setup", MessageBoxButtons.OK, MessageBoxIcon.Warning);
    return;
}

// display message if connection is a success.
MessageBox.Show(this, "Successfully connected to the phone.",
"Connection setup", MessageBoxButtons.OK, MessageBoxIcon.Information);

private void MessageReceived()
{
    Cursor.Current = Cursors.WaitCursor;
    string storage = GetMessageStorage();
    DecodedShortMessage[] messages = CommSetting.comm.ReadMessages
                   (PhoneMessageStatus.ReceivedUnread, storage);
    foreach(DecodedShortMessage message in messages)
    {
         Output(string.Format("Message status = {0},
     Location =  {1}/{2}",
         StatusToString(message.Status),
         message.Storage, message.Index));
         ShowMessage(message.Data);
         Output("");
    }

    Output(string.Format("{0,9} messages read.",
                messages.Length.ToString()));
    Output("");
}   
Posted
Updated 12-Jan-20 8:29am
Rate this:
Please Sign up or sign in to vote.

Solution 1

Hello..

As per understand you are opening a comport of your Phone modem. and trying to communicate. I do see the comport configurations are incorrect because port 0 buadrate 0 is invalid.

I think you need to get some information about the how to communicate hardware with comport.
Google[^]

Second, when you are connect directly through the modem (not phone software). you need to use modem commands called AT commands[^]

I have worked on this almost 7 years back, I did not remember correctly command for sending SMS, But I am giving below example you can try it.

AT+CMGS="919XXXXXXXXXXXX"
<SMS MEssage> 
Crtl+Z



Tip: before doing this in the C# code use and Terminal window ,I used hyperterminal ( not available after xp, but you can download exe from web). you can test this commands and everything is OK. Then start codeing in C#.

Good Luck
--RA
   
Comments
irfanansari 13-Nov-18 7:38am
   
sir thanks a lot your response there are a lot of people but no one ready to help me
sir actually my question is that i have a smart phone amazon fire or Samsung any model i already connected it and i am able to access my smart phone by data-cable how can i send sms by using a vb.net or c# software i did very good practice by nokia keypad mobiles it is shows comport then i access it easily like Nokia 6680 ETC
Rate this:
Please Sign up or sign in to vote.

Solution 4

Write this code in the top


Imports System.IO.Ports
Imports System.IO

Secondly:


Write this code in the public class of form:

Dim SerialPort As New System.IO.Ports.SerialPort()
Dim CR As String
Thirdly:

Create a textBox(TextmsgTextBox) to write the text message, and TextBox2(MobileNumberTextBox) to enter the mobile number, and Button(SendBUT) to Send message.

And write this code in the button click event.

If SerialPort.IsOpen Then
SerialPort.Close()
End If
SerialPort.PortName = COM4
SerialPort.BaudRate = 9600
SerialPort.Parity = Parity.None
SerialPort.StopBits = StopBits.One
SerialPort.DataBits = 8
SerialPort.Handshake = Handshake.RequestToSend
SerialPort.DtrEnable = True
SerialPort.RtsEnable = True
SerialPort.NewLine = vbCrLf

Dim message As String
message = MsgRichTextBox.Text

Try
SerialPort.Open()
Catch ex As Exception
MsgBox("The modem with the port '" & SerialPort.PortName & "'is not plugged in!!" & vbcrlf & "Please plug the modem and try again.")
End Try

If SerialPort.IsOpen() Then
SerialPort.Write("AT" & vbCrLf)
SerialPort.Write("AT+CMGF=1" & vbCrLf)
SerialPort.Write("AT+CMGS=" & Chr(34) & phoneNumBox.Text & Chr(34) & vbCrLf)
SerialPort.Write(message & Chr(26))
SentPicture.Visible = True
SentLabel.Visible = True
SentTimer.Start()
Else
MsgBox("Port '" & SerialPort.PortName & "' is not available!")
End If
   
Rate this:
Please Sign up or sign in to vote.

Solution 5

Write this code in the top
Imports System.IO.Ports
Imports System.IO

Secondly:
Write this code in the public class of form:

Dim SerialPort As New System.IO.Ports.SerialPort()
Dim CR As String
Thirdly:

Create a textBox(TextmsgTextBox) to write the text message, and TextBox2(MobileNumberTextBox) to enter the mobile number, and Button(SendBUT) to Send message.

And write this code in the button click event.

If SerialPort.IsOpen Then
SerialPort.Close()
End If
SerialPort.PortName = COM4
SerialPort.BaudRate = 9600
SerialPort.Parity = Parity.None
SerialPort.StopBits = StopBits.One
SerialPort.DataBits = 8
SerialPort.Handshake = Handshake.RequestToSend
SerialPort.DtrEnable = True
SerialPort.RtsEnable = True
SerialPort.NewLine = vbCrLf

Dim message As String
message = MsgRichTextBox.Text

Try
SerialPort.Open()
Catch ex As Exception
MsgBox("The modem with the port '" & SerialPort.PortName & "'is not plugged in!!" & vbcrlf & "Please plug the modem and try again.")
End Try

If SerialPort.IsOpen() Then
SerialPort.Write("AT" & vbCrLf)
SerialPort.Write("AT+CMGF=1" & vbCrLf)
SerialPort.Write("AT+CMGS=" & Chr(34) & phoneNumBox.Text & Chr(34) & vbCrLf)
SerialPort.Write(message & Chr(26))
SentPicture.Visible = True
SentLabel.Visible = True
SentTimer.Start()
Else
MsgBox("Port '" & SerialPort.PortName & "' is not available!")
End IfWrite this code in the top
Imports System.IO.Ports
Imports System.IO

Secondly:
Write this code in the public class of form:

Dim SerialPort As New System.IO.Ports.SerialPort()
Dim CR As String
Thirdly:

Create a textBox(TextmsgTextBox) to write the text message, and TextBox2(MobileNumberTextBox) to enter the mobile number, and Button(SendBUT) to Send message.

And write this code in the button click event.

If SerialPort.IsOpen Then
SerialPort.Close()
End If
SerialPort.PortName = COM4
SerialPort.BaudRate = 9600
SerialPort.Parity = Parity.None
SerialPort.StopBits = StopBits.One
SerialPort.DataBits = 8
SerialPort.Handshake = Handshake.RequestToSend
SerialPort.DtrEnable = True
SerialPort.RtsEnable = True
SerialPort.NewLine = vbCrLf

Dim message As String
message = MsgRichTextBox.Text

Try
SerialPort.Open()
Catch ex As Exception
MsgBox("The modem with the port '" & SerialPort.PortName & "'is not plugged in!!" & vbcrlf & "Please plug the modem and try again.")
End Try

If SerialPort.IsOpen() Then
SerialPort.Write("AT" & vbCrLf)
SerialPort.Write("AT+CMGF=1" & vbCrLf)
SerialPort.Write("AT+CMGS=" & Chr(34) & phoneNumBox.Text & Chr(34) & vbCrLf)
SerialPort.Write(message & Chr(26))
SentPicture.Visible = True
SentLabel.Visible = True
SentTimer.Start()
Else
MsgBox("Port '" & SerialPort.PortName & "' is not available!")
End If
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100