【问题标题】:programming GSM modem in C#用 C# 编写 GSM 调制解调器
【发布时间】:2011-09-29 16:47:51
【问题描述】:

我有一个 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# 代码可以帮助我吗?

【问题讨论】:

  • 如果不设置 Handshake 属性,则必须自己设置硬件握手信号。将 RtsEnable 和 DtrEnable 属性设置为 true。
  • 您必须使用自己的处理程序来接收数据并做出相应的决定,而不是使用 GSMcomm。

标签: c# .net com gsm modem


【解决方案1】:

+CMTI

GSM/GPRS 调制解调器或手机使用 +CMTI 通知计算机/PC 已收到一条新的 SMS 消息及其存储位置。

继续在事件句柄DataReceivedHandler处运行线程,

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

获取位置并从该特定 sim 位置读取消息。

参考http://www.developershome.com/sms/resultCodes3.asp

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

【讨论】:

    【解决方案2】:

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

    添加处理程序只需编写以下代码......

    comm.MessageReceived += comm_MessageReceived;
    

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

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

    【讨论】:

      猜你喜欢
      • 2013-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-13
      • 2015-11-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多