2

I've been trying to use GSMComm library in a C# app, in order to sent SMS messages using a mobile phone (connected via USB cable) as a GSM modem. I've read all similar threads in SO, but didn't help.

Everything works well, except the delivery reports. I set RequestStatusReport to true and i enabled notifications (EnableMessageNotifications()).

The problem is that i am not able to read the received delivery report, although i know its storage (it's always "SR") and index number. I keep getting a 321 error code (invalid index) because SR storage looks empty when i try to read from it.

The MessageReceived event code and the corresponding report are as following, any help would be greatly appreciated!

private static void Comm_MessageReceived(object sender, MessageReceivedEventArgs e)
{
    IMessageIndicationObject obj = e.IndicationObject;
    if (obj is MemoryLocation)
    {
        MemoryLocation loc = (MemoryLocation)obj;
        Util.AddLog(string.Format("New message received in storage \"{0}\", index {1}.", loc.Storage, loc.Index));

        DecodedShortMessage msg = Comm.ReadMessage(loc.Index, loc.Storage);

        if (((SmsPdu)msg.Data) is SmsStatusReportPdu)
        {
            SmsStatusReportPdu data = (SmsStatusReportPdu)msg.Data;
            Util.AddLog("rec msg ref #: " + data.MessageReference.ToString());
        }
    }
    else
    {
        Util.AddLog("Error: Unknown notification object!");
    }
}

Report:

New message received in storage "SR", index 0.
[GSM_LOG]  17:08:49.528 Reading message...
[Catch in MessageReceived]  ##### ERROR: Message service error 321 occurred.
[GSM_LOG]  17:08:49.501 [gsmphone] >> 
[GSM_LOG]  17:08:49.501 [gsmphone]    +CDSI: "SR",0
[GSM_LOG]  17:08:49.501 [gsmphone]    
[GSM_LOG]  17:08:49.501 [gsmphone] Unsolicited message: New SMS-STATUS-REPORT received (indicated by memory location)
[GSM_LOG]  17:08:49.501 [gsmphone] Firing async MessageReceived event.
[GSM_LOG]  17:08:49.528 [gsmphone] Selecting "SR" as read storage...
[GSM_LOG]  17:08:49.528 [gsmphone] << AT+CPMS="SR"
[GSM_LOG]  17:08:49.528 [gsmphone]    
[GSM_LOG]  17:08:49.528 [gsmphone] >> AT+CPMS="SR"
[GSM_LOG]  17:08:49.528 [gsmphone]    
[GSM_LOG]  17:08:49.528 [gsmphone]    +CPMS: 0,0,0,23,1,40
[GSM_LOG]  17:08:49.528 [gsmphone]    
[GSM_LOG]  17:08:49.528 [gsmphone]    OK
[GSM_LOG]  17:08:49.528 [gsmphone]    
[GSM_LOG]  17:08:49.528 [gsmphone] Memory status: 0/0 (0% used)
[GSM_LOG]  17:08:49.528 [gsmphone] Activating PDU mode...
[GSM_LOG]  17:08:49.528 [gsmphone] << AT+CMGF=0
[GSM_LOG]  17:08:49.528 [gsmphone]    
[GSM_LOG]  17:08:49.528 [gsmphone] >> AT+CMGF=0
[GSM_LOG]  17:08:49.528 [gsmphone]    
[GSM_LOG]  17:08:49.528 [gsmphone]    OK
[GSM_LOG]  17:08:49.528 [gsmphone]    
[GSM_LOG]  17:08:49.528 [gsmphone] Reading message from index 0...
[GSM_LOG]  17:08:49.528 [gsmphone] << AT+CMGR=0
[GSM_LOG]  17:08:49.528 [gsmphone]    
[GSM_LOG]  17:08:49.528 [gsmphone] >> AT+CMGR=0
[GSM_LOG]  17:08:49.528 [gsmphone]    
[GSM_LOG]  17:08:49.528 [gsmphone]    +CMS ERROR: 321
[GSM_LOG]  17:08:49.528 [gsmphone]    
[GSM_LOG]  17:08:49.545 [gsmphone] Failed. Phone reports message service (MS) error 321.
[GSM_LOG]  17:08:49.545 [gsmphone] AT+CMGR=0
[GSM_LOG]  17:08:49.545 [gsmphone] 
[GSM_LOG]  17:08:49.545 [gsmphone] +CMS ERROR: 321
[GSM_LOG]  17:08:49.545 [gsmphone] 
[GSM_LOG]  17:08:49.548 [gsmphone] Ending async MessageReceivedEventHandler call
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
ion
  • 79
  • 2
  • 10
  • really i didn't know how to fix it,.. if u can solve it perhaps can share with me,.. because i wanna get delivery report in my app but i couldn't.. thanks need for tutorial too... – aminvincent Aug 08 '16 at 08:36
  • Would you mind to explain how to enable delivery report notifications using this DLL please? – NoWar Jul 06 '18 at 08:22

1 Answers1

1

Indication object can be MemoryLocation or ShortMessage. There was no need to read from memory location again for the ShortMessage received (which is for delivery status) as you already have the object and just need to decode it. The below works for me

private void comm_MessageReceived(object sender, MessageReceivedEventArgs e)
    {
        try
        {
            IMessageIndicationObject obj = e.IndicationObject;
            if (obj is MemoryLocation)
            {
                MemoryLocation loc = (MemoryLocation)obj;
                log.InfoFormat("New message received in storage {0}, index {1}.", loc.Storage, loc.Index);

            }
            else if (obj is ShortMessage)
            {
                ShortMessage msg = (ShortMessage)obj;
                SmsPdu pdu = comm.DecodeReceivedMessage(msg);                  

                //Here can be delivery status or received message so cast to the right type by doing type checks for SmsDeliverPdu or SmsStatusReportPdu


            }
            else
            {
                log.ErrorFormat("Unknown notification message received");
                log.InfoFormat("Message indication object is {0}", e.IndicationObject);
            }
        }
        catch (Exception ex)
        {
            log.ErrorFormat("An error occurred while message ws received. Error: {0}", ex.Message);
            log.Error(ex);
        }
Scrappy
  • 122
  • 6
  • Would you mind to explain how to enable delivery report notifications using this DLL please? – NoWar Jul 06 '18 at 08:22
  • 1
    @AcademyofProgrammer you would need to set the flag to true for this when you have generated your SmsSubmitPdu...like so: `pdu.RequestStatusReport = true;` Also note that when you initialize the GsmCommMain object, you will have to bind to the message received event handler before attempting to send the message `comm = new GsmCommMain(CommPort, CommBaudRate, Timeout); comm.MessageReceived += comm_MessageReceived;` – Scrappy Jul 23 '18 at 16:03