mCore™ .NET SMS Library 1.2

mCore.SMS.NewMessageReceived Event

Description:

The NewMessageReceived Event is raised whenever a new text message is received, if NewMessageIndication property is set as True.

The NewMessageReceived event is raised on a secondary thread when a new incoming SMS is received.

Namespace: mCore
Assembly: mCoreLib (in mCoreLib.dll)

Remarks:

Exceptions:

mCore.GeneralException

Usage Example:

Visual Basic

Public Class MyClass
   Public WithEvents objSMS As New mCore.SMS
  
   Public Sub New()
      Try     
         SetCommParameters()
         objSMS.NewMessageIndication = True
         objSMS.NewMessageConcatenate = True
         objSMS.AutoDeleteNewMessage = True
      Catch ex As mCore.GeneralException
         MsgBox(ex.Message)
      End Try
   End Sub

   'New Message Event Handling
   'A message box will pop-up whenever
   'a new message is received

   Private Sub objSMS_NewMessageReceived(ByVal sender As Object, _
               ByVal e As mCore.NewMessageReceivedEventArgs) _
               Handles objSMS.NewMessageReceived

      MsgBox("FROM: " & e.Phone & vbCrLf & vbCrLf & _
         "DATE/TIME: " & e.TimeStampRFC & vbCrLf & vbCrLf & _
         "MESSAGE:" & vbCrLf & e.TextMessage, _
         MsgBoxStyle.Information, "NEW MESSAGE RECEIVED")

   End Sub

   Public Sub SetCommParameters()
      Try
         objSMS.Port = "COM1"
         objSMS.BaudRate = mCore.BaudRate.BaudRate_19200
         objSMS.DataBits = mCore.DataBits.Eight
         objSMS.StopBits = mCore.StopBits.One
         objSMS.Parity = mCore.Parity.None
         objSMS.FlowControl = mCore.FlowControl.RTS_CTS

      Catch ex As mCore.GeneralException
         MsgBox(ex.Message)
      Catch ex As Exception
      End Try
   End Function
End Class

 
C#

class MyClass
{
   public mCore.SMS objSMS = new mCore.SMS();

   public MyClass()

   {
      try
      {
         SetCommParameters();
         objSMS.NewMessageIndication = true;
         objSMS.NewMessageConcatenate = true;
         objSMS.AutoDeleteNewMessage = true;
      }
      catch (mCore.GeneralException e)
      {
         MessageBox.Show(e.ToString());
      }

      objSMS.NewMessageReceived +=
         new mCore.SMS.NewMessageReceivedEventHandler(objSMS_NewMessageReceived);
   }

   //New Message Event Handling
   //A message box will pop-up whenever
   //a new message is received

   private void objSMS_NewMessageReceived
      (object sender, mCore.NewMessageReceivedEventArgs e)
   {
      MessageBox.Show("NEW MESSAGE RECEIVED" + "\r\n" +
         "FROM: " + e.Phone + "\r\n" +
         "DATE/TIME: " + e.TimeStampRFC + "\r\n" +
         "MESSAGE:" + "\r\n" + e.TextMessage);
   }

   public static void SetCommParameters()
   {
      try
      {
         objSMS.Port = "COM1";
         objSMS.BaudRate = mCore.BaudRate.BaudRate_19200;
         objSMS.DataBits = mCore.DataBits.Eight;
         objSMS.StopBits = mCore.StopBits.One;
         objSMS.Parity = mCore.Parity.None;
         objSMS.FlowControl = mCore.FlowControl.RTS_CTS;
      }

      catch (mCore.GeneralException e)
      {
         MessageBox.Show(e.ToString());
      }
      catch (Exception e)
      {
      }
   }
}

See Also:

mCore.SMS.NewMessageIndication Property
mCore.SMS.NewMessageConcatenate Property
mCore.SMS.AutoDeleteNewMessage Property
mCore.NewMessageReceivedEventArgs Class
mCore.SMS.NewMessageReceivedEventHandler Delegate

 

Copyright © IG Logix Softech Pvt Ltd, All Rights Reserved