用C#编程GSM调制解调器

时间:2011-07-06 14:33:14

标签: c# .net com gsm modem

我有一个类型为lightWave的usb gsm调制解调器。我在c#中发现了这个代码,可以从这个调制解调器接收,发送,删除和读取短信,但是当新消息到达调制解调器时,收到新消息时应该引发的事件不会被引发。我不知道问题是什么;但是,我收到后可以从sim中读取此消息,但是当消息到达此部分代码时,我希望收到消息的事件:

private void Form1_Load(object sender, EventArgs e)
{
    int port = GsmCommMain.DefaultPortNumber;
    int baudRate = 9600; // We Set 9600 as our Default Baud Rate
    int timeout = GsmCommMain.DefaultTimeout;

    dlg = new frmConnection();

    dlg.StartPosition = FormStartPosition.CenterScreen;
    dlg.SetData(port, baudRate, timeout);
    if (dlg.ShowDialog(this) == DialogResult.OK)
    {
        dlg.GetData(out port, out baudRate, out timeout);
        CommSetting.Comm_Port = port;
        CommSetting.Comm_BaudRate = baudRate;
        CommSetting.Comm_TimeOut = timeout;
    }
    else
    {
        Close();
        return;
    }
    Cursor.Current = Cursors.WaitCursor;
    CommSetting.comm = new GsmCommMain(port, baudRate, timeout);
    Cursor.Current = Cursors.Default;
    CommSetting.comm.PhoneConnected += new EventHandler(comm_PhoneConnected);
    CommSetting.comm.MessageReceived += new MessageReceivedEventHandler(comm_MessageReceived);
    //....
}

消息

时不会引发此事件
CommSetting.comm.MessageReceived += new MessageReceivedEventHandler(comm_MessageReceived);

我在codeproject.com成立的C#中的代码可以帮助我吗?

2 个答案:

答案 0 :(得分:0)

+ CMTI

GSM / GPRS调制解调器或移动电话使用+ CMTI通知计算机/ PC已收到新的SMS消息以及存储它的存储位置。

继续运行事件句柄DataReceivedHandler

的线程
if(indata.Contains("+CMTI"))//Alert for message recived read message from the loacation

获取loaction并从该specfic sim位置读取消息。

ref http://www.developershome.com/sms/resultCodes3.asp

ref http://msdn.microsoft.com/en-us/library/system.io.ports.serialport.datareceived.aspx

答案 1 :(得分:0)

首先,您必须确保您的端口,波特率和超时有效。然后检查comm是否已正确初始化。

添加处理程序只写下面的代码......

comm.MessageReceived += comm_MessageReceived;

并通过以下代码初始化comm .......

comm = new GsmCommMain(port, baudRate, timeout);