开发者

programming GSM modem in C#

I have a usb gsm modem of type lightWave. I found this code in c# that can receive, send, delete and read sms message from this modem but when a new message arrives to modem, the event that should be raised when new message is received does not get raised. I don't know what the problem is; however, I can read this message from sim after received, but I want the event of received message raised when message arrive this part of code:

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);
    //....
}

This event does not get rai开发者_如何转开发sed when message

CommSetting.comm.MessageReceived += new MessageReceivedEventHandler(comm_MessageReceived);

This code in C# I founded at codeproject.com can any help me please?


+CMTI

A GSM/GPRS modem or mobile phone uses +CMTI to notify the computer / PC that a new SMS message has been received and the memory location where it is stored.

keep on run the thread at event handle DataReceivedHandler,

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

Get the loaction and read the message from that specfic sim location.

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

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


first of all you have to make sure that your port, baudRate and time out is valid. And then check comm is properly initialized.

to add handler write the following code only......

comm.MessageReceived += comm_MessageReceived;

and initialize comm by following code.......

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