Connecting and sending message through GSM modem using C#

/* Here I am going to explain how to send sms with mobile using c#,gsmcomm a free library available which can be obtained from the following web.
www.download.com/GSMComm/3000-2070_4-10409993.html */
//you need to download the library and add reference to your project.
// all you need is to have a GSM enabled mobile and Bluetooth dongle.
//For testing the connection with your mobile
//create a object for the class GsmCommMain

//create a windows project add refernce for GSM communication
/*Create 2 combo box for the following
1. Port
2. Baud rate you can add values ranging from 1..15 in port combo box
you have to add the baud speed in the baud rate combo*/


Form1_Load()
{
public static GsmCommMain comm;
comm = new GsmCommMain(Comm_Port, Comm_BaudRate); //comm_port id of the combobox
comm.Open();
}


/*For sending sms you have to design a windows form
with the destination number and message field and a button named send
you have to import the following namespace in your project
using GsmComm.GsmCommunication;
using GsmComm.Interfaces;
using GsmComm.PduConverter;
using GsmComm.Server; */

//For sending the message, you have to create a object for the SmsSubmitPdu class
// In the send button click you have to write the following code

btnsend_Click()
{
pdu = new SmsSubmitPdu(txmessage.Text, txdestination.Text, "");

}


// Here I have submitted my code. You can make use of it.


