I am sending sms via serial Port but receiving ????. Please help me to receive sms properly and in bulk. Below is my code:
SmsHandler.SendSMS("hello world",phonenumber,"USB Modem");
public static void SendSMS(String smstxt, String PhoneNumber, String DeviceName)
{
_serialPort = new SerialPort(Port.getPort(DeviceName), 19200, Parity.None, 8, StopBits.One);
_serialPort.Handshake = Handshake.None;
_serialPort.DataReceived += new SerialDataReceivedEventHandler(sp_DataReceived);
_serialPort.ReadTimeout = 2000;
_serialPort.WriteTimeout = 2000;
_serialPort.Open();
try
{
if (!_serialPort.IsOpen)
_serialPort.Open();
_serialPort.Write("AT+CMGF=1\r\n");
Thread.Sleep(1000);
_serialPort.Write("AT+CSCA=SERVICE\r\n");// Service Center
Thread.Sleep(1000);
_serialPort.Write("AT+CMGS=\"" + PhoneNumber + "\"" + Environment.NewLine);
_serialPort.Write(smstxt + char.ConvertFromUtf32(26) + Environment.NewLine);
MessageBox.Show("Message Sent");
}
catch (Exception ex)
{
MessageBox.Show("Error opening/writing to serial port :: " + ex.Message, "Error!");
}
}
static void sp_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
Thread.Sleep(500);
string data = _serialPort.ReadLine();
Console.Write(data);
}
I am getting garbage at receiver mobile. Please help to resolve the problem. Thankx