예제 #1
0
        private OutgoingSmsPdu[] CreateConcatMessage(string message, string number, bool unicode)
        {
            OutgoingSmsPdu[] pdus = null;
            try
            {
                if (!unicode)
                {
                    logger("Creating concatenated message.");
                    pdus = SmartMessageFactory.CreateConcatTextMessage(message, number);
                }
                else
                {
                    logger("Creating concatenated Unicode message.");
                    pdus = SmartMessageFactory.CreateConcatUnicodeTextMessage(message, number);
                }
            }
            catch (Exception ex)
            {
                ShowException(ex);
                return(null);
            }

            if (pdus.Length == 0)
            {
                logger("Error: No PDU parts have been created!");
                return(null);
            }
            else
            {
                logger(pdus.Length.ToString() + " message part(s) created.");
            }

            return(pdus);
        }
예제 #2
0
        public bool Open()
        {
            //GsmCommMain comm = null;
            Close();
            bool chk = false;

            try
            {
                try
                {
                    if (GSMport.Length == 0)
                    {
                        ApplicationConfigManagement acm = new ApplicationConfigManagement();
                        GSMport = acm.ReadSetting("GSMport");
                        if (GSMport.Length > 0)
                        {
                            comm = new GsmCommMain(GSMport, 19200, 500);
                            comm.Open();
                            return(true);
                        }
                    }
                }
                catch (Exception)
                {
                    ;
                }

                string[] ports = SerialPort.GetPortNames();
                foreach (string port in ports)
                {
                    try
                    {
                        comm = new GsmCommMain(port, 19200, 500);
                        comm.Open();
                        SmsSubmitPdu[] pdu = SmartMessageFactory.CreateConcatTextMessage("تست سلامت جی اس ام Port:" + port, true, "09195614157");
                        comm.SendMessages(pdu);
                        chk     = true;
                        GSMport = port;
                        AddUpdateAppSettings("GSMport", GSMport);
                        logger.ErrorLog("Valid Port of GSM is : " + GSMport);
                        //Close(ref comm);
                        break;
                    }
                    catch (Exception err)
                    {
                        Close(); //ref comm
                    }
                }
            }
            catch (Exception ex)
            {
                logger.ErrorLog("هیچ پورتی وجود ندارد...");
            }

            if (!chk)
            {
                logger.ErrorLog("خطای ارتباط با مودم .... \n\r لطفا از ارتباط مودم با سیستم اطمینان حاصل نمایید....");
            }
            return(chk);
        }
예제 #3
0
        public string SendSMSWithGSM(string bodyStr, string Phone, ref bool SendStatus)
        {
            string ReturnStr = "";

            try
            {
                if (comm != null)
                {
                    SmsSubmitPdu[] pdu = SmartMessageFactory.CreateConcatTextMessage(bodyStr, true, Phone);
                    //SmsSubmitPdu[] pdu = SmartMessageFactory.CreateConcatTextMessage(bodyStr, true, "09195614157");
                    comm.SendMessages(pdu);
                    ReturnStr += " --- از طریق گوشی محلی ارسال شد";
                    SendStatus = true;
                }
                else
                {
                    ReturnStr += " --- خطای ارسال از طریق گوشی محلی --- Comm Port is Null";
                }
            }
            catch (Exception err)
            {
                ReturnStr += " --- خطای ارسال از طریق گوشی محلی --- " + err.Message;
            }
            return(ReturnStr);
        }
예제 #4
0
        public async Task <bool> SendSMS(string sms, List <string> phones)
        {
            try
            {
                await Task.FromResult(true);

                GsmCommMain comm = new GsmCommMain("COM6", 1, 80000);
                if (!comm.IsOpen())
                {
                    comm.Open();
                }

                foreach (var phone in phones)
                {
                    SmsSubmitPdu[] messagePDU = SmartMessageFactory.CreateConcatTextMessage(sms, true, phone);
                    comm.SendMessages(messagePDU);
                }

                comm.Close();
                return(true);
            }
            catch (Exception ex)
            {
            }
            return(false);
        }
예제 #5
0
        void SendMessages()
        {
            Log.Add(LogLevel.Verbose, "SMS", "Sending SMS...");

            List <TriggerMessage> msgs = new List <TriggerMessage>();

            for (int i = 0; i < _messagesPerTimerTick && _messagesToSend.Count > 0; i++)
            {
                msgs.Add(_messagesToSend.Dequeue());
            }

            foreach (TriggerMessage msg in msgs)
            {
                Log.Add(LogLevel.Info, "SMS", string.Format("Sending Message to {0}", msg.Destination));
                Log.Add(LogLevel.Verbose, "SMS",
                        string.Format("Message: {0} ({2}): {1}", msg.Destination, msg.Text, msg.FlashMessage));

                SmsSubmitPdu[] pdus = SmartMessageFactory.CreateConcatTextMessage(msg.Text, msg.Destination);

                if (msg.FlashMessage)
                {
                    foreach (var pdu in pdus)
                    {
                        pdu.DataCodingScheme = DataCodingScheme.Class0_7Bit;
                    }
                }

                _gsm.SendMessages(pdus);
            }
        }