Attachments

  • Sourcecode (23568-71340-testConnection.zip)
  • Comments

    Author: Suganya28 Jan 2009 Member Level: Gold   Points : 2

    hi dharmaraj,
    I am also using the same source code to send sms. I need to more than 1 sms at same time, so i used a loop to send sms as follow, When I am trying this code, its shows "Write Pending Errot" in SendMessage Method. How to solve this help me

    'col is collection to keep sms
    For a = 1 To col.Count

    Try
    If Not MobileModem.IsOpen Then
    MobileModem.Open()
    End If
    dcs = GsmComm.PduConverter.DataCodingScheme.NoClass_7Bit
    pdu = New GsmComm.PduConverter.SmsSubmitPdu(col.Item(a).ToString, mobileno, "", dcs)
    pdu.DataCodingScheme = GsmComm.PduConverter.DataCodingScheme.NoClass_7Bit

    MobileModem.SendMessage(pdu)

    Catch ex As Exception

    End Try
    Next

    Author: Suganya28 Jan 2009 Member Level: Gold   Points : 2

    hi dharmaraj,
    I am also using the same source code to send sms. I need to more than 1 sms at same time, so i used a loop to send sms as follow, When I am trying this code, its shows "Write Pending Errot" in SendMessage Method. How to solve this help me

    'col is collection to keep sms
    For a = 1 To col.Count

    Try
    If Not MobileModem.IsOpen Then
    MobileModem.Open()
    End If
    dcs = GsmComm.PduConverter.DataCodingScheme.NoClass_7Bit
    pdu = New GsmComm.PduConverter.SmsSubmitPdu(col.Item(a).ToString, mobileno, "", dcs)
    pdu.DataCodingScheme = GsmComm.PduConverter.DataCodingScheme.NoClass_7Bit

    MobileModem.SendMessage(pdu)

    Catch ex As Exception

    End Try
    Next

    Author: Suganya28 Jan 2009 Member Level: Gold   Points : 2

    hi dharmaraj,
    I am also using the same source code to send sms. I need to more than 1 sms at same time, so i used a loop to send sms as follow, When I am trying this code, its shows "Write Pending Errot" in SendMessage Method. How to solve this help me

    'col is collection to keep sms
    For a = 1 To col.Count

    Try
    If Not MobileModem.IsOpen Then
    MobileModem.Open()
    End If
    dcs = GsmComm.PduConverter.DataCodingScheme.NoClass_7Bit
    pdu = New GsmComm.PduConverter.SmsSubmitPdu(col.Item(a).ToString, mobileno, "", dcs)
    pdu.DataCodingScheme = GsmComm.PduConverter.DataCodingScheme.NoClass_7Bit

    MobileModem.SendMessage(pdu)

    Catch ex As Exception

    End Try
    Next

    Author: Dharmaraj Nagarajan29 Jan 2009 Member Level: Gold   Points : 1

    Hi,
    I will check my code and will get back to you soon.
    Regards,
    Dharma

    Author: Dharmaraj Nagarajan01 Feb 2009 Member Level: Gold   Points : 1

    Hi,
    Try to open the connection before the loop and close the connection after you sent the message.

    Author: Mrs. Meetu Choudhary Nanda02 Apr 2009 Member Level: Gold   Points : 1

    Hi DharamRaj.
    Nice Piece of information.
    You Shared with Us.
    Looking Forward for more contributions from your side.

    Thanks and Regards
    Meetu Choudhary
    Editor

    Author: Huang04 May 2009 Member Level: Bronze   Points : 1

    Hi,

    If it possible to use GsmComm class to make the gsm phone become a modem ie. use the phone to connect to internet on the PC ?

    I check the class. It seems not possible. Please enlighten how I can do that.

    Huang

    Author: Ralala Yves22 Aug 2009 Member Level: Bronze   Points : 1

    I downloaded and use GSMComm
    but how to send non-ASCII character with it? same as Persian.

    it says :
    The character '?' does not exist in the GSM 7-bit .default alphabet

    Do you have an idea?

    Author: pandikumar01 Dec 2009 Member Level: Bronze   Points : 1

    Hi Dharmaraj nice artical..
    I am trying to get the incomming message indication and read that new msg but i cannot... I cannot trace the library i have lot of confusions can u guide me

    Author: Raju Melveetilpurayil21 May 2010 Member Level: Gold   Points : 1

    thank you Dharmaraj.good article. thankx one more. will c u later now am going to kill my docomo number. 2 sms are chargable 98 sms are free for 1 day. he he ...

    Author: manish30 Jun 2010 Member Level: Bronze   Points : 2


    hello,

    i am using GsmComm.GsmCommunication library. i have problem while sending messages. i am sending more than one message at a time and i have used loop. there are about 150 messages to send in my database. when i am sending messages it sends sometimes 25 or sometimes 30 messages, then it shows error "unable to open port" means it not sends all messages at a time. when i run again my application it send to 20 or 30 messages then also same error. i am using nokia e50 device.

    anyone please tell me the solution?

    Thanks in Advance.

    Regards

    Author: manish30 Jun 2010 Member Level: Bronze   Points : 2


    hello,

    i am using GsmComm.GsmCommunication library. i have problem while sending messages. i am sending more than one message at a time and i have used loop. there are about 150 messages to send in my database. when i am sending messages it sends sometimes 25 or sometimes 30 messages, then it shows error "unable to open port" means it not sends all messages at a time. when i run again my application it send to 20 or 30 messages then also same error. i am using nokia e50 device.

    anyone please tell me the solution?

    Thanks in Advance.

    Regards

    Author: Dharmaraj Nagarajan01 Jul 2010 Member Level: Gold   Points : 1

    Hi,

    You have to write a thread after sending 30 messages, just close the connection and you can set a flag in db to indicate upto which message you have sent. In the next cycle you can fetch the unsent message and send.

    Author: Biju26 Aug 2010 Member Level: Gold   Points : 2

    GO
    IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[Save_Country]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE dbo.[Save_Country];
    GO

    CREATE PROCEDURE dbo.[Save_Country]
    (
    @Id INT = 0,
    @Name NVARCHAR(50),
    @CreatedBy INT,
    @CreatedDate BIGINT,
    @ModifiedBy INT,
    @ModifiedDate BIGINT,
    @ActiveStatus TINYINT,
    @StoreId INT = null ,
    @SyncServerId INT = null ,
    @SyncStoreId int = null,
    @SyncLogEntry bit = true,
    @Country_Output INT OUTPUT
    )
    AS
    BEGIN
    SET NOCOUNT OFF
    BEGIN TRANSACTION trn_Country
    IF @Id <> 0
    BEGIN
    UPDATE [Country]
    SET
    [Name] = @Name
    ,[ModifiedBy] = @ModifiedBy
    ,[ModifiedDate] = @ModifiedDate
    ,[ActiveStatus] = @ActiveStatus
    ,[StoreId] = @StoreId
    ,[SyncServerId] = @SyncServerId
    WHERE
    [Id] = @Id
    SET @Country_Output=@Id
    END
    ELSE
    BEGIN
    DECLARE @cur_pkid INT
    SET @cur_pkid = (select ISNULL(max(id),0) from [Country])
    IF @cur_pkid <> 0
    BEGIN
    DBCC CHECKIDENT ('[Country]', RESEED, @cur_pkid)
    END
    INSERT INTO [Country]
    (
    [Name]
    ,[CreatedBy]
    ,[CreatedDate]
    ,[ModifiedBy]
    ,[ModifiedDate]
    ,[ActiveStatus]
    ,[StoreId]
    ,[SyncServerId]
    )
    VALUES
    (
    @Name
    ,@CreatedBy
    ,@CreatedDate
    ,@ModifiedBy
    ,@ModifiedDate
    ,@ActiveStatus
    ,@StoreId
    ,@SyncServerId
    )
    SET @Country_Output=SCOPE_IDENTITY()
    END
    IF @@ERROR = 0
    BEGIN
    COMMIT TRANSACTION trn_Country
    if(@SyncLogEntry = 'True')
    BEGIN
    Exec Sync_IDS 'Country', @Country_Output, @SyncStoreId
    END
    END
    ELSE
    BEGIN
    ROLLBACK TRANSACTION trn_Country
    SET @Country_Output=0
    END

    END

    GO

    IF (@@Error = 0) PRINT 'Procedure Creation:Save_Country Succeeded'
    ELSE PRINT 'Procedure Creation: Save_Country Error on Creation'
    GO


    Author: abhishek saxena19 Jun 2011 Member Level: Silver   Points : 1

    Hi!
    Guys I am new in .net I am also working as a SE on SMS project using the same DLL GSMComm & PUDConvertoer I just want to know that can we have code for the GSmComm & PDU convertoer DLLs

    Thanks

    Guest Author: anu21 Mar 2012

    hello, I downloaded gsmcomm library. help me how to add reference of gsmcomm library to my project.

    Guest Author: anu21 Mar 2012

    hello,
    I downloaded gsmcomm library.
    help me how to add reference of gsmcomm library to my project.

    Author: Dharmaraj Nagarajan23 Mar 2012 Member Level: Gold   Points : 1

    Hi,
    Once you download the source code, you can view the DLL like Gsm communicator and PDUconverter.dll, simply create a folder called DLL, add copy the dll from source code to the folder and add reference. You will be done with that.

    Guest Author: Michael Frans28 Jun 2012

    Hi Tony, my name is Michael..
    i'm currently working with GSMComm library and i'm currently in a pinch..
    there is a problem i have been working on, but i couldn't come up with a solution, so i would like to ask you about that library..
    here's my question:
    i'm creating an application for sending a SMS with GSMComm library..
    that application retrieves phone and message data from database one by one and it will send a short messages based on the corresponding data and that application runs on windows services..
    for example :
    i have 3 phone number and message on my database
    at first, that application will get 1 record of data and send a short messages.. (FIFO) after send a SMS, that data will be deleted..
    and goes on like that until the data is empty..

    the main problem is that database store a lot of record, so 1 modem for sending a SMS is not enough..
    i need about 2 or 3 modems to handle that record on same table, so it will take shorter time than before..

    do you have any suggestion how to do that?

    Thanks before..

    Best regards,
    Michael Frans



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: