我一直试图在一个GSMComm库应用程序中使用C#,以便使用移动电话(通过USB线缆连接)作为GSM调制解调器发送短信。我读过所有类似的文章,但都没帮上忙。
一切正常,除了送货报告。我将RequestStatusReport设置为true,并启用了通知(EnableMessageNotifications()).
问题是我无法阅读接收到的交付报告,尽管我知道它的存储(总是"SR")和索引号。我一直得到321个错误代码(无效索引),因为当我尝试从中读取内存时,它看起来是空的。
MessageReceived事件代码和相应的report如下所示,任何帮助都将不胜感激!
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发布于 2017-01-02 00:29:20
指示对象可以是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);
}https://stackoverflow.com/questions/34840383
复制相似问题