1

I read some SMS from the modem (by AT command). I use gsmcomm library. I save read SMS as a string. But gsmcomm work with List of smsPDU.. I have some code- where SMS reading from device (not in a string). How convert my string to List? or add to List?

//I read sms with string
string input = ExecCommand("AT+CMGL=\"ALL\"", 5000, "Failed to read the messages.");
//other code with read long sms where read from device (not AT command)
List<string> messagesList = new List<messageList>();
List<SmsPdu> multiPartMsg = new List<SmsPdu>();


foreach (var i in modem.ReadMessages(PhoneMessageStatus.All, PhoneStorageType.Phone))
{
    string msg;

    if (SmartMessageDecoder.IsPartOfConcatMessage(((SmsDeliverPdu)i.Data)))
    {

        multiPartMsg.Add(i.Data);
        try
        {
            if (SmartMessageDecoder.AreAllConcatPartsPresent(multiPartMsg))
            {

                msg= SmartMessageDecoder.CombineConcatMessageText(multiPartMsg);
                messagesList.Add(msg);
                multiPartMsg.Clear();


            }
        }
        catch (Exception ex) {}


    }
    else
    {
        msg = ((SmsDeliverPdu)i.Data).UserDataText;
        messagesList.Add(msg);

    }
}

Help me, please.

BPDESILVA
  • 2,040
  • 5
  • 15
  • 35
Le0n
  • 37
  • 5
  • Fir change to : List messagesList = new List(); the use : foreach(string message in messageList){ string newMessage = string.Format("AT+CMGL=\"{0}\"", message); messageList.Add(newMessage); } – jdweng Jul 04 '19 at 13:25
  • sorry but i understand. ```string input = ExecCommand("AT+CMGL=\"ALL\"", 5000, "Failed to read the messages."); List messagesList = new List(); List multiPartMsg = new List(); foreach (string message in messagesList) { string newMessage = string.Format("AT+CMGL=\"{0}\"", input); messagesList.Add(newMessage); }``` message and messageList is empty.. – Le0n Jul 04 '19 at 16:04
  • What messages are you sending? I assumed messageList already contained the messages you were going to send. – jdweng Jul 04 '19 at 16:11
  • no no. I read sms from modem! I want read long sms. i see this [link] (https://stackoverflow.com/questions/17249911/how-can-i-decode-pdu-with-gsmcomm-or-pdubitpacker/56888938?noredirect=1#comment100326789_56888938) and not undastad how it read. – Le0n Jul 04 '19 at 16:17

0 Answers0