Пример #1
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);
        }
Пример #2
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);
        }
Пример #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;
                }
            }
        }