Click here to Skip to main content
15,167,677 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I am trying to develop a WinForm Application that will allow me to send sms message via a serial port. I have bluetooth from samsung gravity tieing into serial port COM7.
The serial port is open Now I only have to find a way to send the message via the open port. The code that i am using which is in the beginning stages looks like this

C#
private SerialPort port;
private string designatedSerialPortNumber;
private string outgoingNumber;
private bool errorOccured;
public Form1()
{
    InitializeComponent();
    port.ErrorReceived += new SerialErrorReceivedEventHandler(port_ErrorReceived);
}
void port_ErrorReceived(object sender, SerialErrorReceivedEventArgs e)
{
    errorOccured = true;
}
private void button1_Click(object sender, EventArgs e)
{
    outgoingNumber = recepientNumber.Text;
    designatedSerialPortNumber = "COM" + PortNumber.Text;
    port = new SerialPort(designatedSerialPortNumber, 9600, Parity.None);
    port.DataBits = 8;
    port.StopBits = StopBits.One;
    port.RtsEnable = true;
    port.DtrEnable = true;
    port.NewLine = System.Environment.NewLine;
    port.Open();
    if (IsOpen() && !errorOccured)
    {
        // port opens and no error was thrown using COM7
        // samsung mobile request permission to serial connect
    }
    port.Close();
}
private bool IsOpen()
{
    return port.IsOpen;
}


If anyone has seen any good examples that they can point me to on sending sms from serial port or if you may be able to give me a few pointers or suggestions it would be greatly appreciated.
Posted

Google: Wonderfull tool. I fed it your subject and pressed "Search"

First link: Your question.
Second link: This question[^].

Now, why couldn't you do that?

I have extracted the relevant lines:

C#
string mobile_number = "+88XXXXXXXXXXX";
string message = "Hi";
port.WriteLine("AT+CMGS=" + mobile_number + "\r" + message + (char)(26));
   
Did you try to see if that works because ive already performed that search found that link could not get that code to work properly. If you have found a way to make that work please let me know?
   

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




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900