예제 #6
0
 /// <summary>
 /// To know the count of SMS
 /// </summary>
 /// <param name="strMessage"></param>
 /// <param name="NumberTo"></param>
 /// <param name="isUnicode"></param>
 /// <returns></returns>
 public int f_getSMSCount(string strMessage, string NumberTo, bool isUnicode)
 {
     try
     {
         SmsSubmitPdu[] obj_smsList = SmartMessageFactory.CreateConcatTextMessage(strMessage, isUnicode, NumberTo);
         return(obj_smsList.Length);
     }
     catch
     {
         return(1);
     }
 }
예제 #7
0
 private OutgoingSmsPdu[] CreateConcatMessage(string textmessage, string mobilenumber)
 {
     OutgoingSmsPdu[] pdus = null;
     try
     {
         pdus = SmartMessageFactory.CreateConcatTextMessage(textmessage, mobilenumber);
     }
     catch (Exception ex)
     {
         Output("Error: " + ex.ToString());
         return(null);
     }
     return(pdus);
 }
예제 #8
0
        private OutgoingSmsPdu[] CreateConcatMessage(string message, string number)
        {
            OutgoingSmsPdu[] pdus = null;

            try
            {
                pdus = SmartMessageFactory.CreateConcatTextMessage(message, number);
            }
            catch
            {
                return(null);
            }

            return(pdus);
        }
예제 #9
0
 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;
     }
 }
