2011-07-06 27 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);