mCore™ .NET SMS Library 1.2

mCore.SMS.Disconnect Method

Description:

Disconnect method closes the serial port that was opened using Connect method.

Returns Boolean value True if closing is successful or else returns Boolean value False.

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

Remarks:

The Disconnect method is called internally by mCore automatically whenever the mCore object is closed/terminated.

Exceptions:

mCore.GeneralException

Usage Example:

Visual Basic

Public Class MyClass
   Public WithEvents objSMS As New mCore.SMS
   Public Sub SendMessage()

      Dim strMsg As String
      strMsg = "This is a very long text message and it has more than one _
               hundred sixty characters in it. This is to test how the _
               long message will be sent using mCore .NET SMS Library."
      Try
         SetCommParameters()
         objSMS.Encoding = mCore.Encoding.GSM_Default_7Bit
         objSMS.LongMessage = mCore.LongMessage.Concatenate
         Try
            objSMS.SendSMS("+919873094767", strMsg)
            MsgBox("Message Sent!")
         Catch ex As mCore.SMSSendException
            MsgBox("Message Failed!" & vbCrLf & ex.Message)
         End Try

      Catch ex As mCore.GeneralException
         MsgBox(ex.Message, MsgBoxStyle.Critical, "mCore Demo")
      Catch ex As Exception
      End Try
      objSMS.Disconnect()
   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 static void SendMessage()
   {
      string strMsg = "This is a very long text message and";
      strMsg = strMsg + " it has more than one hundred sixty";
      strMsg = strMsg + " characters in it. This is to test how";
      strMsg = strMsg + " the long message will be sent using";
      strMsg = strMsg + " mCore .NET SMS Library.";
      try
      {

         SetCommParameters();
         objSMS.Encoding = mCore.Encoding.GSM_Default_7Bit;
         objSMS.LongMessage = mCore.LongMessage.Concatenate;
         try
         {
            objSMS.SendSMS("+919873094767", "This is a test message");
            MessageBox.Show("Message Sent!");
         }
         catch (mCore.SMSSendException e)
         {
            MessageBox.Show("Message Failed!" + "\r\n" + e.ToString());
         }
         objSMS.Disconnect();
      }

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

   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.Connect Method

 

Copyright © IG Logix Softech Pvt Ltd, All Rights Reserved