I'm developing SMS system using C#. I use GSMCOMM
how to send sms with more than 160 characters and enable the customer to receive cut SMS as ONE SMS
My code is
public ShortMessageCollection ReadSMS(SerialPort port, string p_strCommand)
{
ShortMessageCollection messages = null;
try
{
#region Execute Command
ExecCommand(port, "AT", 5000, "No phone connected");
ExecCommand(port, "AT+CMGF=1", 5000, "Failed to set message format.");
ExecCommand(port, "AT+CSCS=\"GSM\"", 5000, "Failed to set character set.");
ExecCommand(port, "AT+CPMS=\"SM\"", 5000, "Failed to select message storage.");
string input = ExecCommand(port, p_strCommand, 5000, "Failed to read the messages.");
#endregion
#region Parse messages
messages = ParseMessages(input);
#endregion
}
catch (Exception ex)
{
throw ex;
}
if (messages != null)
return messages;
else
return null;
}
public ShortMessageCollection ParseMessages(string input)
{
var r = new Regex(@"\+CMGL: (\d+),""(.+)"",""(.+)"",(.*),""(.+)""",
RegexOptions.Compiled);
var messages = new ShortMessageCollection();
using (var sw = new StringReader(input))
{
string currentLine = sw.ReadLine();
while (currentLine != null)
{
var m = r.Match(currentLine);
if (m.Success)
{
string message = string.Empty;
currentLine = sw.ReadLine();
while (currentLine != null && !r.IsMatch(currentLine))
{
message += Environment.NewLine;
message += currentLine;
currentLine = sw.ReadLine();
}
messages.Add(new ShortMessage
{
Index = m.Groups[1].Value,
Status = m.Groups[2].Value,
Sender = m.Groups[3].Value,
Alphabet = m.Groups[4].Value,
Sent = m.Groups[5].Value,
Message = message,
});
}
else
{
currentLine = sw.ReadLine();
}
}
}
return messages;
}