【问题标题】:GSMComm SMS delivery reportGSMComm 短信送达报告
【发布时间】:2017-04-05 17:03:18
【问题描述】:

我一直在尝试在 C# 应用程序中使用 GSMComm library,以便使用手机(通过 USB 电缆连接)作为 GSM 调制解调器发送 SMS 消息。 我已经阅读了 SO 中所有类似的主题,但没有帮助。

一切正常,除了交付报告。我将 RequestStatusReport 设置为 true 并启用了通知 (EnableMessageNotifications())。

问题是我无法读取收到的交货报告,尽管我知道它的存储(它总是“SR”)和索引号。我不断收到 321 错误代码(无效索引),因为 当我尝试从中读取时,SR 存储看起来是空的

MessageReceived 事件代码及对应的报告如下,如有帮助,不胜感激!

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!");
    }
}

报告:

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

【问题讨论】:

  • 真的我不知道如何解决它,..如果你能解决它也许可以与我分享,..因为我想在我的应用程序中获得交货报告但我不能..感谢也需要教程...
  • 您介意解释一下如何使用此 DLL 启用发送报告通知吗?

标签: sms report gsmcomm


【解决方案1】:

指示对象可以是 MemoryLocation 或 ShortMessage。由于您已经拥有对象并且只需要对其进行解码,因此无需再次从内存位置读取接收到的 ShortMessage(用于传递状态)。以下对我有用

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);
        }

【讨论】:

  • 您介意解释一下如何使用此 DLL 启用发送报告通知吗?
  • @AcademyofProgrammer 您需要在生成 SmsSubmitPdu 时为此设置标志为 true ......就像这样:pdu.RequestStatusReport = true; 另请注意,当您初始化 GsmCommMain 对象时,您必须在尝试发送消息之前绑定到消息接收事件处理程序comm = new GsmCommMain(CommPort, CommBaudRate, Timeout); comm.MessageReceived += comm_MessageReceived;
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多