예제 #10
0
        public void AutoSMS(string m, string n)
        {
            try
            {
                // GsmCommMain comm = new GsmCommMain("COM78", 9600, 150);
                comm.Open();
                bool           unicode = true;
                SmsSubmitPdu[] pdu     = SmartMessageFactory.CreateConcatTextMessage(m, unicode, n);
                comm.SendMessages(pdu);
                comm.Close();
                // this.Alert("Message Sent!", SDRS.Alert.alertTypeEnum.Success);

                snd();
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
예제 #11
0
        public static String sendSMS(String phoneno, String message, String portno, bool usePDU = true)
        {
            String responseOfAction = "";

            if (usePDU == false)
            {
                try
                {
                    // for more info visit https://stackoverflow.com/a/15450868/8140312
                    SerialPort sp = new SerialPort();
                    sp.PortName = portno;
                    sp.Open();
                    SendCommand("AT", sp);
                    SendCommand("AT+CMGF=1", sp);
                    SendCommand("AT+CSCS=\"GSM\"", sp);
                    SendCommand("AT+CMGS=\"" + phoneno + "\"", sp);

                    var response = SendCommand(message + "\x1A", sp);

                    if (response.Contains("ERROR"))
                    {
                        responseOfAction = $"Unable to send SMS{Environment.NewLine}RESPONSE: “{response}”";
                    }
                    else
                    {
                        responseOfAction = $"SMS sent successfully.{Environment.NewLine}RESPONSE: “{response}”";
                    }
                    sp.Close();

                    return(responseOfAction);
                }
                catch (Exception e)
                {
                    return(e.Message);
                }
            }
            else
            {
                // GsmComm is installed from nuget Package Manager
                GsmCommMain GsmCom = null;
                try
                {
                    GsmCom = new GsmCommMain(portno, 9600, 5000);
                    GsmCom.Open();
                    GsmCom.PortName.ToString();
                    OutgoingSmsPdu[] pdus = null;
                    bool             isValidGSMCharaters = isValidGSMCharateres(message);
                    if (isValidGSMCharaters)
                    {
                        pdus = SmartMessageFactory.CreateConcatTextMessage(message, false, phoneno);
                    }
                    else
                    {
                        pdus = SmartMessageFactory.CreateConcatTextMessage(message, true, phoneno);
                    }
                    Debug.WriteLine($" ===>> {isValidGSMCharaters}");
                    //var st = new Stopwatch();
                    //st.Start();
                    long smsSent = 0;
                    if (pdus != null)
                    {
                        foreach (OutgoingSmsPdu pdu in pdus)
                        {
                            GsmCom.SendMessage(pdu);
                        }
                        //smsSent = st.ElapsedMilliseconds;
                    }
                    GsmCom.Close();
                    //var gsmClsed = st.ElapsedMilliseconds;
                    //st.Stop();
                    //Debug.WriteLine($"smsSentIN: {smsSent} == gsmClosed in {gsmClsed - smsSent }");
                    String formate = isValidGSMCharaters == true ? "GSM" : "Unicode";
                    return($"Message Sent with {portno.ToString()} in “{formate}” format in {pdus.Count()} part(s)");
                }
                catch (Exception exp)
                {
                    if (GsmCom.IsOpen())
                    {
                        GsmCom.Close();
                    }
                    return("Not send: " + exp.Message);
                    // goto lebe;
                }
            }
        }
예제 #12
0
        //public static SmsSubmitPdu[] CreateConcatTextMessage(string userDataText, string destinationAddress)
        //{
        //    return SmartMessageFactory.CreateConcatTextMessage(userDataText, false, destinationAddress);
        //}

        /// <summary>
        /// Creates a concatenated text message.
        /// </summary>
        /// <param name="userDataText">The message text.</param>
        /// <param name="unicode">Specifies if the userDataText is to be encoded as Unicode. If not, the GSM 7-bit default alphabet is used.</param>
        /// <param name="destinationAddress">The message's destination address.</param>
        /// <returns>A set of <see cref="T:GsmComm.PduConverter.SmsSubmitPdu" /> objects that represent the message.</returns>
        /// <remarks>
        /// <para>A concatenated message makes it possible to exceed the maximum length of a normal message,
        /// created by splitting the message data into multiple parts.</para>
        /// <para>Concatenated messages are also known as long or multi-part messages.</para>
        /// <para>If no concatenation is necessary, a single, non-concatenated <see cref="T:GsmComm.PduConverter.SmsSubmitPdu" /> object is created.</para>
        /// </remarks>
        /// <exception cref="T:System.ArgumentException"><para>userDataText is so long that it would create more than 255 message parts.</para></exception>
        public static SmsSubmitPdu[] CreateConcatTextMessage(string userDataText, bool unicode, string destinationAddress)
        {
            string str;
            int    length = 0;
            int    num;

            byte[]       bytes;
            SmsSubmitPdu smsSubmitPdu;
            int          num1;
            byte         num2;

            if (unicode)
            {
                num1 = 70;
            }
            else
            {
                num1 = 160;
            }
            int num3 = num1;

            if (unicode)
            {
                str = userDataText;
            }
            else
            {
                str = TextDataConverter.StringTo7Bit(userDataText);
            }
            if (str.Length <= num3)
            {
                if (unicode)
                {
                    smsSubmitPdu = new SmsSubmitPdu(userDataText, destinationAddress, 8);
                }
                else
                {
                    smsSubmitPdu = new SmsSubmitPdu(userDataText, destinationAddress);
                }
                SmsSubmitPdu[] smsSubmitPduArray = new SmsSubmitPdu[1];
                smsSubmitPduArray[0] = smsSubmitPdu;
                return(smsSubmitPduArray);
            }
            else
            {
                ConcatMessageElement16 concatMessageElement16 = new ConcatMessageElement16(0, 0, 0);
                byte length1 = (byte)((int)SmartMessageFactory.CreateUserDataHeader(concatMessageElement16).Length);
                byte num4    = (byte)((double)length1 / 7 * 8);
                if (unicode)
                {
                    num2 = length1;
                }
                else
                {
                    num2 = num4;
                }
                byte             num5 = num2;
                StringCollection stringCollections = new StringCollection();
                for (int i = 0; i < str.Length; i = i + length)
                {
                    if (!unicode)
                    {
                        if (str.Length - i < num3 - num5)
                        {
                            length = str.Length - i;
                        }
                        else
                        {
                            length = num3 - num5;
                        }
                    }
                    else
                    {
                        if (str.Length - i < (num3 * 2 - num5) / 2)
                        {
                            length = str.Length - i;
                        }
                        else
                        {
                            length = (num3 * 2 - num5) / 2;
                        }
                    }
                    string str1 = str.Substring(i, length);
                    stringCollections.Add(str1);
                }
                if (stringCollections.Count <= 255)
                {
                    SmsSubmitPdu[] smsSubmitPduArray1 = new SmsSubmitPdu[stringCollections.Count];
                    ushort         num6 = CalcNextRefNumber();
                    byte           num7 = 0;
                    for (int j = 0; j < stringCollections.Count; j++)
                    {
                        num7 = (byte)(num7 + 1);
                        ConcatMessageElement16 concatMessageElement161 = new ConcatMessageElement16(num6, (byte)stringCollections.Count, num7);
                        byte[] numArray = SmartMessageFactory.CreateUserDataHeader(concatMessageElement161);
                        if (unicode)
                        {
                            Encoding bigEndianUnicode = Encoding.BigEndianUnicode;
                            bytes = bigEndianUnicode.GetBytes(stringCollections[j]);
                            num   = (int)bytes.Length;
                        }
                        else
                        {
                            bytes = TextDataConverter.SeptetsToOctetsInt(stringCollections[j]);
                            num   = stringCollections[j].Length;
                        }
                        SmsSubmitPdu smsSubmitPdu1 = new SmsSubmitPdu();
                        smsSubmitPdu1.DestinationAddress = destinationAddress;
                        if (unicode)
                        {
                            smsSubmitPdu1.DataCodingScheme = 8;
                        }
                        smsSubmitPdu1.SetUserData(bytes, (byte)num);
                        smsSubmitPdu1.AddUserDataHeader(numArray);
                        smsSubmitPduArray1[j] = smsSubmitPdu1;
                    }
                    return(smsSubmitPduArray1);
                }
                else
                {
                    throw new ArgumentException("A concatenated message must not have more than 255 parts.", "userDataText");
                }
            }
        }