2011-07-06 24 views
1

我有一个类型lightWave的USB调制解调器。我在c#中发现了这个代码,它可以接收,发送,删除和读取来自此调制解调器的短消息,但是当新消息到达调制解调器时,收到新消息时应该引发的事件不会引发。我不知道问题是什么;不过,我可以读取SIM卡收到后,此消息,但我想提出接收消息的事件,当信息到达这部分代码:C语言编程GSM调制解调器#

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

C#中的这段代码我创建于codeproject.com可以帮助我吗?

+0

如果不设置Handshake属性,那么你必须自己设置硬件握手信号。将RtsEnable和DtrEnable属性设置为true。 –

+0

而不是使用GSMcomm,您必须将您自己的处理程序接收数据并相应地做出决定。 –

回答

0

+ CMTI

甲GSM/GPRS调制解调器或移动电话用途+ CMTI以通知新的SMS消息已被接收到的计算机/ PC,并且其中它被存储的存储器位置。

继续运行的线程在事件处理DataReceivedHandler

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

获取loaction并从specfic SIM位置读取的消息。

裁判http://www.developershome.com/sms/resultCodes3.asp

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

0

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

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

comm.MessageReceived += comm_MessageReceived; 

,并通过下面的代码初始化通讯.......

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