How to concat long SMS in GSMComm Library?
Asked Answered
C

2

6

Here is my code:

According to this page the CreateConcatTextMessage method returns an array with type SmsSubmitPdu[] but, when I try to send it with SendMessages I get a MessageServiceError 500. What am I missing?

       SmsSubmitPdu[] pdu2;

        try{
            pdu2 = SmartMessageFactory.CreateConcatTextMessage("My name is Barry Allen. And I am the fastest man alive. When I was a child I saw my mother killed by something impossible. My father went to prison for her murder.", "+639234597676");
            comm.SendMessages(pdu2);
        }

        catch (MessageServiceErrorException e500){
            MessageBox.Show(e500.ToString(), "Information", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
        }
        catch (CommException e501){
            MessageBox.Show(e501.ToString(), "Information", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
        }
Claypool answered 21/1, 2016 at 8:6 Comment(0)
F
8

Your code should looks like this:

GsmCommMain comm=new GsmCommMain(/*Set your option here*/);

string txtMessage="your long message...";
string txtDestinationNumbers="your destination number";

//select unicode option by a checkBox or any other control
bool unicode = chkUnicode.Checked;

SmsSubmitPdu[] pdu = SmartMessageFactory.CreateConcatTextMessage(txtMessage, unicode, txtDestinationNumbers);
сomm.SendMessages(pdu);
Fitzgerald answered 8/11, 2016 at 19:6 Comment(0)
E
4

Enter the number without the county code.

using GsmComm.GsmCommunication;
using GsmComm.PduConverter;
using GsmComm.PduConverter.SmartMessaging; 
using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                GsmCommMain comm = new GsmCommMain("COM7", 19200, 500);
                comm.Open();
                string txtMessage = "Input here very long message please ";
                string txtDestinationNumbers = "+79235280406";
                bool unicode = true;  
                SmsSubmitPdu[] pdu = SmartMessageFactory.CreateConcatTextMessage(txtMessage, unicode, txtDestinationNumbers);
                comm.SendMessages(pdu);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
    }
}

https://github.com/welly87/GSMComm

Eous answered 28/5, 2016 at 10:18 Comment(1)
The above code works fine. However I wanted to know, Is there any need to close the port, that we have opened?Brooklime

© 2022 - 2024 — McMap. All rights reserved.