Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# C GSMcomm在触发MessageReceived时提取SMS_C#_Gsmcomm - Fatal编程技术网

C# C GSMcomm在触发MessageReceived时提取SMS

C# C GSMcomm在触发MessageReceived时提取SMS,c#,gsmcomm,C#,Gsmcomm,当触发MessageReceived事件时,是否有方法提取新接收消息的内容并将其放入字符串变量中?非常简单,只需添加如下方法: private void comm_MessageReceived(object sender, MessageReceivedEventArgs e) { var obj = e.IndicationObject; if (obj is MemoryLocation) { var loc = (MemoryLocation)ob

当触发MessageReceived事件时,是否有方法提取新接收消息的内容并将其放入字符串变量中?

非常简单,只需添加如下方法:

private void comm_MessageReceived(object sender, MessageReceivedEventArgs e)
{
    var obj = e.IndicationObject;
    if (obj is MemoryLocation)
    {
        var loc = (MemoryLocation)obj;
        var msg = string.Format("New message received in storage \"{0}\", index {1}.",
                                loc.Storage, loc.Index);
        MessageBox.Show(msg);

        DecodedShortMessage[] messages = CommSetting.comm.ReadMessages(PhoneMessageStatus.All, PhoneStorageType.Sim);
        foreach (DecodedShortMessage message in messages)
        {
            DisplayMessage(message.Data);
        }
        return;
    }
}

private void DisplayMessage(SmsPdu pdu)
{
    if (pdu is SmsDeliverPdu)
    {
        SmsDeliverPdu data = (SmsDeliverPdu)pdu;
        var phoneNumber = data.OriginatingAddress; 
        var msg = data.UserDataText;
        var date = string.Format("{0:dd/MM/yyyy}", data.SCTimestamp.ToDateTime());
        var time = string.Format("{0:HH:mm:ss}", data.SCTimestamp.ToDateTime());

        //read message in listBox1
        listBox1.Items.Add(string.Format("{0}, {1}, {2}, {3}", date, time, phoneNumber, msg));
    }
}
但不要忘记在连接打开时注册此事件:

comm.MessageReceived += new MessageReceivedEventHandler(comm_MessageReceived);

我希望这有助于:D

提取这些传入消息需要什么?将其存储到数据库还是其他数据库?给我一个解释试图实现这一点。。这里设置了什么?它向我展示了errorCommSetting是设置连接到gsm通信库的类。转到此链接并下载示例项目类CommSetting{public static string Comm_Port=;public static Int64 Comm_BaudRate=0;public static Int64 Comm_TimeOut=0;public static gsmcomm main Comm;public CommSetting{///TODO:在此处添加构造函数逻辑//}